Skip to content

Commit d603ff6

Browse files
adding new cutout sync section 4 to image cutout nb
1 parent a168463 commit d603ff6

1 file changed

Lines changed: 120 additions & 7 deletions

File tree

DP1/100_How_to_Use_RSP_Tools/103_Image_access_and_display/103_4_Small_Image_Cutout.ipynb

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@
324324
"id": "d945e191-7ee4-458a-bb0f-fb00cd219e30",
325325
"metadata": {},
326326
"source": [
327-
"Lastly, call the Rubin Image Cutout Service. This is the IVOA procedure `cutout-sync` that is called using `get_adhocservice_by_id`. It is done by feeding the data link created above (called `dl_result`) to `from_resource`. Since the Rubin DP1 imaging is proprietary it is necessary to again provide the authorization for the current RSP session. Do this using the `get_pyvo_auth` function."
327+
"Lastly, call the Rubin Image Cutout Service. Three types of cutout services exist: `cutout-sync` which, by default, returns just the image extension of the LSST imaging; `cutout-sync-exposure`, which returns the full set of metadata and image extensions that are contained in the `ExposureF` data type; and `cutout-sync-mask` which contains just the mask extension. This section will demonstrate the use of `cutout-sync-exposure` and Section 4 below will demonstrate the other two. \n",
328+
"\n",
329+
"To use the cutout service in this example, the IVOA procedure `cutout-sync-exposure` is called using `get_adhocservice_by_id`. It is done by feeding the data link created above (called `dl_result`) to `from_resource`. Since the Rubin DP1 imaging is proprietary it is necessary to again provide the authorization for the current RSP session. Do this using the `get_pyvo_auth` function."
328330
]
329331
},
330332
{
@@ -386,15 +388,15 @@
386388
"sq.raise_if_error()\n",
387389
"mem = MemFileManager(len(cutout_bytes))\n",
388390
"mem.setData(cutout_bytes, len(cutout_bytes))\n",
389-
"exposure = ExposureF(mem)"
391+
"exposure = ExposureF(mem)\n"
390392
]
391393
},
392394
{
393395
"cell_type": "markdown",
394396
"id": "324be87a-337b-4db7-b57d-842f14614613",
395397
"metadata": {},
396398
"source": [
397-
"Display the cutout."
399+
"Display the image extension of the `ExposureF` cutout."
398400
]
399401
},
400402
{
@@ -502,7 +504,7 @@
502504
"outputs": [],
503505
"source": [
504506
"sqp = SodaQuery.from_resource(dl_result,\n",
505-
" dl_result.get_adhocservice_by_id(\"cutout-sync\"),\n",
507+
" dl_result.get_adhocservice_by_id(\"cutout-sync-exposure\"),\n",
506508
" session=get_pyvo_auth())\n",
507509
"\n",
508510
"ra_edge = 0.02 * u.deg\n",
@@ -565,7 +567,7 @@
565567
"outputs": [],
566568
"source": [
567569
"sq2 = SodaQuery.from_resource(dl_result,\n",
568-
" dl_result.get_adhocservice_by_id(\"cutout-sync\"),\n",
570+
" dl_result.get_adhocservice_by_id(\"cutout-sync-exposure\"),\n",
569571
" session=get_pyvo_auth())\n",
570572
"\n",
571573
"edge1 = Radius\n",
@@ -604,7 +606,7 @@
604606
"cosd = np.cos(a.radian)\n",
605607
"\n",
606608
"sq3 = SodaQuery.from_resource(dl_result,\n",
607-
" dl_result.get_adhocservice_by_id(\"cutout-sync\"),\n",
609+
" dl_result.get_adhocservice_by_id(\"cutout-sync-exposure\"),\n",
608610
" session=get_pyvo_auth())\n",
609611
"\n",
610612
"sq3.polygon = (spherePoint.getRa().asDegrees() * u.deg - edge1/cosd,\n",
@@ -674,6 +676,117 @@
674676
"The zooniverse package should be used instead of this procedure for citizen science applications. "
675677
]
676678
},
679+
{
680+
"cell_type": "markdown",
681+
"id": "99e75a7a-348e-409e-88f6-871b68a4e9dc",
682+
"metadata": {},
683+
"source": [
684+
"## 4. Other cutout service data types\n",
685+
"\n",
686+
"As mentioned in Section 3, there are three types of cutout services: cutout-sync-exposure to return an `ExposureF` type image with all LSST image extensions (demonstrated above); cutout-sync which returns just the image extension, and and cutout-sync-mask which contains just the mask extension. The latter 2 will be demonstrated below.\n"
687+
]
688+
},
689+
{
690+
"cell_type": "code",
691+
"execution_count": null,
692+
"id": "c2c8ab4c-cd1d-4ae8-937d-b34a21035e1e",
693+
"metadata": {},
694+
"outputs": [],
695+
"source": [
696+
"from astropy.io import fits\n",
697+
"import io\n",
698+
"\n",
699+
"print(results[0])\n",
700+
"datalink_url = results[0].access_url\n",
701+
"dl_result = DatalinkResults.from_result_url(datalink_url,\n",
702+
" session=get_pyvo_auth())\n",
703+
"\n",
704+
"f\"Datalink status: {dl_result.status}. Datalink service url: {datalink_url}\"\n"
705+
]
706+
},
707+
{
708+
"cell_type": "code",
709+
"execution_count": null,
710+
"id": "837fbd2a-c3e2-4ee3-a06d-69f4df50823b",
711+
"metadata": {},
712+
"outputs": [],
713+
"source": [
714+
"\n",
715+
"sq5 = SodaQuery.from_resource(dl_result,\n",
716+
" dl_result.get_adhocservice_by_id(\"cutout-sync\"),\n",
717+
" session=get_pyvo_auth())\n",
718+
"\n",
719+
"spherePoint = geom.SpherePoint(target_ra*geom.degrees, target_dec*geom.degrees)\n",
720+
"Radius = 0.01 * u.deg\n",
721+
"sq5.circle = (spherePoint.getRa().asDegrees() * u.deg,\n",
722+
" spherePoint.getDec().asDegrees() * u.deg,\n",
723+
" Radius)\n",
724+
"\n",
725+
"cutout_bytes = sq5.execute_stream().read()\n",
726+
"sq5.raise_if_error()\n"
727+
]
728+
},
729+
{
730+
"cell_type": "code",
731+
"execution_count": null,
732+
"id": "516dbd86-d573-4d81-a017-2ebbce8fb445",
733+
"metadata": {},
734+
"outputs": [],
735+
"source": [
736+
"mem = MemFileManager(len(cutout_bytes))\n",
737+
"mem.setData(cutout_bytes, len(cutout_bytes))\n",
738+
"\n"
739+
]
740+
},
741+
{
742+
"cell_type": "code",
743+
"execution_count": null,
744+
"id": "ed3f7908-a256-42f5-939f-61f38645c7ca",
745+
"metadata": {},
746+
"outputs": [],
747+
"source": [
748+
"data = mem.getData() # returns `bytes`\n",
749+
"\n",
750+
"# this doesn't work\n",
751+
"import lsst.afw.image as afwImage\n",
752+
"\n",
753+
"#image = afwImage.ImageF(mem)\n"
754+
]
755+
},
756+
{
757+
"cell_type": "code",
758+
"execution_count": null,
759+
"id": "d23a0397-6500-4e36-b956-7917ed6a7173",
760+
"metadata": {},
761+
"outputs": [],
762+
"source": [
763+
"\n",
764+
"#data = mem.getData()\n",
765+
"hdul = fits.open(io.BytesIO(data))\n",
766+
"hdul.info()\n",
767+
"\n",
768+
"image_hdu = hdul[1] # IMAGE extension\n",
769+
"image_data = image_hdu.data # NumPy array\n",
770+
"#image = afwImage.ImageF(image_data)\n",
771+
"image = afwImage.ImageF(image_data.astype(\"float32\"))\n",
772+
"print(type(image_data)) # numpy.ndarray\n",
773+
"print(type(image)) # lsst.afw.image._image.ImageF\n"
774+
]
775+
},
776+
{
777+
"cell_type": "code",
778+
"execution_count": null,
779+
"id": "1aa9009a-b493-41ea-bc3c-e0c79adef913",
780+
"metadata": {},
781+
"outputs": [],
782+
"source": [
783+
"\n",
784+
"display = afwDisplay.Display()\n",
785+
"display.scale('asinh', 'zscale')\n",
786+
"display.image(image)\n",
787+
"plt.show()"
788+
]
789+
},
677790
{
678791
"attachments": {
679792
"923e951d-30c0-4a8f-a1b0-8bb851f1cb5f.png": {
@@ -684,7 +797,7 @@
684797
"id": "acbe9638-e7b7-4229-8301-3f57eb0b0c5b",
685798
"metadata": {},
686799
"source": [
687-
"## 4. Exercise for the learner\n",
800+
"## 5. Exercise for the learner\n",
688801
"\n",
689802
"Reproduce the cutout below, whose center is (ra, dec) = 59.1, -48.8 with 0.06 degrees on a side.\n",
690803
"\n",

0 commit comments

Comments
 (0)