%matplotlib inline

import matplotlib.pyplot as plt
plt.rcParams['figure.dpi'] = 150

"""
Explanation: The MIT License (MIT)<br>
Copyright (c) 2018 Massachusetts Institute of Technology<br>
Author: Cody Rude<br>
This software has been created in projects supported by the US National<br>
Science Foundation and NASA (PI: Pankratius)<br>
Permission is hereby granted, free of charge, to any person obtaining a copy<br>
of this software and associated documentation files (the "Software"), to deal<br>
in the Software without restriction, including without limitation the rights<br>
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
copies of the Software, and to permit persons to whom the Software is<br>
furnished to do so, subject to the following conditions:<br>
The above copyright notice and this permission notice shall be included in<br>
all copies or substantial portions of the Software.<br>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
THE SOFTWARE.<br>
Setup plotting libraries
End of explanation
"""


from skdaccess.framework.param_class import *
from skdaccess.astro.spectra.stream import DataFetcher

"""
Explanation: Import data fetcher
End of explanation
"""


ap_spectra_url = AutoList([
    'https://dr14.sdss.org/sas/dr14/eboss/spectro/redux/v5_10_0/spectra/lite/4055/spec-4055-55359-0596.fits',
])

"""
Explanation: Specify list of SDSS spectra URLs to retrieve
End of explanation
"""


df = DataFetcher([ap_spectra_url])

"""
Explanation: Create data fetcher
End of explanation
"""


dw = df.output()

label, data = next(dw.getIterator())

header = dw.info(label)

"""
Explanation: Access data and metadata
End of explanation
"""


plt.plot(10**data['loglam'], data['flux']);
plt.title(label.split('/')[-1]);
plt.ylabel('Flux ({})'.format(header['BUNIT']));
plt.xlabel('Wavelength (Ångströms)');

"""
Explanation: Plot spectra
End of explanation
"""


