Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PEP8 and broken link changes to existing COS notebooks #208

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notebooks/COS/AsnFile/AsnFile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
" \"Exposure_type\": rawtag_a_exptypes,\n",
" # Date in MJD\n",
" \"Exposure_start_date\": rawtag_a_expstart_times,\n",
" \"Seconds_since_first_exposure\":\\\n",
" \"Seconds_since_first_exposure\": \\\n",
" # Convert time since the first exposure into seconds\n",
" 86400*np.subtract(rawtag_a_expstart_times, min(rawtag_a_expstart_times))\n",
"})"
Expand Down
30 changes: 17 additions & 13 deletions notebooks/COS/AsnFile/test_asn.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env python
#%%[markdown]
### From here, you can run the `calcos` pipeline on your new association file.
##### Running `calcos` is explained in *much* more detail in our [Notebook on running the pipeline](https://github.com/spacetelescope/notebooks/blob/master/notebooks/COS/CalCOS/CalCOS.ipynb)
# From here, you can run the `calcos` pipeline on your new association file.
# Running `calcos` is explained in *much* more detail in our [Notebook on running the pipeline](https://github.com/spacetelescope/notebooks/blob/master/notebooks/COS/CalCOS/CalCOS.ipynb)

##### In short, to run the `calcos` pipeline, you will need the relavent reference files. These will need be hosted in the directory assigned the environmetn variable `lref`.
##### No matter *where* you place these files, you *must* create the lref environment variable.
# In short, to run the `calcos` pipeline, you will need the relavent reference files. These will need be hosted in the directory assigned the environmetn variable `lref`.
# No matter *where* you place these files, you *must* create the lref environment variable.
# %%
import os, shutil
import os
import shutil
import calcos
from astropy.table import Table
import matplotlib.pyplot as plt
from pathlib import Path
# %%
datadir = Path('./data/')
outputdir = Path('./output/')
plotsdir = Path('./output/plots/')
plotsdir = Path('./output/plots/')
# %%
######### Setting the lref environment variable:
### YOU LIKELY NEED TO CHANGE THIS LOCATION !
# Setting the lref environment variable:
# YOU LIKELY NEED TO CHANGE THIS LOCATION !
where_i_keep_my_ref_files = "/grp/hst/cdbs/lref/"
os.environ['lref'] = where_i_keep_my_ref_files
assert Path(os.environ['lref']).exists(), "Make sure to set the 'lref' environment variable to a valid path with all of your reference files."
Expand All @@ -26,7 +26,9 @@
shutil.copy("./output/ldifcombo_2_asn.fits", "./data/ldifcombo_2_asn.fits")

# Run the CalCOS pipeline on our ldifcombo asn file
calcos.calcos('./data/ldifcombo_2_asn.fits', verbosity=0, outdir=str(outputdir/"./calcos_processed_1"))
calcos.calcos('./data/ldifcombo_2_asn.fits',
verbosity=0,
outdir=str(outputdir/"./calcos_processed_1"))

# %%
# Read in the processed data
Expand All @@ -37,12 +39,14 @@
wvln, flux = segment["WAVELENGTH", "FLUX"]
plt.plot(wvln, flux)

plt.xlabel('Wavelength [$\AA$]')
plt.ylabel('Flux [ergs/s/$cm^2$/$\AA$]')
plt.xlabel(r'Wavelength [$\AA$]')
plt.ylabel(r'Flux [ergs/s/$cm^2$/$\AA$]')

plt.title("If this graph looks at all reasonable, your ASN file seems to have worked\n")
plt.tight_layout()
plot_path = str(plotsdir/"AsnFile_test.png")
plt.savefig(plot_path, bbox_inches = 'tight', dpi = 200)
plt.savefig(plot_path,
bbox_inches='tight',
dpi=200)
print(f"Saved plot to: {plot_path}")
# %%
29 changes: 15 additions & 14 deletions notebooks/COS/AsnFile/test_removed_exposure_asn.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#!/usr/bin/env python3
#%%[markdown]
### From here, you can run the `CalCOS` pipeline on your association file where we've removed the empty exposure file.
##### Running `CalCOS` is explained in *much* more detail in our [Notebook on running the pipeline](https://github.com/spacetelescope/notebooks/blob/master/notebooks/COS/CalCOS/CalCOS.ipynb)

##### In short, to run the `CalCOS` pipeline, you will need the relavent reference files. These will need be hosted in the directory assigned the environmetn variable `lref`.
##### No matter *where* you place these files, you *must* create the lref environment variable.
# From here, you can run the `CalCOS` pipeline on your association file where we've removed the empty exposure file.
# Running `CalCOS` is explained in *much* more detail in our [Notebook on running the pipeline](https://github.com/spacetelescope/notebooks/blob/master/notebooks/COS/CalCOS/CalCOS.ipynb)

# In short, to run the `CalCOS` pipeline, you will need the relavent reference files. These will need be hosted in the directory assigned the environmetn variable `lref`.
# No matter *where* you place these files, you *must* create the lref environment variable.
# %%
import os, shutil
import os
import calcos
from astropy.table import Table
import matplotlib.pyplot as plt
from pathlib import Path
from astropy.io import fits
# %%
datadir = Path('./data/')
mast_download_dir = datadir / "mastDownload"
outputdir = Path('./output/')
plotsdir = Path('./output/plots/')
plotsdir = Path('./output/plots/')
# %%
######### Setting the lref environment variable:
### YOU LIKELY NEED TO CHANGE THIS LOCATION !
# Setting the lref environment variable:
# YOU LIKELY NEED TO CHANGE THIS LOCATION!
where_i_keep_my_ref_files = "/grp/hst/cdbs/lref/"
os.environ['lref'] = where_i_keep_my_ref_files
assert Path(os.environ['lref']).exists(), "Make sure to set the 'lref' environment variable to a valid path with all of your reference files."
# %%
remove_badfile_asn = "data/removed_badfile_asn.fits"
# Run the CalCOS pipeline on our asn file
calcos.calcos(remove_badfile_asn, verbosity=0, outdir=str(outputdir/"calcos_processed_remove_badfile/"))
calcos.calcos(remove_badfile_asn,
verbosity=0,
outdir=str(outputdir/"calcos_processed_remove_badfile/"))
# %%
# Read in the processed data
processed_data_tab = Table.read(str(outputdir/'calcos_processed_remove_badfile/')+'/ldif01010_x1dsum.fits')
Expand All @@ -36,12 +37,12 @@
wvln, flux = segment["WAVELENGTH", "FLUX"]
plt.plot(wvln, flux)

plt.xlabel('Wavelength [$\AA$]')
plt.ylabel('Flux [ergs/s/$cm^2$/$\AA$]')
plt.xlabel(r'Wavelength [$\AA$]')
plt.ylabel(r'Flux [ergs/s/$cm^2$/$\AA$]')

plt.title("If this plot looks reasonable, your ASN file seems to have worked\n")
plt.tight_layout()
plot_path = str(plotsdir/"remove_badfile_AsnFile_test.png")
plt.savefig(plot_path, bbox_inches = 'tight', dpi = 200)
plt.savefig(plot_path, bbox_inches='tight', dpi=200)
print(f"Saved plot to: {plot_path}")
# %%
43 changes: 23 additions & 20 deletions notebooks/COS/AsnFile/test_splitwave_asn.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
#!/usr/bin/env python3
#%%[markdown]
### From here, you can run the `CalCOS` pipeline on your new association SPLIT wavecal file.
##### Running `CalCOS` is explained in *much* more detail in our [Notebook on running the pipeline](https://github.com/spacetelescope/notebooks/blob/master/notebooks/COS/CalCOS/CalCOS.ipynb)
# From here, you can run the `CalCOS` pipeline on your new association SPLIT wavecal file.
# Running `CalCOS` is explained in *much* more detail in our [Notebook on running the pipeline](https://github.com/spacetelescope/notebooks/blob/master/notebooks/COS/CalCOS/CalCOS.ipynb)

##### In short, to run the `CalCOS` pipeline, you will need the relavent reference files. These will need be hosted in the directory assigned the environmetn variable `lref`.
##### No matter *where* you place these files, you *must* create the lref environment variable.
# %%
import os, shutil
# In short, to run the `CalCOS` pipeline, you will need the relavent reference files. These will need be hosted in the directory assigned the environmetn variable `lref`.
# No matter *where* you place these files, you *must* create the lref environment variable.

import os
import shutil
import calcos
from astropy.table import Table
import matplotlib.pyplot as plt
from pathlib import Path
from astropy.io import fits
# %%

datadir = Path('./data/')
mast_download_dir = datadir / "mastDownload"
lp6_1exp_datadir = datadir / "lp6_1exp_datadir"
lp6_1exp_datadir.mkdir(exist_ok=True)
outputdir = Path('./output/')
plotsdir = Path('./output/plots/')
plotsdir = Path('./output/plots/')
# %%
# Copy all of the relevant LP6 data files into the lp6_1exp_datadir
splitwave_rawtags = [
shutil.copy(rt, lp6_1exp_datadir / rt.name) \
for rt in mast_download_dir.glob("**/*rawtag*fits") \
# Only grab the necessary files
if fits.getval(rt, "ROOTNAME").upper() in ['LETC01M6Q','LETC01MTQ','LETC01MVQ']
shutil.copy(rt, lp6_1exp_datadir / rt.name)
for rt in mast_download_dir.glob("**/*rawtag*fits")
if fits.getval(rt, "ROOTNAME").upper() in ['LETC01M6Q', 'LETC01MTQ', 'LETC01MVQ']
]
# Copy the LP6 single exposure asn file we made into the directory where we moved all of the relevant exposures' data
lp6_1exp_asn = shutil.copy('data/letc01mtq_only_asn.fits', lp6_1exp_datadir)
# %%
######### Setting the lref environment variable:
### YOU LIKELY NEED TO CHANGE THIS LOCATION !

# Setting the lref environment variable:
# YOU LIKELY NEED TO CHANGE THIS LOCATION !
where_i_keep_my_ref_files = "/grp/hst/cdbs/lref/"
os.environ['lref'] = where_i_keep_my_ref_files
assert Path(os.environ['lref']).exists(), "Make sure to set the 'lref' environment variable to a valid path with all of your reference files."
# %%
# Run the CalCOS pipeline on our SPLIT wavecal asn file
calcos.calcos(lp6_1exp_asn, verbosity=0, outdir=str(outputdir/"calcos_processed_lp6_1exp/"))
calcos.calcos(lp6_1exp_asn,
verbosity=0,
outdir=str(outputdir/"calcos_processed_lp6_1exp/"))
# %%
# Read in the processed data
processed_data_tab = Table.read(str(outputdir/'calcos_processed_lp6_1exp/')+'/letc01mtq_only_x1dsum.fits')
Expand All @@ -47,12 +48,14 @@
wvln, flux = segment["WAVELENGTH", "FLUX"]
plt.plot(wvln, flux)

plt.xlabel('Wavelength [$\AA$]')
plt.ylabel('Flux [ergs/s/$cm^2$/$\AA$]')
plt.xlabel(r'Wavelength [$\AA$]')
plt.ylabel(r'Flux [ergs/s/$cm^2$/$\AA$]')

plt.title("If this plot looks reasonable, your ASN file seems to have worked\n")
plt.tight_layout()
plot_path = str(plotsdir/"LP6_1exposure_AsnFile_test.png")
plt.savefig(plot_path, bbox_inches = 'tight', dpi = 200)
plt.savefig(plot_path,
bbox_inches='tight',
dpi=200)
print(f"Saved plot to: {plot_path}")
# %%
21 changes: 9 additions & 12 deletions notebooks/COS/CalCOS/CalCOS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"## 1.1. Prerequisites\n",
"This tutorial assumes some basic knowledge of the command line and was built using a unix style shell. Those using a Windows computer will likely have the best results if working within the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10).\n",
"\n",
"If you do not already have any distribution of the `conda` tool, see [this page](https://stenv.readthedocs.io/en/latest/getting_started.html#getting-started) for instructions, and install either [`anaconda` (\\~ 3 GB, more beginner friendly, lots of extras you likely won't use)](https://docs.anaconda.com/anaconda/install/), [`miniconda` (\\~ 400 MB, only what you need to make environments)](https://docs.conda.io/en/latest/miniconda.html), or [`mamba` (\\~85 MB, similar to `miniconda` but rewritten in C++).](https://mamba.readthedocs.io/en/latest/installation.html)\n"
"If you do not already have any distribution of the `conda` tool, see [this page](https://stenv.readthedocs.io/en/latest/getting_started.html#getting-started) for instructions, and install either [`anaconda` (\\~ 3 GB, more beginner friendly, lots of extras you likely won't use)](https://docs.anaconda.com/anaconda/install/), [`miniconda` (\\~ 400 MB, only what you need to make environments)](https://docs.conda.io/en/latest/miniconda.html), or [`mamba` (\\~85 MB, similar to `miniconda` but rewritten in C++).](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html)\n"
]
},
{
Expand Down Expand Up @@ -442,7 +442,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -459,11 +459,8 @@
"# This command looks up the pmap file, which tells what ref files to download.\n",
"# It then downloads these to the CRDS_PATH directory.\n",
"# Make sure you have the latest pmap file, found on the CRDS site.\n",
"!crds bestrefs \\\n",
" --files data/*raw*.fits \\\n",
" --sync-references=2 \\\n",
" --update-bestrefs \\\n",
" --new-context 'hst_1071.pmap'"
"!crds bestrefs --files data/*raw*.fits --sync-references=2\n",
"!crds bestrefs --update-bestrefs --new-context 'hst_1140.pmap'"
]
},
{
Expand Down Expand Up @@ -579,10 +576,10 @@
"# 1st param specifies which asn file to run the pipeline on\n",
"try:\n",
" calcos.calcos(str(datadir/asn_name),\n",
" # verbosity param\n",
" verbosity=2,\n",
" # Save all resulting files in this subdirectory in our outdir\n",
" outdir=str(outputdir/\"calcos_processed_1\"))\n",
" # verbosity param\n",
" verbosity=2,\n",
" # Save all resulting files in this subdirectory in our outdir\n",
" outdir=str(outputdir/\"calcos_processed_1\"))\n",
"except RuntimeError as e:\n",
" print('An error occured, ', e)"
]
Expand Down Expand Up @@ -1096,7 +1093,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
7 changes: 6 additions & 1 deletion notebooks/COS/DataDl/DataDl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@
" - Clicking the single dataset download button will attempt to open a \"pop-up\" window, which you must allow in order to download the file. Some browsers will require you to manually allow pop-ups.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -580,7 +585,7 @@
"print(col_data[sort_order])\n",
"\n",
"chosenObs = col_data[sort_order][-1] # Grab the last value of the sorted list\n",
"print(f\"\\n\\nThe longest COS/FUV exposure with the G160M filter is:\" +\n",
"print(\"\\n\\nThe longest COS/FUV exposure with the G160M filter is:\" +\n",
" f\"\\n\\n{chosenObs}\")"
]
},
Expand Down
16 changes: 11 additions & 5 deletions notebooks/COS/LSF/LSF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,19 @@
"<font size=\"4 \"><b>Where can you find the LSF files?</b></font>\n",
"The COS team maintains up-to-date LSF files on the [COS Spectral Resolution page](https://www.stsci.edu/hst/instrumentation/cos/performance/spectral-resolution). Opening up this link leads to a page like that shown in Fig. 1.1, where the LSF files are discussed in detail. The bottom part of this page has links to all the relavent files. The links at the top of the page will take you to the relevant section. In Fig. 1.1, we have circled in black the link to the section pertaining to our data: FUV at the Lifetime Position: 3.\n",
"\n",
"### <center> Fig 1.1: Screenshot of the COS Spectral Resolution Site</center>\n",
"<img src=./figures/LSFHomepage.png width =\"900\" title=\"COS Spectral Resolution Site\" alt=\"COS Spectral Resolution Site\">\n",
"<div style=\"text-align:center\">\n",
"<img src=\"./figures/LSFHomepage.png\" width=\"900\" alt=\"COS Spectral Resolution Site\">\n",
"<p>Fig 1.1: Screenshot of the COS Spectral Resolution Site</p>\n",
"</div>\n",
"\n",
"\n",
"Clicking on the circled link takes us to the table of hyperlinks to all the files perataining to data taken with the FUV, Lifetime Postition 3 configutation, shown in Fig. 1.2:\n",
"\n",
"### <center>Fig 1.2: Screenshot of the COS Spectral Resolution Site - Focus on LP-POS 3</center>\n",
"<img src=./figures/LSFHomepage2.png width =\"900\" title=\"COS Spectral Resolution Site - Lifetime Position 3\" alt=\"COS Spectral Resolution Site - Lifetime Position 3\">\n",
"<div style=\"text-align:center\">\n",
"<img src=\"./figures/LSFHomepage2.png\" width=\"900\" alt=\"COS Spectral Resolution Site - Lifetime Position 3\">\n",
"<p>Fig 1.2: Screenshot of the COS Spectral Resolution Site - Focus on LP-POS 3</p>\n",
"</div>\n",
"\n",
"\n",
"Circled in solid red is the button to download the LSF file we need for our data with CENWAVE = 1291. Circled in dashed black is the corresponding CDSF.\n",
"\n",
Expand Down Expand Up @@ -1341,7 +1347,7 @@
" continuum (array or -1) : if -1, default of continuum of 1, \\\n",
" otherwise must be same length as emitspec\n",
" \"\"\"\n",
" if type(continuum) == int:\n",
" if type(continuum) is int:\n",
" if continuum == -1:\n",
" continuum = np.ones(len(emitspec))\n",
" \n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/COS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If you don't want to run the Notebooks for yourself but just want to see rendere

|Name|Topic|Notebook file (`ipynb`)|Rendered file (`html`)|
|-|-|-|-|
|Setup|Setting up an environment to work with COS data|[Setup.ipynb](https://github.com/spacetelescope/hst_notebooks/blob/master/notebooks/COS/Setup/Setup.ipynb)|[Setup.html](https://spacetelescope.github.io/hst_notebooks/notebooks/COS/Setup/Setup.html)|
|Setup|Setting up an environment to work with COS data|[Setup.ipynb](https://github.com/spacetelescope/hst_notebooks/blob/main/notebooks/COS/Setup/Setup.ipynb)|[Setup.html](https://spacetelescope.github.io/hst_notebooks/notebooks/COS/Setup/Setup.html)|
|DataDl|Downloading COS Data from the archive|[DataDl.ipynb](https://github.com/spacetelescope/hst_notebooks/blob/master/notebooks/COS/DataDl/DataDl.ipynb)|[DataDl.html](https://spacetelescope.github.io/hst_notebooks/notebooks/COS/DataDl/DataDl.html)|
|ViewData|Beginning to work with COS data in Python: *plotting, binning, calculating SNR, & evaluating* a spectrum|[ViewData.ipynb](https://github.com/spacetelescope/hst_notebooks/blob/master/notebooks/COS/ViewData/ViewData.ipynb)|[ViewData.html](https://spacetelescope.github.io/hst_notebooks/notebooks/COS/ViewData/ViewData.html)|
|AsnFile|Modifying or creating an association file|[AsnFile.ipynb](https://github.com/spacetelescope/hst_notebooks/blob/master/notebooks/COS/AsnFile/AsnFile.ipynb)|[AsnFile.html](https://spacetelescope.github.io/hst_notebooks/notebooks/COS/AsnFile/AsnFile.html)|
Expand Down
Loading
Loading