Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
383 changes: 383 additions & 0 deletions DP1/200_Data_Products/201_Catalogs/201_12_CoaddPatches_table.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"source": [
"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",
"\n",
"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."
"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."
]
},
{
Expand All @@ -98,7 +98,6 @@
"from lsst.daf.butler import Butler\n",
"import lsst.afw.display as afw_display\n",
"import lsst.sphgeom as sphgeom\n",
"import lsst.geom as geom\n",
"from lsst.utils.plotting import (\n",
" get_multiband_plot_colors,\n",
" get_multiband_plot_symbols,\n",
Expand Down Expand Up @@ -444,14 +443,62 @@
"}"
]
},
{
"cell_type": "markdown",
"id": "858dcd92-c913-4b31-ae82-ff8dd96c5e92",
"metadata": {},
"source": [
"Use TAP to find vertices of each patch covering the field in the `dp1.coaddPatches` table."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "127a6e54-d56b-4a1e-b6a6-a72796a3b3f0",
"metadata": {},
"outputs": [],
"source": [
"query = \"SELECT lsst_patch, lsst_tract, s_ra, s_dec, s_region \" \\\n",
" \"FROM dp1.CoaddPatches \" \\\n",
" \"WHERE CONTAINS(POINT('ICRS', s_ra, s_dec), \" \\\n",
" \"CIRCLE('ICRS', {}, {}, {})) = 1 \".format(ra_cen, dec_cen, radius)\n",
"job = service.submit_job(query)\n",
"job.run()\n",
"job.wait(phases=['COMPLETED', 'ERROR'])\n",
"print('Job phase is', job.phase)\n",
"if job.phase == 'ERROR':\n",
" job.raise_if_error()"
]
},
{
"cell_type": "markdown",
"id": "00f38067-8ee3-422c-b774-63ac8b83b60f",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"source": [
"Fetch the results as an `astropy` table."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de109d47-9c87-4c92-98af-7f83bca9c0c8",
"metadata": {},
"outputs": [],
"source": [
"assert job.phase == 'COMPLETED'\n",
"coadd_patches = job.fetch_result().to_table()"
]
},
{
"cell_type": "markdown",
"id": "76ef7e00-f9e5-425e-9c74-26b4697107c1",
"metadata": {},
"source": [
"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",
"\n",
"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."
"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."
]
},
{
Expand All @@ -466,17 +513,23 @@
"mesh = ax.pcolormesh(x, y, values_rmaglim, cmap='Greys_r', shading='auto')\n",
"fig.colorbar(mesh, ax=ax, label=\"r-band limiting magnitude (mag)\")\n",
"\n",
"for rec in coadd_datasetrefs:\n",
" vertices = rec.dataId.patch.region.getVertices()\n",
" vertices_deg = []\n",
" for vertex in vertices:\n",
" vertices_deg.append([geom.SpherePoint(vertex).getRa().asDegrees(),\n",
" geom.SpherePoint(vertex).getDec().asDegrees()])\n",
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
" edgecolor=style_dict[rec.dataId['tract']]['color'],\n",
" linestyle=style_dict[rec.dataId['tract']]['linestyle'],\n",
" linewidth=2)\n",
" ax.add_patch(polygon)\n",
"tracts = set(coadd_patches['lsst_tract'])\n",
"\n",
"for tract in tracts:\n",
" s_regions = coadd_patches[coadd_patches['lsst_tract'] == tract]['s_region']\n",
"\n",
" for s_region in s_regions:\n",
" coordinates = np.array(s_region.split()[2:], dtype=float)\n",
" ra = coordinates[0::2]\n",
" ra = (ra + 180) % 360 - 180\n",
" dec = coordinates[1::2]\n",
" vertices_deg = np.vstack([ra, dec]).T\n",
"\n",
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
" edgecolor=style_dict[tract]['color'],\n",
" linestyle=style_dict[tract]['linestyle'],\n",
" linewidth=2)\n",
" ax.add_patch(polygon)\n",
"\n",
"ax.set_xlim(ra_max, ra_min)\n",
"ax.set_ylim(dec_min, dec_max)\n",
Expand Down Expand Up @@ -526,7 +579,8 @@
"del coadd_datasetrefs\n",
"del hspmap_rmaglim, hspmap_rexptime\n",
"del x, y, values_rmaglim, values_rexptime\n",
"del style_dict"
"del style_dict\n",
"del tracts, s_regions, coordinates, ra, dec"
]
},
{
Expand Down Expand Up @@ -1218,7 +1272,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b2961b68-461c-42b8-bc67-e17a6d63f60f",
"id": "d7a90cd6-86c2-4944-b0ba-6e02dbdb9bd5",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"including custom shapes (`Polygon`) and lines (`mlines`). `itertools` supports efficient iteration and combinatorics.\n",
"\n",
"From the `lsst` package, import modules for accessing the Table Access Protocol (TAP) service, \n",
"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."
"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."
]
},
{
Expand All @@ -101,7 +101,6 @@
"from lsst.daf.butler import Butler\n",
"import lsst.afw.display as afw_display\n",
"import lsst.sphgeom as sphgeom\n",
"import lsst.geom as geom\n",
"from lsst.utils.plotting import (\n",
" get_multiband_plot_colors,\n",
" get_multiband_plot_symbols,\n",
Expand Down Expand Up @@ -449,9 +448,53 @@
"id": "b7417527-3836-4541-b56a-b6ed67a9f41c",
"metadata": {},
"source": [
"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",
"\n",
"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."
"Use TAP to find vertices of each patch covering the field in the `dp1.coaddPatches` table."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5b75d52-50d4-41cc-96b8-9e34277a850c",
"metadata": {},
"outputs": [],
"source": [
"query = \"SELECT lsst_patch, lsst_tract, s_ra, s_dec, s_region \" \\\n",
" \"FROM dp1.CoaddPatches \" \\\n",
" \"WHERE CONTAINS(POINT('ICRS', s_ra, s_dec), \" \\\n",
" \"CIRCLE('ICRS', {}, {}, {})) = 1 \".format(ra_cen, dec_cen, radius)\n",
"job = service.submit_job(query)\n",
"job.run()\n",
"job.wait(phases=['COMPLETED', 'ERROR'])\n",
"print('Job phase is', job.phase)\n",
"if job.phase == 'ERROR':\n",
" job.raise_if_error()"
]
},
{
"cell_type": "markdown",
"id": "06b52f45-548a-4111-bdae-74f8075a3231",
"metadata": {},
"source": [
"Fetch the results as an `astropy` table."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e08dc33-906a-4ea2-8bbf-40db48f151fd",
"metadata": {},
"outputs": [],
"source": [
"assert job.phase == 'COMPLETED'\n",
"coadd_patches = job.fetch_result().to_table()"
]
},
{
"cell_type": "markdown",
"id": "3949d79c-82fa-465b-bfa4-7298c5998622",
"metadata": {},
"source": [
"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."
]
},
{
Expand All @@ -466,17 +509,23 @@
"mesh = ax.pcolormesh(x, y, values_rmaglim, cmap='Greys_r', shading='auto')\n",
"fig.colorbar(mesh, ax=ax, label=\"r-band limiting magnitude (mag)\")\n",
"\n",
"for rec in coadd_datasetrefs:\n",
" vertices = rec.dataId.patch.region.getVertices()\n",
" vertices_deg = []\n",
" for vertex in vertices:\n",
" vertices_deg.append([geom.SpherePoint(vertex).getRa().asDegrees(),\n",
" geom.SpherePoint(vertex).getDec().asDegrees()])\n",
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
" edgecolor=style_dict[rec.dataId['tract']]['color'],\n",
" linestyle=style_dict[rec.dataId['tract']]['linestyle'],\n",
" linewidth=2)\n",
" ax.add_patch(polygon)\n",
"tracts = set(coadd_patches['lsst_tract'])\n",
"\n",
"for tract in tracts:\n",
" s_regions = coadd_patches[coadd_patches['lsst_tract'] == tract]['s_region']\n",
"\n",
" for s_region in s_regions:\n",
" coordinates = np.array(s_region.split()[2:], dtype=float)\n",
" ra = coordinates[0::2]\n",
" ra = (ra + 180) % 360 - 180\n",
" dec = coordinates[1::2]\n",
" vertices_deg = np.vstack([ra, dec]).T\n",
"\n",
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
" edgecolor=style_dict[tract]['color'],\n",
" linestyle=style_dict[tract]['linestyle'],\n",
" linewidth=2)\n",
" ax.add_patch(polygon)\n",
"\n",
"ax.set_xlim(ra_max, ra_min)\n",
"ax.set_ylim(dec_min, dec_max)\n",
Expand Down Expand Up @@ -523,7 +572,8 @@
"del coadd_datasetrefs\n",
"del hspmap_rmaglim, hspmap_rexptime\n",
"del x, y, values_rmaglim, values_rexptime\n",
"del style_dict"
"del style_dict\n",
"del tracts, s_regions, coordinates, ra, dec"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"source": [
"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",
"\n",
"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."
"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."
]
},
{
Expand All @@ -99,7 +99,6 @@
"from lsst.daf.butler import Butler\n",
"import lsst.afw.display as afw_display\n",
"import lsst.sphgeom as sphgeom\n",
"import lsst.geom as geom\n",
"from lsst.utils.plotting import (\n",
" get_multiband_plot_colors,\n",
" get_multiband_plot_symbols,\n",
Expand Down Expand Up @@ -445,14 +444,58 @@
"}"
]
},
{
"cell_type": "markdown",
"id": "dff8b8b9-a16b-4668-89c5-175257497d04",
"metadata": {},
"source": [
"Use TAP to find vertices of each patch covering the field in the `dp1.coaddPatches` table."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "76921d22-4ba5-498f-8d50-1dca93cee564",
"metadata": {},
"outputs": [],
"source": [
"query = \"SELECT lsst_patch, lsst_tract, s_ra, s_dec, s_region \" \\\n",
" \"FROM dp1.CoaddPatches \" \\\n",
" \"WHERE CONTAINS(POINT('ICRS', s_ra, s_dec), \" \\\n",
" \"CIRCLE('ICRS', {}, {}, {})) = 1 \".format(ra_cen, dec_cen, radius)\n",
"job = service.submit_job(query)\n",
"job.run()\n",
"job.wait(phases=['COMPLETED', 'ERROR'])\n",
"print('Job phase is', job.phase)\n",
"if job.phase == 'ERROR':\n",
" job.raise_if_error()"
]
},
{
"cell_type": "markdown",
"id": "0414cdb1-05e2-45be-a484-3b0360a3e9ff",
"metadata": {},
"source": [
"Fetch the results as an `astropy` table."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ca60a80-71ad-461e-9d23-caaf416cdf4d",
"metadata": {},
"outputs": [],
"source": [
"assert job.phase == 'COMPLETED'\n",
"coadd_patches = job.fetch_result().to_table()"
]
},
{
"cell_type": "markdown",
"id": "76ef7e00-f9e5-425e-9c74-26b4697107c1",
"metadata": {},
"source": [
"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",
"\n",
"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."
"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."
]
},
{
Expand All @@ -467,18 +510,23 @@
"mesh = ax.pcolormesh(x, y, values_rmaglim, cmap='Greys_r', shading='auto')\n",
"fig.colorbar(mesh, ax=ax, label=\"r-band limiting magnitude (mag)\")\n",
"\n",
"# Plot patch outlines\n",
"for rec in coadd_datasetrefs:\n",
" vertices = rec.dataId.patch.region.getVertices()\n",
" vertices_deg = []\n",
" for vertex in vertices:\n",
" vertices_deg.append([geom.SpherePoint(vertex).getRa().asDegrees(),\n",
" geom.SpherePoint(vertex).getDec().asDegrees()])\n",
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
" edgecolor=style_dict[rec.dataId['tract']]['color'],\n",
" linestyle=style_dict[rec.dataId['tract']]['linestyle'],\n",
" linewidth=2)\n",
" ax.add_patch(polygon)\n",
"tracts = set(coadd_patches['lsst_tract'])\n",
"\n",
"for tract in tracts:\n",
" s_regions = coadd_patches[coadd_patches['lsst_tract'] == tract]['s_region']\n",
"\n",
" for s_region in s_regions:\n",
" coordinates = np.array(s_region.split()[2:], dtype=float)\n",
" ra = coordinates[0::2]\n",
" ra = (ra + 180) % 360 - 180\n",
" dec = coordinates[1::2]\n",
" vertices_deg = np.vstack([ra, dec]).T\n",
"\n",
" polygon = Polygon(vertices_deg, closed=True, facecolor='None',\n",
" edgecolor=style_dict[tract]['color'],\n",
" linestyle=style_dict[tract]['linestyle'],\n",
" linewidth=2)\n",
" ax.add_patch(polygon)\n",
"\n",
"ax.set_xlim(ra_max, ra_min)\n",
"ax.set_ylim(dec_min, dec_max)\n",
Expand Down Expand Up @@ -528,7 +576,8 @@
"del coadd_datasetrefs\n",
"del hspmap_rmaglim, hspmap_rexptime\n",
"del x, y, values_rmaglim, values_rexptime\n",
"del style_dict"
"del style_dict\n",
"del tracts, s_regions, coordinates, ra, dec"
]
},
{
Expand Down
Loading