diff --git a/notebooks/MIRI_LRS_spectral_extraction/miri_lrs_advanced_extraction_part1.ipynb b/notebooks/MIRI_LRS_spectral_extraction/miri_lrs_advanced_extraction_part1.ipynb
index 72c2bf818..dd9bd61c5 100644
--- a/notebooks/MIRI_LRS_spectral_extraction/miri_lrs_advanced_extraction_part1.ipynb
+++ b/notebooks/MIRI_LRS_spectral_extraction/miri_lrs_advanced_extraction_part1.ipynb
@@ -13,8 +13,7 @@
"**Data:** Publicly available science data
\n",
"**Tools:** jwst, matplotlib, astropy.
\n",
"**Cross-intrument:** NIRSpec, MIRI.
\n",
- "\n",
- "\n",
+ "**Documentation:** This notebook is part of a STScI's larger [post-pipeline Data Analysis Tools Ecosystem](https://jwst-docs.stsci.edu/jwst-post-pipeline-data-analysis) and can be [downloaded](https://github.com/spacetelescope/dat_pyinthesky/tree/main/jdat_notebooks/MRS_Mstar_analysis) directly from the [JDAT Notebook Github directory](https://github.com/spacetelescope/jdat_notebooks).
\n",
"\n",
"### Introduction: Spectral extraction in the JWST calibration pipeline\n",
"\n",
@@ -61,42 +60,10 @@
},
{
"cell_type": "markdown",
+ "id": "14ff9543",
"metadata": {},
"source": [
- "
Reviewer note: Begin PEP8 check cells (delete below when finished)
" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# disable all imported packages' loggers\n", - "import logging\n", - "logging.root.manager.loggerDict = {}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# enable PEP8 checker for this notebook\n", - "%load_ext pycodestyle_magic\n", - "%flake8_on --ignore E261,E501,W291,W293\n", - "\n", - "# only allow the checker to throw warnings when there's a violation\n", - "logging.getLogger('flake8').setLevel('ERROR')\n", - "logging.getLogger('stpipe').setLevel('ERROR')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Reviewer note: Begin PEP8 check cells (delete above when finished)
" + "## Import Packages" ] }, { @@ -130,13 +97,10 @@ "from astropy.modeling import models, fitting\n", "\n", "import jwst\n", - "from jwst.pipeline import Spec2Pipeline, Spec3Pipeline\n", "from jwst import datamodels\n", "from jwst.extract_1d import Extract1dStep\n", "\n", "from matplotlib.patches import Rectangle\n", - "from matplotlib.collections import PatchCollection\n", - "\n", "\n", "import json\n", "import crds\n", @@ -166,22 +130,16 @@ "metadata": {}, "outputs": [], "source": [ - "# Download Data\n", - "if os.path.exists(\"data.tar.gz\"):\n", - " print(\"Original Data tar.gz Exists\")\n", - "else:\n", - " print(\"Downloading Data\")\n", - " url = 'https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/MIRI_LRS_notebook/data.tar.gz'\n", - " urllib.request.urlretrieve(url, 'data.tar.gz')\n", + "data_tar_url = 'https://data.science.stsci.edu/redirect/JWST/jwst-data_analysis_tools/MIRI_LRS_notebook/data.tar.gz'\n", "\n", - "# Unzip files if they haven't already been unzipped\n", - "if os.path.exists(\"data/\"):\n", - " print(\"Data Directory Already Exists\")\n", - "else:\n", + "# Download and unpack data if needed\n", + "if not os.path.exists(\"data.tar.gz\"):\n", + " print(\"Downloading Data\")\n", + " urllib.request.urlretrieve(data_tar_url, 'data.tar.gz')\n", + "if not os.path.exists(\"data/\"):\n", " print(\"Unpacking Data\")\n", - " tar = tarfile.open('./data.tar.gz', \"r:gz\")\n", - " tar.extractall()\n", - " tar.close()" + " with tarfile.open('./data.tar.gz', \"r:gz\") as tar:\n", + " tar.extractall()\n" ] }, { @@ -261,7 +219,7 @@ }, "outputs": [], "source": [ - "print('Spectral extraction reference file used: {}'.format(l3_spec.meta.ref_file.extract1d.name))" + "print(f'Spectral extraction reference file used: {l3_spec.meta.ref_file.extract1d.name}')" ] }, { @@ -273,22 +231,16 @@ }, "outputs": [], "source": [ - "hdu = fits.open('data/jw02072-o001_t010_miri_p750l_x1d_1089.fits')\n", - "json_ref_default = crds.getreferences(hdu[0].header)['extract1d']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "50c8ba27", - "metadata": {}, - "outputs": [], - "source": [ - "with open(json_ref_default) as json_ref:\n", - " x1dref_default = json.load(json_ref)\n", - " print('Settings for SLIT data: {}'.format(x1dref_default['apertures'][0]))\n", - " print(' ')\n", - " print('Settings for SLITLESS data: {}'.format(x1dref_default['apertures'][1]))" + "file_path = 'data/jw02072-o001_t010_miri_p750l_x1d_1089.fits'\n", + "with fits.open(file_path) as hdul:\n", + " header = hdu[0].header\n", + " json_ref_default = crds.getreferences(header)['extract1d']\n", + " \n", + " with open(json_ref_default) as json_ref:\n", + " x1dref_default = json.load(json_ref)\n", + " print('Settings for SLIT data: {}'.format(x1dref_default['apertures'][0]))\n", + " print(' ')\n", + " print('Settings for SLITLESS data: {}'.format(x1dref_default['apertures'][1])) " ] }, { @@ -705,7 +657,8 @@ " ax.set_xlabel('wavelength')\n", " ax.set_ylabel('px')\n", " ax.legend()\n", - " return(fitted_line)\n" + " return(fitted_line)\n", + "\n" ] }, {