|
78 | 78 | "source": [ |
79 | 79 | "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", |
80 | 80 | "\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." |
82 | 82 | ] |
83 | 83 | }, |
84 | 84 | { |
|
98 | 98 | "from lsst.daf.butler import Butler\n", |
99 | 99 | "import lsst.afw.display as afw_display\n", |
100 | 100 | "import lsst.sphgeom as sphgeom\n", |
101 | | - "import lsst.geom as geom\n", |
102 | 101 | "from lsst.utils.plotting import (\n", |
103 | 102 | " get_multiband_plot_colors,\n", |
104 | 103 | " get_multiband_plot_symbols,\n", |
|
444 | 443 | "}" |
445 | 444 | ] |
446 | 445 | }, |
| 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 | + }, |
447 | 492 | { |
448 | 493 | "cell_type": "markdown", |
449 | 494 | "id": "76ef7e00-f9e5-425e-9c74-26b4697107c1", |
450 | 495 | "metadata": {}, |
451 | 496 | "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." |
455 | 498 | ] |
456 | 499 | }, |
457 | 500 | { |
|
466 | 509 | "mesh = ax.pcolormesh(x, y, values_rmaglim, cmap='Greys_r', shading='auto')\n", |
467 | 510 | "fig.colorbar(mesh, ax=ax, label=\"r-band limiting magnitude (mag)\")\n", |
468 | 511 | "\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", |
480 | 529 | "\n", |
481 | 530 | "ax.set_xlim(ra_max, ra_min)\n", |
482 | 531 | "ax.set_ylim(dec_min, dec_max)\n", |
|
526 | 575 | "del coadd_datasetrefs\n", |
527 | 576 | "del hspmap_rmaglim, hspmap_rexptime\n", |
528 | 577 | "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" |
530 | 580 | ] |
531 | 581 | }, |
532 | 582 | { |
|
1218 | 1268 | { |
1219 | 1269 | "cell_type": "code", |
1220 | 1270 | "execution_count": null, |
1221 | | - "id": "b2961b68-461c-42b8-bc67-e17a6d63f60f", |
| 1271 | + "id": "d7a90cd6-86c2-4944-b0ba-6e02dbdb9bd5", |
1222 | 1272 | "metadata": {}, |
1223 | 1273 | "outputs": [], |
1224 | 1274 | "source": [] |
|
0 commit comments