{ "cells": [ { "cell_type": "code", "execution_count": 64, "metadata": { "ExecuteTime": { "end_time": "2018-05-29T11:57:27.475966Z", "start_time": "2018-05-29T11:57:27.467839Z" }, "collapsed": false }, "outputs": [], "source": [ "import re\n", "import os\n", "from glob import glob\n", "\n", "import pandas as pd\n", "import numpy as np\n", "\n", "from astropy.io import fits\n", "from astropy.table import Table\n", "from astropy import units as u, constants as const\n", "\n", "from starkit.gridkit.io.process import BaseProcessGrid\n", "from starkit.gridkit import load_grid\n", "from scipy import ndimage as nd\n", "from scipy.interpolate import interp1d\n" ] }, { "cell_type": "code", "execution_count": 67, "metadata": { "ExecuteTime": { "end_time": "2018-05-29T11:58:46.539236Z", "start_time": "2018-05-29T11:58:46.530411Z" }, "collapsed": true }, "outputs": [], "source": [ "moehler_bib = \"\"\"@ARTICLE{2014A&A...568A...9M,\n", " author = {{Moehler}, S. and {Modigliani}, A. and {Freudling}, W. and\n", " {Giammichele}, N. and {Gianninas}, A. and {Gonneau}, A. and\n", " {Kausch}, W. and {Lan{\\c{c}}on}, A. and {Noll}, S. and {Rauch},\n", " T. and {Vinther}, J.},\n", " title = \"{Flux calibration of medium-resolution spectra from 300 nm to 2500 nm:\n", " Model reference spectra and telluric correction}\",\n", " journal = {\\aap},\n", " keywords = {standards, techniques: spectroscopic, Astrophysics - Instrumentation and\n", " Methods for Astrophysics, Astrophysics - Solar and Stellar\n", " Astrophysics},\n", " year = 2014,\n", " month = Aug,\n", " volume = {568},\n", " eid = {A9},\n", " pages = {A9},\n", " doi = {10.1051/0004-6361/201423790},\n", " adsurl = {https://ui.adsabs.harvard.edu/#abs/2014A&A...568A...9M},\n", " adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n", "}\n", "\n", "\n", "\"\"\"\n", "moehler_telluric_meta = pd.Series([moehler_bib, ['airmass', 'pwv'], 'vacuum', 'Angstrom', '1'], \n", " index=[u'bibtex', u'parameters', u'wavelength_type', u'wavelength_unit', 'flux_unit'], )\n" ] }, { "cell_type": "code", "execution_count": 51, "metadata": { "ExecuteTime": { "end_time": "2018-05-29T11:55:25.558435Z", "start_time": "2018-05-29T11:55:25.543662Z" }, "collapsed": false }, "outputs": [], "source": [ "class MoehlerTelluric(BaseProcessGrid):\n", " R_initial = 60000.\n", " R_initial_sampling=1\n", "\n", " def __init__(self, index, input_wavelength, meta, wavelength_start=0*u.angstrom, wavelength_stop=np.inf*u.angstrom,\n", " R=None, R_sampling=4):\n", " super(MoehlerTelluric, self).__init__(index, input_wavelength, meta, wavelength_start=wavelength_start,\n", " wavelength_stop=wavelength_stop, R=R, R_sampling=R_sampling)\n", " def load_flux(self, fname):\n", " return Table.read(fname)['trans']\n", " \n", " def interp_wavelength(self, flux):\n", " cut_flux = flux[self.start_idx:self.stop_idx]\n", " rescaled_R = 1 / np.sqrt((1/self.R)**2 - (1/self.R_initial)**2)\n", " sigma = ((self.R_initial / rescaled_R) * self.R_initial_sampling\n", " / (2 * np.sqrt(2 * np.log(2))))\n", "\n", " processed_flux = nd.gaussian_filter1d(cut_flux, sigma)\n", " output_flux = interp1d(self.cut_wavelength, processed_flux)(\n", " self.output_wavelength)\n", " return output_flux\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Generating Index for Telluric Data ####" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2018-05-29T11:16:45.910691Z", "start_time": "2018-05-29T11:16:45.905347Z" }, "collapsed": false }, "outputs": [], "source": [ "lbl_telluric_pattern = re.compile('LBL_A(\\d\\d)_s0_w(\\d\\d\\d).+?\\.fits')" ] }, { "cell_type": "code", "execution_count": 54, "metadata": { "ExecuteTime": { "end_time": "2018-05-29T11:55:54.817092Z", "start_time": "2018-05-29T11:55:54.798642Z" }, "collapsed": false }, "outputs": [], "source": [ "fname_list = np.sort(glob('LBL*.fits'))\n", "raw_index = pd.DataFrame(index=np.arange(len(fname_list)), columns=['airmass', 'pwv', 'filename'])\n", "for i, fname in enumerate(fname_list):\n", " airmass, pwv = lbl_telluric_pattern.match(os.path.basename(fname)).groups()\n", " airmass = float(airmass) / 10.\n", " pwv = float(pwv) / 10.\n", " raw_index.iloc[i] = (airmass, pwv, fname)" ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "ExecuteTime": { "end_time": "2018-05-29T11:55:55.633768Z", "start_time": "2018-05-29T11:55:55.600102Z" }, "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | airmass | \n", "pwv | \n", "filename | \n", "
---|---|---|---|
0 | \n", "1 | \n", "0.5 | \n", "LBL_A10_s0_w005_R0060000_T.fits | \n", "
1 | \n", "1 | \n", "1 | \n", "LBL_A10_s0_w010_R0060000_T.fits | \n", "
2 | \n", "1 | \n", "1.5 | \n", "LBL_A10_s0_w015_R0060000_T.fits | \n", "
3 | \n", "1 | \n", "2.5 | \n", "LBL_A10_s0_w025_R0060000_T.fits | \n", "
4 | \n", "1 | \n", "3.5 | \n", "LBL_A10_s0_w035_R0060000_T.fits | \n", "
5 | \n", "1 | \n", "5 | \n", "LBL_A10_s0_w050_R0060000_T.fits | \n", "
6 | \n", "1 | \n", "7.5 | \n", "LBL_A10_s0_w075_R0060000_T.fits | \n", "
7 | \n", "1 | \n", "10 | \n", "LBL_A10_s0_w100_R0060000_T.fits | \n", "
8 | \n", "1 | \n", "20 | \n", "LBL_A10_s0_w200_R0060000_T.fits | \n", "
9 | \n", "1.5 | \n", "0.5 | \n", "LBL_A15_s0_w005_R0060000_T.fits | \n", "
10 | \n", "1.5 | \n", "1 | \n", "LBL_A15_s0_w010_R0060000_T.fits | \n", "
11 | \n", "1.5 | \n", "1.5 | \n", "LBL_A15_s0_w015_R0060000_T.fits | \n", "
12 | \n", "1.5 | \n", "2.5 | \n", "LBL_A15_s0_w025_R0060000_T.fits | \n", "
13 | \n", "1.5 | \n", "3.5 | \n", "LBL_A15_s0_w035_R0060000_T.fits | \n", "
14 | \n", "1.5 | \n", "5 | \n", "LBL_A15_s0_w050_R0060000_T.fits | \n", "
15 | \n", "1.5 | \n", "7.5 | \n", "LBL_A15_s0_w075_R0060000_T.fits | \n", "
16 | \n", "1.5 | \n", "10 | \n", "LBL_A15_s0_w100_R0060000_T.fits | \n", "
17 | \n", "1.5 | \n", "20 | \n", "LBL_A15_s0_w200_R0060000_T.fits | \n", "
18 | \n", "2 | \n", "0.5 | \n", "LBL_A20_s0_w005_R0060000_T.fits | \n", "
19 | \n", "2 | \n", "1 | \n", "LBL_A20_s0_w010_R0060000_T.fits | \n", "
20 | \n", "2 | \n", "1.5 | \n", "LBL_A20_s0_w015_R0060000_T.fits | \n", "
21 | \n", "2 | \n", "2.5 | \n", "LBL_A20_s0_w025_R0060000_T.fits | \n", "
22 | \n", "2 | \n", "3.5 | \n", "LBL_A20_s0_w035_R0060000_T.fits | \n", "
23 | \n", "2 | \n", "5 | \n", "LBL_A20_s0_w050_R0060000_T.fits | \n", "
24 | \n", "2 | \n", "7.5 | \n", "LBL_A20_s0_w075_R0060000_T.fits | \n", "
25 | \n", "2 | \n", "10 | \n", "LBL_A20_s0_w100_R0060000_T.fits | \n", "
26 | \n", "2 | \n", "20 | \n", "LBL_A20_s0_w200_R0060000_T.fits | \n", "
27 | \n", "2.5 | \n", "0.5 | \n", "LBL_A25_s0_w005_R0060000_T.fits | \n", "
28 | \n", "2.5 | \n", "1 | \n", "LBL_A25_s0_w010_R0060000_T.fits | \n", "
29 | \n", "2.5 | \n", "1.5 | \n", "LBL_A25_s0_w015_R0060000_T.fits | \n", "
30 | \n", "2.5 | \n", "2.5 | \n", "LBL_A25_s0_w025_R0060000_T.fits | \n", "
31 | \n", "2.5 | \n", "3.5 | \n", "LBL_A25_s0_w035_R0060000_T.fits | \n", "
32 | \n", "2.5 | \n", "5 | \n", "LBL_A25_s0_w050_R0060000_T.fits | \n", "
33 | \n", "2.5 | \n", "7.5 | \n", "LBL_A25_s0_w075_R0060000_T.fits | \n", "
34 | \n", "2.5 | \n", "10 | \n", "LBL_A25_s0_w100_R0060000_T.fits | \n", "
35 | \n", "2.5 | \n", "20 | \n", "LBL_A25_s0_w200_R0060000_T.fits | \n", "
36 | \n", "3 | \n", "0.5 | \n", "LBL_A30_s0_w005_R0060000_T.fits | \n", "
37 | \n", "3 | \n", "1 | \n", "LBL_A30_s0_w010_R0060000_T.fits | \n", "
38 | \n", "3 | \n", "1.5 | \n", "LBL_A30_s0_w015_R0060000_T.fits | \n", "
39 | \n", "3 | \n", "2.5 | \n", "LBL_A30_s0_w025_R0060000_T.fits | \n", "
40 | \n", "3 | \n", "3.5 | \n", "LBL_A30_s0_w035_R0060000_T.fits | \n", "
41 | \n", "3 | \n", "5 | \n", "LBL_A30_s0_w050_R0060000_T.fits | \n", "
42 | \n", "3 | \n", "7.5 | \n", "LBL_A30_s0_w075_R0060000_T.fits | \n", "
43 | \n", "3 | \n", "10 | \n", "LBL_A30_s0_w100_R0060000_T.fits | \n", "
44 | \n", "3 | \n", "20 | \n", "LBL_A30_s0_w200_R0060000_T.fits | \n", "