Skip to content

Commit

Permalink
PEP8 tweaks and typo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhilbert4 committed Sep 30, 2024
1 parent 68563ad commit daf8584
Showing 1 changed file with 35 additions and 41 deletions.
76 changes: 35 additions & 41 deletions notebooks/NIRCAM/JWpipeNB-nircam-imaging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@
"source": [
"\n",
"## Table of Contents\n",
"1. [Configuration](#Configuration) \n",
"1. [Configuration](#1.-Configuration) \n",
"2. [Package Imports](#2.-Package-Imports)\n",
"3. [Demo Mode Setup (ignore if not using demo data)](#3.-Demo-Mode-Setup-(ignore-if-not-using-demo-data))\n",
"5. [Directory Setup](#4.-Directory-Setup)\n",
"6. [Detector1 Pipelineg](#5.-Detector1-Pipeline)\n",
"7. [Image2 Pipeline](#6.-Image2-Pipeline)\n",
"8. [Image3 Pipeline](#7.-Image3-Pipeline)\n",
"9. [Visualize the resampled images](#8.-Visualize-the-resampled-images)\n",
"10. [Notes](#9.-Notes)"
"4. [Directory Setup](#4.-Directory-Setup)\n",
"5. [Detector1 Pipeline](#5.-Detector1-Pipeline)\n",
"6. [Image2 Pipeline](#6.-Image2-Pipeline)\n",
"7. [Image3 Pipeline](#7.-Image3-Pipeline)\n",
"8. [Visualize the resampled images](#8.-Visualize-the-resampled-images)\n",
"9. [Visualize Detected Sources](#9.-Visualize-Detected-Sources)\n",
"10. [Notes](#10.-Notes)"
]
},
{
"cell_type": "markdown",
"id": "43bd07d7",
"metadata": {},
"source": [
"<a id='Configuration'></a>\n",
"## 1. Configuration"
]
},
Expand Down Expand Up @@ -228,9 +228,10 @@
"# files; leave commented out to use the default context. This is, the latest \n",
"# reference files associated with the version of the calibration pipeline)\n",
"\n",
"# Implementation to associate a context with a version of the jwst Calibration\n",
"# pipeline will be released soon, until that happens we will set the context to the \n",
"# correct one for the version of the jwst Calibration pipeline used here.\n",
"# In the near future, STScI will move to a model where each version of the\n",
"# calibration pipeline is associated with a specific CRDS context file. Here,\n",
"# we explicitly set the context for the version of the jwst Calibration pipeline\n",
"# specificed in this notebook's requirement file.\n",
"%env CRDS_CONTEXT jwst_1293.pmap\n",
"\n",
"# Check whether the local CRDS cache directory has been set.\n",
Expand All @@ -252,7 +253,6 @@
"id": "575588c8",
"metadata": {},
"source": [
"<a id='Package-Imports'></a>\n",
"## 2. Package Imports"
]
},
Expand Down Expand Up @@ -336,7 +336,6 @@
"id": "7ef8050f",
"metadata": {},
"source": [
"<a id='Demo-Mode-Setup-(ignore-if-not-using-demo-data)'></a>\n",
"## 3. Demo Mode Setup (ignore if not using demo data)"
]
},
Expand All @@ -357,7 +356,7 @@
"and start with uncalibrated data products. The files are named\n",
"`jw02739001002_02105_0000<dither>_nrc<det>_uncal.fits`, where *dither* refers to the\n",
"dither step number, and *det* is the detector name. Through this notebook we will refer to data\n",
"with filter `f200W` as SW data and `f444W` as LW data.\n",
"with filter `F200W` as SW data and `F444W` as LW data.\n",
" \n",
"More information about the JWST file naming conventions can be found at:\n",
"https://jwst-pipeline.readthedocs.io/en/latest/jwst/data_products/file_naming.html"
Expand Down Expand Up @@ -387,7 +386,7 @@
" \n",
" # Create directory if it does not exist\n",
" if not os.path.isdir(data_dir):\n",
" os.mkdir(data_dir)\n"
" os.mkdir(data_dir)"
]
},
{
Expand All @@ -400,7 +399,7 @@
"Work one filter at a time, so that we can more easily filter by detector and keep only the module A files.\n",
"</div>\n",
"\n",
"Download first the F200W data."
"First download the F200W data."
]
},
{
Expand Down Expand Up @@ -496,7 +495,7 @@
" provenance_name=[\"CALJWST\"], # Executed observations\n",
" filters=['F444W'], # Data for Specific Filter\n",
" obs_id=['jw' + program + '-o' + sci_observtn + '*']\n",
" )"
" )"
]
},
{
Expand Down Expand Up @@ -600,7 +599,6 @@
"id": "a6c51254-6295-4f98-bc25-d07300e0d8f4",
"metadata": {},
"source": [
"<a id='Directory-Setup'></a>\n",
"## 4. Directory Setup"
]
},
Expand Down Expand Up @@ -659,7 +657,7 @@
"sw_uncal_files = [uncfile for uncfile in uncal_files if 'long' not in uncfile]\n",
"lw_uncal_files = [uncfile for uncfile in uncal_files if 'long' in uncfile]\n",
"\n",
"# Open one SW adn one LW file as JWST datamodel\n",
"# Open one SW and one LW file as JWST datamodel instances\n",
"sw_examine = datamodels.open(sw_uncal_files[0])\n",
"lw_examine = datamodels.open(lw_uncal_files[0])\n",
"\n",
Expand Down Expand Up @@ -691,8 +689,7 @@
"about how JWST exposures are defined by up-the-ramp sampling, see the\n",
"[Understanding Exposure Times JDox article](https://jwst-docs.stsci.edu/understanding-exposure-times).\n",
"\n",
"This metadata will be the same for all exposures in this observation other\n",
"than the dither position number."
"This metadata will be the same for all exposures in this observation, except for the dither position number."
]
},
{
Expand All @@ -712,7 +709,6 @@
"id": "267e28e0-a63f-4790-b8a0-3ad4bff5a167",
"metadata": {},
"source": [
"<a id='Detector1-Pipeline'></a>\n",
"## 5. Detector1 Pipeline\n",
"Run the datasets through the\n",
"[Detector1](https://jwst-docs.stsci.edu/jwst-science-calibration-pipeline-overview/stages-of-jwst-data-processing/calwebb_detector1)\n",
Expand All @@ -724,7 +720,7 @@
"for each integration.\n",
"\n",
"By default, all steps in the `Detector1` stage of the pipeline are run for\n",
"NIRCam except: the `ipc` correction step and the `gain_scale` step. Note\n",
"NIRCam except the `ipc` correction step and the `gain_scale` step. Note\n",
"that the [`persistence` step](https://jwst-pipeline.readthedocs.io/en/latest/jwst/persistence/description.html)\n",
"has been turned off by default starting with CRDS context `jwst_1264.pmap`.\n",
"This step does not automatically correct the science data for persistence.\n",
Expand Down Expand Up @@ -886,9 +882,10 @@
{
"cell_type": "markdown",
"id": "350808ee-9579-4cb5-8f02-a74904c91449",
"metadata": {},
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"<a id='Image2-Pipeline'></a>\n",
"## 6. Image2 Pipeline \n",
"\n",
"In the [Image2 stage of the pipeline](https://jwst-pipeline.readthedocs.io/en/latest/jwst/pipeline/calwebb_image2.html),\n",
Expand Down Expand Up @@ -1081,7 +1078,6 @@
"id": "7cfbb244-7af9-4cbf-90d9-08598378c16a",
"metadata": {},
"source": [
"<a id='Image3-Pipeline'></a>\n",
"## 7. Image3 Pipeline\n",
"\n",
"In the [Image3 stage of the pipeline](https://jwst-pipeline.readthedocs.io/en/latest/jwst/pipeline/calwebb_image3.html), the individual `*_cal.fits` files for each filter are combined to one single distortion corrected image. Unlike the previous stages, we must run the `Image3` stage separately for the files from each filter as well as channel (i.e. shortwave vs longwave).\n",
Expand Down Expand Up @@ -1259,7 +1255,7 @@
"### Run Image3 stage of the pipeline\n",
"\n",
"For each set of grouped exposures in an association file, the `Image3` stage of the pipeline will produce:\n",
"- a `*_cr.fits` file produced by the `outlier_detection` step, where the `DQ` array marks the pixels flagged as outliers.\n",
"- a `*_crf.fits` file produced by the `outlier_detection` step, where the `DQ` array marks the pixels flagged as outliers.\n",
"- a final combined, rectified image with name `*_i2d.fits`,\n",
"- a source catalog with name `*_cat.ecsv`,\n",
"- a segmentation map file (`*_segm.fits`) which has integer values at the pixel locations where a source is detected where the pixel values match the source ID number in the catalog."
Expand Down Expand Up @@ -1427,10 +1423,9 @@
"id": "46be5421-7fc8-4d96-b2cd-2484f294e082",
"metadata": {},
"source": [
"<a id='Visualize-the-resampled-images'></a>\n",
"## 8. Visualize the resampled images\n",
"\n",
"If you specified that the LW and SW outputs should be resampled onto the same pixel grid, you should be able to open the two i2d files and overlay them and see that the sources are aligned. If there is any misalignment, you may need to adjust tweakreg parameters in the calls to the Image3 pipeline in order to improve the alignment.\n",
"If you specified that the LW and SW outputs should be resampled onto the same pixel grid, you should be able to open the two i2d files and overlay them and see that the sources and pixel grids line up. If there is any misalignment, you may need to adjust tweakreg parameters in the calls to the Image3 pipeline in order to improve the alignment.\n",
"\n",
"Below we use the [Imviz tool](https://jdaviz.readthedocs.io/en/latest/imviz/index.html) within the `jdaviz` package to visualize the images, one filter at a time."
]
Expand Down Expand Up @@ -1462,7 +1457,7 @@
"id": "e4654602-c6e9-4178-9b3d-9a219a1471df",
"metadata": {},
"source": [
"Remember that in this data science we have only two detectors nrc2 and nrc4 (left and right) respectively. THe ditter is not large enough to cover the gap. "
"Remember that in this mosaic we have only two detectors: NRC2 and NRC4 (left and right, respectively). The dither is not large enough to cover the gap between the detectors, and so that gap is still visible in the mosaic."
]
},
{
Expand Down Expand Up @@ -1515,7 +1510,6 @@
},
{
"cell_type": "markdown",

"id": "e4797288-5db3-4c4e-bcd3-a1215527fab5",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1571,23 +1565,23 @@
" #'image_opacity': 0.32,\n",
" #'image_contrast': 0.69,\n",
" #'image_bias': 0.39\n",
" },\n",
" },\n",
" 'lw': {'image_color': '#ff767c',\n",
" #'stretch_vmin': 0,\n",
" #'stretch_vmax': 16,\n",
" #'image_opacity': 0.4,\n",
" #'image_contrast': 0.94,\n",
" #'image_bias': 0.74\n",
" }\n",
" }"
" }\n",
" }"
]
},
{
"cell_type": "markdown",
"id": "fd7c00b6-8a84-4d4d-a0dd-b73a1f355f17",
"metadata": {},
"source": [
"We populate the imviz instance with the settings in the cell above and visualize the dataset"
"Populate the imviz instance with the settings in the cell above and visualize the dataset"
]
},
{
Expand Down Expand Up @@ -1622,8 +1616,8 @@
"id": "018733eb-07ec-44a4-a5a7-d6d2f27d193a",
"metadata": {},
"source": [
"## <a id='detections'>Visualize Detected Sources</a>\n",
"Using the source catalogs created by the `Image3` stage of the pipeline, mark the detected sources, using different markers for point sources and extended sources. The source catalogs are saved in `image3/image3_sw_cat.ecsv` and `image3/image3_lw_cat.ecsv`. This time, we will provide the i2d filename to the `imviz` `load_data` function, rather than just the array of pixel values. This way, `imviz` will be able to make use of the World Coordinate System (WCS) in the file. This will allow the sources in the source catalog to be accurately marked in the display."
"## 9. Visualize Detected Sources\n",
"Using the source catalogs created by the `Image3` stage of the pipeline, mark the detected sources, using different markers for point sources and extended sources. The source catalogs are saved in `image3/image3_sw_cat.ecsv` and `image3/image3_lw_cat.ecsv`. This time, we will provide the i2d filename to the `imviz` `load_data` function, rather than just the array of pixel values. This way, `imviz` will be able to make use of the WCS in the file. This will allow the sources in the source catalog to be accurately marked in the display."
]
},
{
Expand Down Expand Up @@ -1759,7 +1753,7 @@
"id": "45a77115-4be8-4b5e-9a45-15a78da35774",
"metadata": {},
"source": [
"No we mark the point sources"
"Now we mark the point sources"
]
},
{
Expand All @@ -1786,15 +1780,15 @@
"id": "85105f12-83ac-4c19-8f52-3ed2a5e08e27",
"metadata": {},
"source": [
"## 9. <a id='Notes'>Notes</a>"
"## 10. Notes"
]
},
{
"cell_type": "markdown",
"id": "f45a68de-194e-4b0d-9ee9-b7ef4d7def42",
"metadata": {},
"source": [
"- Note that the stratgy presented in this notebook for placing the SW data onto the same pixel grid as the LW data can be applied to data from any two datasets, regardless of filter or channel. By saving the gWCS from the first dataset into an asdf file and providing that file to the `Image3` call with the second dataset, the resulting i2d images will be aligned onto the same pixel grid.\n",
"- Note that the strategy presented in this notebook for placing the SW data onto the same pixel grid as the LW data can be applied to data from any two datasets, regardless of filter or channel. By saving the gWCS from the first dataset into an asdf file and providing that file to the `Image3` call with the second dataset, the resulting i2d images will be aligned onto the same pixel grid.\n",
"\n",
"- If you notice poor alignment across tiles within a single i2d image, or between i2d images that you expect to be aligned, try adjusting the parameters in the `tweakreg` step. With these, you can customize which sources `tweakreg` identifies and uses for the alignment."
]
Expand Down Expand Up @@ -1824,7 +1818,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit daf8584

Please sign in to comment.