Skip to content

Commit d5661b6

Browse files
committed
updated 301_1
1 parent 019c19f commit d5661b6

1 file changed

Lines changed: 68 additions & 18 deletions

File tree

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

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"source": [
7979
"Import `numpy`, a fundamental package for scientific computing with arrays in Python (<a href=\"https://numpy.org\">numpy.org</a>), and `matplotlib`, a comprehensive library for data visualization (<a href=\"https://matplotlib.org/\">matplotlib.org</a>; <a href=\"https://matplotlib.org/stable/gallery/index.html\">matplotlib gallery</a>), including custom shapes (`Polygon`) and lines (`mlines`). `itertools` supports efficient iteration and combinatorics.\n",
8080
"\n",
81-
"From the `lsst` package, import modules for accessing the Table Access Protocol (TAP) service, 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."
81+
"From the `lsst` package, import modules for accessing the Table Access Protocol (TAP) service, 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."
8282
]
8383
},
8484
{
@@ -98,7 +98,6 @@
9898
"from lsst.daf.butler import Butler\n",
9999
"import lsst.afw.display as afw_display\n",
100100
"import lsst.sphgeom as sphgeom\n",
101-
"import lsst.geom as geom\n",
102101
"from lsst.utils.plotting import (\n",
103102
" get_multiband_plot_colors,\n",
104103
" get_multiband_plot_symbols,\n",
@@ -444,14 +443,58 @@
444443
"}"
445444
]
446445
},
446+
{
447+
"cell_type": "markdown",
448+
"id": "858dcd92-c913-4b31-ae82-ff8dd96c5e92",
449+
"metadata": {},
450+
"source": [
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": "127a6e54-d56b-4a1e-b6a6-a72796a3b3f0",
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": "00f38067-8ee3-422c-b774-63ac8b83b60f",
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": "de109d47-9c87-4c92-98af-7f83bca9c0c8",
485+
"metadata": {},
486+
"outputs": [],
487+
"source": [
488+
"assert job.phase == 'COMPLETED'\n",
489+
"coadd_patches = job.fetch_result().to_table()"
490+
]
491+
},
447492
{
448493
"cell_type": "markdown",
449494
"id": "76ef7e00-f9e5-425e-9c74-26b4697107c1",
450495
"metadata": {},
451496
"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."
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",
@@ -526,7 +575,8 @@
526575
"del coadd_datasetrefs\n",
527576
"del hspmap_rmaglim, hspmap_rexptime\n",
528577
"del x, y, values_rmaglim, values_rexptime\n",
529-
"del style_dict"
578+
"del style_dict\n",
579+
"del tracts, s_regions, coordinates, ra, dec"
530580
]
531581
},
532582
{
@@ -1218,7 +1268,7 @@
12181268
{
12191269
"cell_type": "code",
12201270
"execution_count": null,
1221-
"id": "b2961b68-461c-42b8-bc67-e17a6d63f60f",
1271+
"id": "d7a90cd6-86c2-4944-b0ba-6e02dbdb9bd5",
12221272
"metadata": {},
12231273
"outputs": [],
12241274
"source": []

0 commit comments

Comments
 (0)