Skip to content

Commit 62011ef

Browse files
committed
Address comments by CW
1 parent a3db09b commit 62011ef

File tree

1 file changed

+77
-67
lines changed

1 file changed

+77
-67
lines changed

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

Lines changed: 77 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868
"source": [
6969
"### 1.1. Import packages\n",
7070
"\n",
71-
"Geometry classes from `lsst.geom` handle pixel and sky coordinates: `Box2I`, `Point2I`, and `Extent2I` define integer-based image regions, `Point2D` represents floating-point coordinates, and `SpherePoint` with `degrees` specifies positions on the celestial sphere.\n",
72-
"`lsst.sphgeom.Box` defines regions on the sky.\n",
7371
"`GetTemplateTask` (`lsst.ip.diffim`) retrieves template images for image differencing, while `lsst.pipe.tasks.makeDiscreteSkyMap` generates discrete sky maps for defining sky coverage."
7472
]
7573
},
@@ -152,6 +150,7 @@
152150
"metadata": {},
153151
"source": [
154152
"Use the galaxy cluster Abell 360 (A360), a rich galaxy cluster at redshift 0.22 that is included in the DP1 data release in the `SV_38_7` field.\n",
153+
"The angular extent of A360 is larger than a single coadd patch, so creating a large cutout is necessary to capture the full cluster within a single image.\n",
155154
"\n",
156155
"Define the coordinates of the brightest cluster galaxy (BCG), in degrees."
157156
]
@@ -164,7 +163,7 @@
164163
"outputs": [],
165164
"source": [
166165
"ra_bcg = 37.865\n",
167-
"dec_bcg = 6.98"
166+
"dec_bcg = 6.982"
168167
]
169168
},
170169
{
@@ -219,7 +218,7 @@
219218
"metadata": {},
220219
"outputs": [],
221220
"source": [
222-
"bands = \"('r')\""
221+
"my_band = ['r']"
223222
]
224223
},
225224
{
@@ -232,7 +231,7 @@
232231
"dataset_refs = set(\n",
233232
" butler.query_datasets(\n",
234233
" \"deep_coadd\",\n",
235-
" where=f\"patch.region OVERLAPS(region) and band in {bands}\",\n",
234+
" where=f\"patch.region OVERLAPS(region) and band in ('{my_band[0]}')\",\n",
236235
" bind={\"region\": box_region}\n",
237236
" )\n",
238237
")"
@@ -256,14 +255,38 @@
256255
"dataset_refs"
257256
]
258257
},
258+
{
259+
"cell_type": "markdown",
260+
"id": "cb4c5d01-ffee-4029-b1f7-b16eb7b7a56d",
261+
"metadata": {},
262+
"source": [
263+
"## 3. Create the cutout"
264+
]
265+
},
266+
{
267+
"cell_type": "markdown",
268+
"id": "6cf9f404-8f17-4d21-85d9-6c2bcfd9c014",
269+
"metadata": {},
270+
"source": [
271+
"Create an image of an arbitrary sky region that is not aligned with the native Legacy Survey of Space and Time (LSST) sky tessellation.\n",
272+
"This is similar to the process in alert production, where past LSST observations are combined to generate static-sky templates for detecting transients in new exposures.\n",
273+
"The same template-generation code (`GetTemplateTask`) can be used to transform input data aligned on the LSST tessellation into the required geometry.\n",
274+
"\n",
275+
"To use the template code, a single astrometric solution or World Coordinate System (WCS) that encompasses all input data is needed, instead of having a separate tangent-plane WCS for each tract.\n",
276+
"A new and custom discrete skymap is therefore created for the input data, producing one tract with a single WCS projection.\n",
277+
"A bounding box is then defined in these new coordinates, centered on the brightest cluster galaxy (BCG) and spanning the specified width.\n",
278+
"\n",
279+
"With this setup, images are generated per band by combining the inputs that fall within the bounding box. The `GetTemplateTask` creates coadds for each band."
280+
]
281+
},
259282
{
260283
"cell_type": "markdown",
261284
"id": "b6e864a7-47cf-4b58-8d87-d22874d71b80",
262285
"metadata": {},
263286
"source": [
264-
"Prepare the inputs for building a custom skymap.\n",
287+
"Prepare the inputs for building the custom skymap.\n",
265288
"\n",
266-
"For each dataset reference, the WCS and bounding box of its patch are stored, so the collection of positions can later define a skymap that includes only the data in use.\n",
289+
"For each dataset reference, the WCS and bounding box of its patch are stored, so the collection of positions can later define the custom skymap that includes only the data in use.\n",
267290
"At the same time, the dataset references are organized into a nested dictionary: first grouped by band, then within each band grouped by tract.\n",
268291
"Each tract key contains all the dataset refs for that tract band combination."
269292
]
@@ -288,30 +311,6 @@
288311
" tract_container.append(ds_ref)"
289312
]
290313
},
291-
{
292-
"cell_type": "markdown",
293-
"id": "cb4c5d01-ffee-4029-b1f7-b16eb7b7a56d",
294-
"metadata": {},
295-
"source": [
296-
"## 3. Create the cutout"
297-
]
298-
},
299-
{
300-
"cell_type": "markdown",
301-
"id": "6cf9f404-8f17-4d21-85d9-6c2bcfd9c014",
302-
"metadata": {},
303-
"source": [
304-
"Create an image of an arbitrary sky region that is not aligned with the native Legacy Survey of Space and Time (LSST) sky tessellation.\n",
305-
"This is similar to the process in alert production, where past LSST observations are combined to generate static-sky templates for detecting transients in new exposures.\n",
306-
"The same template-generation code (`GetTemplateTask`) can be used to transform input data aligned on the LSST tessellation into the required geometry.\n",
307-
"\n",
308-
"To use the template code, a single astrometric solution or World Coordinate System (WCS) that encompasses all input data is needed, instead of having a separate tangent-plane WCS for each tract.\n",
309-
"A discrete skymap is therefore created for the input data, producing one tract with a single WCS projection.\n",
310-
"A bounding box is then defined in these new coordinates, centered on the brightest cluster galaxy (BCG) and spanning the specified width.\n",
311-
"\n",
312-
"With this setup, images are generated per band by combining the inputs that fall within the bounding box. The `GetTemplateTask` creates coadds for each band."
313-
]
314-
},
315314
{
316315
"cell_type": "markdown",
317316
"id": "0fea3ad8-0fe7-45da-808a-a49373058101",
@@ -335,15 +334,16 @@
335334
"id": "b7ce29de-5122-4939-9a46-9550596ef8a3",
336335
"metadata": {},
337336
"source": [
338-
"Override the default configuration values for LSSTComCam, in particular, the pixel scale and the WCS projection."
337+
"The default configuration values of this custom skymap for the pixel scale and WCS projection type are not appropriate for LSSTComCam.\n",
338+
"The following cells override these parameters with appropriate values."
339339
]
340340
},
341341
{
342342
"cell_type": "markdown",
343343
"id": "549fa673-002d-4f6e-8ab9-7027a00ccd13",
344344
"metadata": {},
345345
"source": [
346-
"Use the BCG location to obtain the pixel scale.\n",
346+
"Use the BCG location to obtain the pixel scale there.\n",
347347
"First, get the WCS of the patch and tract where the BCG is located.\n",
348348
"From the 300 DP1 tutorials, the patch and tract numbers are 10463 and 62 respectively."
349349
]
@@ -384,7 +384,7 @@
384384
"id": "58613b7a-9f1f-4156-b8ba-cb08c915996d",
385385
"metadata": {},
386386
"source": [
387-
"Get the WCs from the coadd."
387+
"Get the WCS from the coadd."
388388
]
389389
},
390390
{
@@ -413,7 +413,7 @@
413413
"id": "f1bb7b34-66e6-4bbf-9381-a66a2bcc021c",
414414
"metadata": {},
415415
"source": [
416-
"Use the plate sclate at the BCG location."
416+
"Use the plate scale at the BCG location."
417417
]
418418
},
419419
{
@@ -449,7 +449,7 @@
449449
"id": "b63a608c-3646-4913-ada2-5c961f82b0f7",
450450
"metadata": {},
451451
"source": [
452-
"Set the WCS projection.\n",
452+
"Set the WCS projection type.\n",
453453
"The WCS of `deep_coadd` images are `TAN` projections ([see the DP1 documentation](https://dp1.lsst.io/products/images/deep_coadd.html#wcs))."
454454
]
455455
},
@@ -537,48 +537,46 @@
537537
"id": "f6bd5018-ed88-4df7-abfc-deeb3b17091a",
538538
"metadata": {},
539539
"source": [
540-
"Loop over bands (just the `r` band in this case) to create images that are combinations of the inputs contained within the defined box. Note that the run method modifies the bounding box in place, so a copy is made."
540+
"Create a new coadd image in the band defined above (`r`) that is a combination of the inputs contained within the defined box.\n",
541+
"Note that the run method modifies the bounding box in place, so a copy is made."
541542
]
542543
},
543544
{
544545
"cell_type": "code",
545546
"execution_count": null,
546-
"id": "683bdacb-1fda-4588-96c7-dca359d0ea36",
547+
"id": "18354f90-d2fe-4659-b021-ff212ba7380a",
547548
"metadata": {},
548549
"outputs": [],
549550
"source": [
550551
"getTemplateTask = GetTemplateTask()\n",
551-
"coadds = {}\n",
552-
"for band, mapping in sorted_data.items():\n",
553-
" small_box_copy = Box2I(small_box)\n",
554-
" new_image_tmp = getTemplateTask.run(\n",
555-
" coaddExposures={\n",
556-
" tract: [butler.get(ref) for ref in refs] for tract, refs in mapping.items()\n",
557-
" },\n",
558-
" bbox=small_box_copy,\n",
559-
" wcs=new_wcs,\n",
560-
" dataIds={tract: [ref.dataId for ref in refs] for tract, refs in mapping.items()},\n",
561-
" physical_filter=band,\n",
562-
" )\n",
563-
" coadds[band] = new_image_tmp"
564-
]
565-
},
566-
{
567-
"cell_type": "markdown",
568-
"id": "6870187a-7aba-4863-8570-00f63ad7c5fe",
569-
"metadata": {},
570-
"source": [
571-
"## 4. Visualize the custom cutout"
552+
"mapping = sorted_data[my_band[0]]\n",
553+
"\n",
554+
"small_box_copy = Box2I(small_box)\n",
555+
"new_image_r = getTemplateTask.run(\n",
556+
" coaddExposures={\n",
557+
" tract: [butler.get(ref) for ref in refs] for tract, refs in mapping.items()\n",
558+
" },\n",
559+
" bbox=small_box_copy,\n",
560+
" wcs=new_wcs,\n",
561+
" dataIds={tract: [ref.dataId for ref in refs] for tract, refs in mapping.items()},\n",
562+
" physical_filter=my_band[0],\n",
563+
")"
572564
]
573565
},
574566
{
575567
"cell_type": "code",
576568
"execution_count": null,
577-
"id": "672f1c76-aaba-46e6-882a-162e60fca0de",
569+
"id": "79b9046c-f83d-4d33-ac7e-5d0f165468d8",
578570
"metadata": {},
579571
"outputs": [],
572+
"source": []
573+
},
574+
{
575+
"cell_type": "markdown",
576+
"id": "6870187a-7aba-4863-8570-00f63ad7c5fe",
577+
"metadata": {},
580578
"source": [
581-
"new_image_r = coadds['r']"
579+
"## 4. Visualize the custom cutout"
582580
]
583581
},
584582
{
@@ -621,6 +619,16 @@
621619
"> Figure 1: Cutout of the Abell 360 cluster, displayed using `matplotlib` as backend for `awf.display`. Note that the coordinates are in pixel units."
622620
]
623621
},
622+
{
623+
"cell_type": "code",
624+
"execution_count": null,
625+
"id": "eb0982f3-7990-43f4-be0b-edd43cc35a28",
626+
"metadata": {},
627+
"outputs": [],
628+
"source": [
629+
"new_image_r.template.image.array.shape"
630+
]
631+
},
624632
{
625633
"cell_type": "markdown",
626634
"id": "aa61bcdb-a195-4b98-a568-71bce6a2d5fe",
@@ -717,7 +725,7 @@
717725
"## 5. Compare PSFs\n",
718726
"\n",
719727
"Retrieve the Point Spread Function (PSF) objects for the new big coadd and for the coadd associated with the cluster BCG. \n",
720-
"Compare the PSF size at the location of the BCG and at one corner of the big coadd region."
728+
"Compare the PSF size at the location of the BCG and at near one corner of the big coadd region."
721729
]
722730
},
723731
{
@@ -735,10 +743,11 @@
735743
"metadata": {},
736744
"outputs": [],
737745
"source": [
746+
"margin = 0.01\n",
738747
"locations = [\n",
739748
" (\"center\", bcg_point),\n",
740-
" (\"corner\", SpherePoint(ra_bcg - box_size_deg,\n",
741-
" dec_bcg - box_size_deg, degrees)),\n",
749+
" (\"corner\", SpherePoint(ra_bcg - box_size_deg + margin,\n",
750+
" dec_bcg - box_size_deg + margin, degrees)),\n",
742751
"]"
743752
]
744753
},
@@ -747,7 +756,7 @@
747756
"id": "c9137e34-b303-4647-a0ef-8990012619cc",
748757
"metadata": {},
749758
"source": [
750-
"Loop over locations and compare the PSF sizes."
759+
"Loop over locations and compare the PSF Full Width at Half Maximum (FWHM) size for each one."
751760
]
752761
},
753762
{
@@ -757,6 +766,7 @@
757766
"metadata": {},
758767
"outputs": [],
759768
"source": [
769+
"SIGMA_TO_FWHM = 2.0*np.sqrt(2.0*np.log(2.0))\n",
760770
"for label, loc in locations:\n",
761771
" center_pix_coadd = wcs_bcg.skyToPixel(loc)\n",
762772
" point_coadd = Point2D(center_pix_coadd)\n",
@@ -769,8 +779,8 @@
769779
" psf_sigma_new = newimage_psf.computeShape(point_new).getDeterminantRadius()\n",
770780
"\n",
771781
" percent_diff = np.abs(psf_sigma_coadd - psf_sigma_new) / psf_sigma_new * 100\n",
772-
" print(f\"{label} coadd_bcg sigma = {psf_sigma_coadd: .3f} pixels\")\n",
773-
" print(f\"{label} newimage sigma = {psf_sigma_new: .3f} pixels\")\n",
782+
" print(f\"{label} coadd_bcg FWHM = {psf_sigma_coadd * SIGMA_TO_FWHM: .3f} pixels\")\n",
783+
" print(f\"{label} newimage FWHM = {psf_sigma_new * SIGMA_TO_FWHM: .3f} pixels\")\n",
774784
" print(f\"{label} percent difference = {percent_diff: .2f}%\\n\")"
775785
]
776786
}

0 commit comments

Comments
 (0)