Download IGRINS data from Box¶
IGRINS is in the process of migrating its data to the Box cloud data storage service. Here we show how to programmatically fetch that data with Python.
[1]:
from muler.igrins import IGRINSSpectrum
import requests
%matplotlib inline
%config InlineBackend.figure_format='retina'
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from muler.igrins import IGRINSSpectrum
2 import requests
3 get_ipython().run_line_magic('matplotlib', 'inline')
File ~/checkouts/readthedocs.org/user_builds/muler/envs/latest/lib/python3.8/site-packages/muler/igrins.py:15
13 import json
14 from matplotlib import pyplot as plt
---> 15 from muler.echelle import EchelleSpectrum, EchelleSpectrumList
16 from muler.utilities import Slit, concatenate_orders, resample_list, roll_along_axis, edge_normalize, isolate_and_normalize_hi_order, round_to_multiple, photometry
17 from astropy.time import Time
File ~/checkouts/readthedocs.org/user_builds/muler/envs/latest/lib/python3.8/site-packages/muler/echelle.py:31
29 from scipy.ndimage import median_filter, gaussian_filter1d
30 import specutils
---> 31 from muler.utilities import apply_numpy_mask, is_list, resample_list
34 # from barycorrpy import get_BC_vel
35 from astropy.coordinates import SkyCoord, EarthLocation
File ~/checkouts/readthedocs.org/user_builds/muler/envs/latest/lib/python3.8/site-packages/muler/utilities.py:15
13 from astropy.convolution import convolve, Gaussian1DKernel
14 from scipy.ndimage import binary_dilation
---> 15 from astroquery.simbad import Simbad
16 Simbad.add_votable_fields('V', 'B', 'J', 'H', 'K', 'parallax')
17 LinInterpResampler = LinearInterpolatedResampler()
ModuleNotFoundError: No module named 'astroquery'
For now, you need the filename and Box static filename to fetch a spectrum. Eventually this information may come from an observation Log provided by the IGRINS team. At the moment, I just retrieved this information by navigating to the UTBox website.
These data are already public on the muler_example_date repo, but I uploaded them to a public UTBox folder for the purpose of this demo. Eventually the entire IGRINS archive may be in a public UTBox like this.
[2]:
URL = 'https://utexas.box.com/shared/static/'
download_dictionary = {'SDCH_20201202_0059.spec_a0v.fits':'verow76mp47nzk6m1t4y08xmwt0n6tlg.fits',
'SDCH_20201202_0059.sn.fits':'wl5roxf0zfgs3tnhqvnlkl9ixqp2xfve.fits'}
We need two files because the IGRINS pipeline houses the uncertainty values in a separate file from the flux values.
[3]:
def download_file(filename, file_id):
"""Download the file from Google Drive"""
session = requests.Session()
response = session.get(URL+file_id)
if response.status_code == 200: # Successfully found the file on Google Drive
with open(filename, "wb") as f:
f.write(response.content)
print("Downloaded {}".format(filename))
[4]:
for key, value in download_dictionary.items():
download_file(key, value)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[4], line 2
1 for key, value in download_dictionary.items():
----> 2 download_file(key, value)
Cell In[3], line 3, in download_file(filename, file_id)
1 def download_file(filename, file_id):
2 """Download the file from Google Drive"""
----> 3 session = requests.Session()
4 response = session.get(URL+file_id)
5 if response.status_code == 200: # Successfully found the file on Google Drive
NameError: name 'requests' is not defined
[5]:
spectrum = IGRINSSpectrum(file='SDCH_20201202_0059.spec_a0v.fits', order=11).normalize()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[5], line 1
----> 1 spectrum = IGRINSSpectrum(file='SDCH_20201202_0059.spec_a0v.fits', order=11).normalize()
NameError: name 'IGRINSSpectrum' is not defined
[6]:
spectrum = spectrum.trim_edges().remove_nans()
spectrum.plot();
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[6], line 1
----> 1 spectrum = spectrum.trim_edges().remove_nans()
2 spectrum.plot();
NameError: name 'spectrum' is not defined
Great, we fetched the spectrum from UTBox, did some light post-processing, and plotted it, all in one fell swoop.