Skip to content

Commit 63d28b8

Browse files
committed
updated 301_2
1 parent d5661b6 commit 63d28b8

1 file changed

Lines changed: 67 additions & 17 deletions

File tree

DP1/300_Science_Demos/301_Field_explorations/301_2_Low_Ecliptic_Latitude.ipynb

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"including custom shapes (`Polygon`) and lines (`mlines`). `itertools` supports efficient iteration and combinatorics.\n",
8181
"\n",
8282
"From the `lsst` package, import modules for accessing the Table Access Protocol (TAP) service, \n",
83-
"for retrieving datasets from the butler, and for image displaying from the LSST Science Pipelines (<a href=\"https://pipelines.lsst.io/\">pipelines.lsst.io</a>). Additional modules support spherical geometry (`sphgeom`), 2D geometry (`geom`), and standardized multiband plotting (`lsst.utils.plotting`) for LSST data analysis and visualization."
83+
"for retrieving datasets from the butler, and for image displaying from the LSST Science Pipelines (<a href=\"https://pipelines.lsst.io/\">pipelines.lsst.io</a>). Additional modules support spherical geometry (`sphgeom`), and standardized multiband plotting (`lsst.utils.plotting`) for LSST data analysis and visualization."
8484
]
8585
},
8686
{
@@ -101,7 +101,6 @@
101101
"from lsst.daf.butler import Butler\n",
102102
"import lsst.afw.display as afw_display\n",
103103
"import lsst.sphgeom as sphgeom\n",
104-
"import lsst.geom as geom\n",
105104
"from lsst.utils.plotting import (\n",
106105
" get_multiband_plot_colors,\n",
107106
" get_multiband_plot_symbols,\n",
@@ -449,9 +448,53 @@
449448
"id": "b7417527-3836-4541-b56a-b6ed67a9f41c",
450449
"metadata": {},
451450
"source": [
452-
"The `coadd_datasetrefs` returned from the butler include region information for each dataset, stored as a `ConvexPolygon3D` with four vertices defining the sky footprint of each overlapping tract and patch.\n",
453-
"\n",
454-
"Convert these vertices to 2D sky coordinates (RA, Dec) using `geom.SpherePoint`, and use `matplotlib.patches.Polygon` along with `ax.add_patch()` to draw each patch outline. Each tract is plotted with a distinct color and linestyle for visual clarity."
451+
"Use TAP to find vertices of each patch covering the field in the `dp1.coaddPatches` table."
452+
]
453+
},
454+
{
455+
"cell_type": "code",
456+
"execution_count": null,
457+
"id": "a5b75d52-50d4-41cc-96b8-9e34277a850c",
458+
"metadata": {},
459+
"outputs": [],
460+
"source": [
461+
"query = \"SELECT lsst_patch, lsst_tract, s_ra, s_dec, s_region \" \\\n",
462+
" \"FROM dp1.CoaddPatches \" \\\n",
463+
" \"WHERE CONTAINS(POINT('ICRS', s_ra, s_dec), \" \\\n",
464+
" \"CIRCLE('ICRS', {}, {}, {})) = 1 \".format(ra_cen, dec_cen, radius)\n",
465+
"job = service.submit_job(query)\n",
466+
"job.run()\n",
467+
"job.wait(phases=['COMPLETED', 'ERROR'])\n",
468+
"print('Job phase is', job.phase)\n",
469+
"if job.phase == 'ERROR':\n",
470+
" job.raise_if_error()"
471+
]
472+
},
473+
{
474+
"cell_type": "markdown",
475+
"id": "06b52f45-548a-4111-bdae-74f8075a3231",
476+
"metadata": {},
477+
"source": [
478+
"Fetch the results as an `astropy` table."
479+
]
480+
},
481+
{
482+
"cell_type": "code",
483+
"execution_count": null,
484+
"id": "3e08dc33-906a-4ea2-8bbf-40db48f151fd",
485+
"metadata": {},
486+
"outputs": [],
487+
"source": [
488+
"assert job.phase == 'COMPLETED'\n",
489+
"coadd_patches = job.fetch_result().to_table()"
490+
]
491+
},
492+
{
493+
"cell_type": "markdown",
494+
"id": "3949d79c-82fa-465b-bfa4-7298c5998622",
495+
"metadata": {},
496+
"source": [
497+
"Use `matplotlib.patches.Polygon` along with `ax.add_patch()` to draw each patch outline. Each tract is plotted with a distinct color and linestyle for visual clarity."
455498
]
456499
},
457500
{
@@ -466,17 +509,23 @@
466509
"mesh = ax.pcolormesh(x, y, values_rmaglim, cmap='Greys_r', shading='auto')\n",
467510
"fig.colorbar(mesh, ax=ax, label=\"r-band limiting magnitude (mag)\")\n",
468511
"\n",
469-
"for rec in coadd_datasetrefs:\n",
470-
" vertices = rec.dataId.patch.region.getVertices()\n",
471-
" vertices_deg = []\n",
472-
" for vertex in vertices:\n",
473-
" vertices_deg.append([geom.SpherePoint(vertex).getRa().asDegrees(),\n",
474-
" geom.SpherePoint(vertex).getDec().asDegrees()])\n",
475-
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
476-
" edgecolor=style_dict[rec.dataId['tract']]['color'],\n",
477-
" linestyle=style_dict[rec.dataId['tract']]['linestyle'],\n",
478-
" linewidth=2)\n",
479-
" ax.add_patch(polygon)\n",
512+
"tracts = set(coadd_patches['lsst_tract'])\n",
513+
"\n",
514+
"for tract in tracts:\n",
515+
" s_regions = coadd_patches[coadd_patches['lsst_tract'] == tract]['s_region']\n",
516+
"\n",
517+
" for s_region in s_regions:\n",
518+
" coordinates = np.array(s_region.split()[2:], dtype=float)\n",
519+
" ra = coordinates[0::2]\n",
520+
" ra = (ra + 180) % 360 - 180\n",
521+
" dec = coordinates[1::2]\n",
522+
" vertices_deg = np.vstack([ra, dec]).T\n",
523+
"\n",
524+
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
525+
" edgecolor=style_dict[tract]['color'],\n",
526+
" linestyle=style_dict[tract]['linestyle'],\n",
527+
" linewidth=2)\n",
528+
" ax.add_patch(polygon)\n",
480529
"\n",
481530
"ax.set_xlim(ra_max, ra_min)\n",
482531
"ax.set_ylim(dec_min, dec_max)\n",
@@ -523,7 +572,8 @@
523572
"del coadd_datasetrefs\n",
524573
"del hspmap_rmaglim, hspmap_rexptime\n",
525574
"del x, y, values_rmaglim, values_rexptime\n",
526-
"del style_dict"
575+
"del style_dict\n",
576+
"del tracts, s_regions, coordinates, ra, dec"
527577
]
528578
},
529579
{

0 commit comments

Comments
 (0)