Skip to content

Commit 06e3cc6

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

1 file changed

Lines changed: 98 additions & 1 deletion

File tree

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

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,11 @@
683683
"source": [
684684
"## 4. Other cutout service data types\n",
685685
"\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"
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+
"\n",
688+
"### 4.1 Single extension image cutouts\n",
689+
"\n",
690+
"Below demonstrates how to retrieve single extension images using `cutout-sync`."
687691
]
688692
},
689693
{
@@ -787,6 +791,99 @@
787791
"plt.show()"
788792
]
789793
},
794+
{
795+
"cell_type": "markdown",
796+
"id": "918e8779-2939-4978-9ec4-c8a4047f04e9",
797+
"metadata": {},
798+
"source": [
799+
"### 4.2 Single extension mask cutouts\n",
800+
"\n",
801+
"Below demonstrates how to retrieve the corresponding mask using `cutout-sync-mask`."
802+
]
803+
},
804+
{
805+
"cell_type": "code",
806+
"execution_count": null,
807+
"id": "a1213ce5-9049-43ce-8032-f1ea2db9c576",
808+
"metadata": {},
809+
"outputs": [],
810+
"source": [
811+
"\n",
812+
"sq5 = SodaQuery.from_resource(dl_result,\n",
813+
" dl_result.get_adhocservice_by_id(\"cutout-sync-maskedimage\"),\n",
814+
" session=get_pyvo_auth())\n",
815+
"\n",
816+
"spherePoint = geom.SpherePoint(target_ra*geom.degrees, target_dec*geom.degrees)\n",
817+
"Radius = 0.01 * u.deg\n",
818+
"sq5.circle = (spherePoint.getRa().asDegrees() * u.deg,\n",
819+
" spherePoint.getDec().asDegrees() * u.deg,\n",
820+
" Radius)\n",
821+
"\n",
822+
"cutout_bytes = sq5.execute_stream().read()\n",
823+
"sq5.raise_if_error()\n"
824+
]
825+
},
826+
{
827+
"cell_type": "code",
828+
"execution_count": null,
829+
"id": "a2f5ed28-c17d-451b-969c-b7d9186eeb23",
830+
"metadata": {},
831+
"outputs": [],
832+
"source": [
833+
"mem = MemFileManager(len(cutout_bytes))\n",
834+
"mem.setData(cutout_bytes, len(cutout_bytes))\n",
835+
"\n"
836+
]
837+
},
838+
{
839+
"cell_type": "code",
840+
"execution_count": null,
841+
"id": "770c6bc2-67f5-4d3f-9d3a-98cd27e28b35",
842+
"metadata": {},
843+
"outputs": [],
844+
"source": [
845+
"data = mem.getData() # returns `bytes`\n",
846+
"\n",
847+
"# this doesn't work\n",
848+
"import lsst.afw.image as afwImage\n",
849+
"\n",
850+
"#image = afwImage.ImageF(mem)\n"
851+
]
852+
},
853+
{
854+
"cell_type": "code",
855+
"execution_count": null,
856+
"id": "ba884db3-cd3e-45b9-bba0-ecd98cd95358",
857+
"metadata": {},
858+
"outputs": [],
859+
"source": [
860+
"\n",
861+
"#data = mem.getData()\n",
862+
"hdul = fits.open(io.BytesIO(data))\n",
863+
"hdul.info()\n",
864+
"\n",
865+
"image_hdu = hdul[2] # IMAGE extension\n",
866+
"image_data = image_hdu.data # NumPy array\n",
867+
"#image = afwImage.ImageF(image_data)\n",
868+
"image = afwImage.ImageF(image_data)#.astype(\"float32\"))\n",
869+
"print(type(image_data)) # numpy.ndarray\n",
870+
"print(type(image)) # lsst.afw.image._image.ImageF\n"
871+
]
872+
},
873+
{
874+
"cell_type": "code",
875+
"execution_count": null,
876+
"id": "cceab1fb-7f66-4858-b46f-d71fddb50159",
877+
"metadata": {},
878+
"outputs": [],
879+
"source": [
880+
"\n",
881+
"display = afwDisplay.Display()\n",
882+
"display.scale('asinh', 'zscale')\n",
883+
"display.image(image)\n",
884+
"plt.show()"
885+
]
886+
},
790887
{
791888
"attachments": {
792889
"923e951d-30c0-4a8f-a1b0-8bb851f1cb5f.png": {

0 commit comments

Comments
 (0)