Skip to content

Commit

Permalink
more pep8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ori Fox committed Aug 17, 2023
1 parent 75ec6d7 commit 47154f5
Showing 1 changed file with 24 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"**Data:** Publicly available science data<br>\n",
"**Tools:** jwst, matplotlib, astropy.<br>\n",
"**Cross-intrument:** NIRSpec, MIRI.<br>\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).<br>\n",
"\n",
"### Introduction: Spectral extraction in the JWST calibration pipeline\n",
"\n",
Expand Down Expand Up @@ -61,42 +60,10 @@
},
{
"cell_type": "markdown",
"id": "14ff9543",
"metadata": {},
"source": [
"<p style=\"font-size:200%; color:#e56020; background-color:#1d1160;\"><b><i>Reviewer note:</i> Begin PEP8 check cells (delete below when finished)</b></p>"
]
},
{
"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": [
"<p style=\"font-size:200%; color:#e56020; background-color:#1d1160;\"><b><i>Reviewer note:</i> Begin PEP8 check cells (delete above when finished)</b></p>"
"## Import Packages"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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}')"
]
},
{
Expand All @@ -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])) "
]
},
{
Expand Down Expand Up @@ -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"
]
},
{
Expand Down

0 comments on commit 47154f5

Please sign in to comment.