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

Changedate #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
423 changes: 398 additions & 25 deletions notebooks/COS/AsnFile/AsnFile.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions notebooks/COS/AsnFile/test_asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,33 @@
outputdir = Path('./output/')
plotsdir = Path('./output/plots/')
# %%
######### SETTING THE lref VARIABLE:
######### 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."

# Copy the asn file we made into the directory where we moved all of our ldif* exposures' data
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"))

# %%
# Read in the processed data
processed_data_tab = Table.read(str(outputdir/'calcos_processed_1/')+'/ldifcombo_x1dsum.fits')

# Plot the processed data
for segment in processed_data_tab:
wvln, flux = segment["WAVELENGTH", "FLUX"]
plt.plot(wvln, flux)

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

plt.title("If this graph looks reasonable, your ASN file seems to have worked\n")
plt.title("If this graph looks at all reasonable, your ASN file seems to have worked\n")
plt.tight_layout()
plt.savefig(str(plotsdir/"AsnFile_test.png"), bbox_inches = 'tight', dpi = 200)
plot_path = str(plotsdir/"AsnFile_test.png")
plt.savefig(plot_path, bbox_inches = 'tight', dpi = 200)
print(f"Saved plot to: {plot_path}")
# %%
47 changes: 47 additions & 0 deletions notebooks/COS/AsnFile/test_removed_exposure_asn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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.
# %%
import os, 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"
outputdir = Path('./output/')
plotsdir = Path('./output/plots/')
# %%
######### 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/"))
# %%
# Read in the processed data
processed_data_tab = Table.read(str(outputdir/'calcos_processed_remove_badfile/')+'/ldif01010_x1dsum.fits')

# Plot the processed data
for segment in processed_data_tab:
wvln, flux = segment["WAVELENGTH", "FLUX"]
plt.plot(wvln, flux)

plt.xlabel('Wavelength [$\AA$]')
plt.ylabel('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)
print(f"Saved plot to: {plot_path}")
# %%
58 changes: 58 additions & 0 deletions notebooks/COS/AsnFile/test_splitwave_asn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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)

##### 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 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/')
# %%
# 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']
]
# 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 !
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/"))
# %%
# Read in the processed data
processed_data_tab = Table.read(str(outputdir/'calcos_processed_lp6_1exp/')+'/letc01mtq_only_x1dsum.fits')

# Plot the processed data
for segment in processed_data_tab:
wvln, flux = segment["WAVELENGTH", "FLUX"]
plt.plot(wvln, flux)

plt.xlabel('Wavelength [$\AA$]')
plt.ylabel('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)
print(f"Saved plot to: {plot_path}")
# %%
7 changes: 4 additions & 3 deletions notebooks/COS/DataDl/DataDl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,9 @@
"---\n",
"## About this Notebook\n",
"**Author:** Nat Kerman <[email protected]>\n",
"**Edited by:** Travis Fischer <[email protected]>\n",
"\n",
"**Updated On:** 2022-02-25\n",
"**Updated On:** 2022-09-09\n",
"\n",
"> *This tutorial was generated to be in compliance with the [STScI style guides](https://github.com/spacetelescope/style-guides) and would like to cite the [Jupyter guide](https://github.com/spacetelescope/style-guides/blob/master/templates/example_notebook.ipynb) in particular.*\n",
"\n",
Expand Down Expand Up @@ -913,7 +914,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.5 ('fs2')",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -927,7 +928,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
"version": "3.9.7"
},
"vscode": {
"interpreter": {
Expand Down