|
15 | 15 | "Questions welcome at <a href=\"https://community.lsst.org/c/support/dp0\">community.lsst.org/c/support/dp0</a> <br>\n", |
16 | 16 | "Find DP0 documentation and resources at <a href=\"https://dp0-1.lsst.io\">dp0-1.lsst.io</a> <br>\n", |
17 | 17 | "\n", |
18 | | - "This notebook provides an introduction to the use of the Gen-3 Butler to explore the structure and content of the DP0.1 data repository containing the LSST DESC DC2 data. The Butler is the LSST Science Pipelines interface for managing, reading, and writing datasets. The Gen-3 Butler is still under development, so this notebook is expected to be updated after the official Gen-3 release.\n", |
| 18 | + "This notebook provides an introduction to the use of the data Butler. The Butler is the LSST Science Pipelines interface for managing, reading, and writing datasets. The Butler can be used to explore the contents of the DP0.1 data repository and access the DP0.1 data. The current version of the Butler (referred to as \"Gen-3\") is still under development, and this notebook may be modified in the future.\n", |
19 | 19 | "\n", |
20 | 20 | "The goals of this notebook are:\n", |
21 | 21 | "\n", |
22 | | - "1. Create a Butler\n", |
| 22 | + "1. Create a Butler.\n", |
23 | 23 | "2. Programmatically explore the content of the DP0.1 data repository\n", |
24 | | - "3. Grab some data!\n", |
| 24 | + "3. Grab some DP0.1 data! \n", |
| 25 | + "4. Grab a cutout of the DP0.1 coadds at a specific (RA,Dec).\n", |
25 | 26 | "\n", |
26 | 27 | "**Credit:** This notebook was originally developed by Alex Drlica-Wagner in the context of the LSST Stack Club.\n", |
27 | 28 | "\n", |
|
44 | 45 | "source": [ |
45 | 46 | "### 1. Create the Butler\n", |
46 | 47 | "\n", |
47 | | - "In this section we are going to create a Gen-3 Butler by pointing it to a specific data set.\n", |
48 | | - "\n", |
49 | | - "We start with some general python package imports." |
| 48 | + "In this section we are going to create an instance of the Butler. We start with some general python package imports." |
50 | 49 | ] |
51 | 50 | }, |
52 | 51 | { |
|
65 | 64 | "cell_type": "markdown", |
66 | 65 | "metadata": {}, |
67 | 66 | "source": [ |
68 | | - "We import LSST Science Pipelines packages to create the Butler and display some data. More details on data display can be found in [03_Intro_to_AFW_Display.ipynb](03_Intro_to_AFW_Display.ipynb)." |
| 67 | + "We import several packages from the LSST Science Pipelines. The first import gives us access to the Butler, while the second provides tools for displaying data. More details on data display can be found in [03_Intro_to_AFW_Display.ipynb](03_Intro_to_AFW_Display.ipynb)." |
69 | 68 | ] |
70 | 69 | }, |
71 | 70 | { |
|
84 | 83 | "cell_type": "markdown", |
85 | 84 | "metadata": {}, |
86 | 85 | "source": [ |
87 | | - "To create the Butler, we need give it a path to the data, which is called a \"repository\". Butler repositories can be remote (the data is on a server, across a network) or local (the data in on a local filesystem)." |
| 86 | + "To create the Butler, we need to provide it with a path to the data set, which is called a \"data repository\". Butler repositories can be remote (i.e., pointing to an S3 bucket) or local (i.e., pointing to a directory on the local file system). In this case, we point to an S3 bucket." |
88 | 87 | ] |
89 | 88 | }, |
90 | 89 | { |
|
103 | 102 | "source": [ |
104 | 103 | "### 2. Explore a data repository\n", |
105 | 104 | "\n", |
106 | | - "With the butler created, we can now access the data `registry` (a database containing information about available data products). The registry will help us examine what collections of data products exist." |
| 105 | + "Now that we've created an instance of the Butler, we can access the data `registry` (a database containing information about available data products). The registry will help us examine what collections of data products exist." |
107 | 106 | ] |
108 | 107 | }, |
109 | 108 | { |
|
448 | 447 | " print()" |
449 | 448 | ] |
450 | 449 | }, |
| 450 | + { |
| 451 | + "cell_type": "markdown", |
| 452 | + "metadata": {}, |
| 453 | + "source": [ |
| 454 | + "### 5. Grabbing an Image Cutout\n", |
| 455 | + "\n", |
| 456 | + "Say we want to grab a cutout of the DP0.1 coadded images at a specific location. In order to do this, we need a few other packages from the LSST Science Pipelines. In particular, access to the geometry and coordinate packages." |
| 457 | + ] |
| 458 | + }, |
| 459 | + { |
| 460 | + "cell_type": "code", |
| 461 | + "execution_count": 2, |
| 462 | + "metadata": {}, |
| 463 | + "outputs": [], |
| 464 | + "source": [ |
| 465 | + "import lsst.geom as geom\n", |
| 466 | + "import lsst.afw.coord as afwCoord" |
| 467 | + ] |
| 468 | + }, |
451 | 469 | { |
452 | 470 | "cell_type": "code", |
453 | 471 | "execution_count": null, |
454 | 472 | "metadata": {}, |
455 | 473 | "outputs": [], |
456 | | - "source": [] |
| 474 | + "source": [ |
| 475 | + "def cutout_coadd(butler, ra, dec, band='r', datasetType='deepCoadd',\n", |
| 476 | + " skymap=None, cutoutSideLength=51, **kwargs):\n", |
| 477 | + " \"\"\"\n", |
| 478 | + " Produce a cutout from a coadd at the given afw SpherePoint radec position.\n", |
| 479 | + "\n", |
| 480 | + " Adapted from DC2 tutorial notebook by Michael Wood-Vasey.\n", |
| 481 | + " \n", |
| 482 | + " Parameters\n", |
| 483 | + " ----------\n", |
| 484 | + " butler: lsst.daf.persistence.Butler\n", |
| 485 | + " Servant providing access to a data repository\n", |
| 486 | + " ra: float\n", |
| 487 | + " Right ascension of the center of the cutout, degrees\n", |
| 488 | + " dec: float\n", |
| 489 | + " Declination of the center of the cutout, degrees\n", |
| 490 | + " filter: string \n", |
| 491 | + " Filter of the image to load\n", |
| 492 | + " datasetType: string ['deepCoadd'] \n", |
| 493 | + " Which type of coadd to load. Doesn't support 'calexp'\n", |
| 494 | + " skymap: lsst.afw.skyMap.SkyMap [optional] \n", |
| 495 | + " Pass in to avoid the Butler read. Useful if you have lots of them.\n", |
| 496 | + " cutoutSideLength: float [optional] \n", |
| 497 | + " Side of the cutout region in pixels.\n", |
| 498 | + " \n", |
| 499 | + " Returns\n", |
| 500 | + " -------\n", |
| 501 | + " MaskedImage\n", |
| 502 | + " \"\"\"\n", |
| 503 | + " radec = geom.SpherePoint(ra, dec, afwGeom.degrees)\n", |
| 504 | + " cutoutSize = geom.ExtentI(cutoutSideLength, cutoutSideLength)\n", |
| 505 | + "\n", |
| 506 | + " if skymap is None:\n", |
| 507 | + " skymap = butler.get(\"skyMap\")\n", |
| 508 | + " \n", |
| 509 | + " # Look up the tract, patch for the RA, Dec\n", |
| 510 | + " tractInfo = skymap.findTract(radec)\n", |
| 511 | + " patchInfo = tractInfo.findPatch(radec)\n", |
| 512 | + " xy = geom.PointI(tractInfo.getWcs().skyToPixel(radec))\n", |
| 513 | + " bbox = geom.BoxI(xy - cutoutSize//2, cutoutSize)\n", |
| 514 | + " patch = tractInfo.getSequentialPatchIndex(patchInfo)\n", |
| 515 | + "\n", |
| 516 | + " coaddId = {'tract': tractInfo.getId(), 'patch': patch, 'band': band}\n", |
| 517 | + " parameters = {'bbox':bbox}\n", |
| 518 | + " \n", |
| 519 | + " cutout_image = butler.get(datasetType, parameters=parameters, immediate=True, dataId=coaddId)\n", |
| 520 | + " \n", |
| 521 | + " return cutout_image" |
| 522 | + ] |
| 523 | + }, |
| 524 | + { |
| 525 | + "cell_type": "code", |
| 526 | + "execution_count": null, |
| 527 | + "metadata": {}, |
| 528 | + "outputs": [], |
| 529 | + "source": [ |
| 530 | + "ra,dec = 55.064, -29.783 # center of DC2 region\n", |
| 531 | + "cutout_image = cutout_coadd(butler,ra,dec,datasetType='deepCoadd', cutoutSideLength=201)\n", |
| 532 | + "print(\"The size of the cutout is: \",cutout_image.image.array.shape)" |
| 533 | + ] |
| 534 | + }, |
| 535 | + { |
| 536 | + "cell_type": "code", |
| 537 | + "execution_count": null, |
| 538 | + "metadata": {}, |
| 539 | + "outputs": [], |
| 540 | + "source": [ |
| 541 | + "fig = plt.figure()\n", |
| 542 | + "afw_display = afwDisplay.Display(1)\n", |
| 543 | + "afw_display.scale('asinh', 'zscale')\n", |
| 544 | + "afw_display.mtv(cutout_image.image)\n", |
| 545 | + "plt.gca().axis('off')" |
| 546 | + ] |
457 | 547 | } |
458 | 548 | ], |
459 | 549 | "metadata": { |
|
0 commit comments