Tellurics guide
The classes and methods in telluricutils allow to:
Read and plot telluric models generated with the ESO ESO Sky Model Calculator (https://www.eso.org/observing/etc/skycalc Noll et al. 2012)
Create telluric masks (0110) from models
Broaden telluric lines by a specific velocity
Plot telluric masks
The script tellmask read a SkyCalc model and creates a mask out of it, masking telluric lines below a certain depth.
[1]:
import os
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from popurri import peakutils
from popurri import plotutils
from popurri.plotutils import wavelength_label
from popurri import telluricutils
plotutils.mpl_custom_basic()
plotutils.mpl_size_same(font_size=18)
# Testing
%load_ext autoreload
%autoreload 2
telluricutils functions
Reading and plotting a mask
[2]:
dirout = './'
filtell = '/Users/marina/work/code/raccoon/raccoon/data/tellurics/CARM_VIS/telluric_mask_carm_short.dat'
tellmask0 = telluricutils.Mask(filin=filtell, dirout=dirout, diroutplot=dirout)
# Mask object attributes
# vars(tellmask0) # print attribute name and value
tellmask0.__dict__.keys() # print attribute name
w [5885.4555 5885.4565 5885.4761 5885.5938 5885.6133 5887.5166 5887.5366
5887.6738 5887.6934 5888.7734] [24409.082 24411.279 24411.359 24412.172 24412.256 24413.148 24413.232
24413.557 24413.637 24413.638]
f [0. 0. 1. 1. 0. 0. 1. 1. 0. 0.] [1. 1. 0. 0. 1. 1. 0. 0. 1. 0.]
w1 [5885.4761 5887.5366 5888.793 5889.2437 5891.207 5891.6592 5893.1714
5893.9771 5898.085 5898.438 ] [24106.672 24112.137 24131.916 24282.646 24285.479 24308.238 24318.531
24399.807 24409.082 24412.256]
w2 [5885.5938 5887.6738 5888.9302 5889.3418 5891.3252 5891.7769 5893.3682
5894.0752 5898.124 5898.4971] [24109.484 24129.502 24280.623 24282.969 24304.51 24317.639 24397.693
24408.514 24411.279 24413.148]
Join overlap between lines
w [5885.4555 5885.4565 5885.4761 5885.5938 5885.6133 5887.5166 5887.5366
5887.6738 5887.6934 5888.7734] [24409.082 24411.279 24411.359 24412.172 24412.256 24413.148 24413.232
24413.557 24413.637 24413.638]
f [0. 0. 1. 1. 0. 0. 1. 1. 0. 0.] [1. 1. 0. 0. 1. 1. 0. 0. 1. 0.]
w1 [5885.4761 5887.5366 5888.793 5889.2437 5891.207 5891.6592 5893.1714
5893.9771 5898.085 5898.438 ] [24106.672 24112.137 24131.916 24282.646 24285.479 24308.238 24318.531
24399.807 24409.082 24412.256]
w2 [5885.5938 5887.6738 5888.9302 5889.3418 5891.3252 5891.7769 5893.3682
5894.0752 5898.124 5898.4971] [24109.484 24129.502 24280.623 24282.969 24304.51 24317.639 24397.693
24408.514 24411.279 24413.148]
update after overlap
w [5885.4751 5885.4761 5885.5938 5885.5948 5887.5356 5887.5366 5887.6738
5887.6748 5888.792 5888.793 ] [24408.514 24408.515 24409.081 24409.082 24411.279 24411.28 24412.255
24412.256 24413.148 24413.149]
f [0. 1. 1. 0. 0. 1. 1. 0. 0. 1.] [1. 0. 0. 1. 1. 0. 0. 1. 1. 0.]
w1 [5885.4761 5887.5366 5888.793 5889.2437 5891.207 5891.6592 5893.1714
5893.9771 5898.085 5898.438 ] [24106.672 24112.137 24131.916 24282.646 24285.479 24308.238 24318.531
24399.807 24409.082 24412.256]
w2 [5885.5938 5887.6738 5888.9302 5889.3418 5891.3252 5891.7769 5893.3682
5894.0752 5898.124 5898.4971] [24109.484 24129.502 24280.623 24282.969 24304.51 24317.639 24397.693
24408.514 24411.279 24413.148]
[2]:
dict_keys(['filin', 'dirout', 'diroutplot', 'tag', 'utag', 'join_overlap', 'broaden_dv', 'w', 'f', 'w1', 'w2', 'Mask'])
[3]:
# Broadened mask lines by 30 km/s
tellmask = telluricutils.Mask(filin=filtell, broaden_dv=30*1.e3, dirout=dirout, diroutplot=dirout)
w [5885.4555 5885.4565 5885.4761 5885.5938 5885.6133 5887.5166 5887.5366
5887.6738 5887.6934 5888.7734] [24409.082 24411.279 24411.359 24412.172 24412.256 24413.148 24413.232
24413.557 24413.637 24413.638]
f [0. 0. 1. 1. 0. 0. 1. 1. 0. 0.] [1. 1. 0. 0. 1. 1. 0. 0. 1. 0.]
w1 [5885.4761 5887.5366 5888.793 5889.2437 5891.207 5891.6592 5893.1714
5893.9771 5898.085 5898.438 ] [24106.672 24112.137 24131.916 24282.646 24285.479 24308.238 24318.531
24399.807 24409.082 24412.256]
w2 [5885.5938 5887.6738 5888.9302 5889.3418 5891.3252 5891.7769 5893.3682
5894.0752 5898.124 5898.4971] [24109.484 24129.502 24280.623 24282.969 24304.51 24317.639 24397.693
24408.514 24411.279 24413.148]
Broadening mask by 30000.000 m/s
w [5885.4555 5885.4565 5885.4761 5885.5938 5885.6133 5887.5166 5887.5366
5887.6738 5887.6934 5888.7734] [24409.082 24411.279 24411.359 24412.172 24412.256 24413.148 24413.232
24413.557 24413.637 24413.638]
f [0. 0. 1. 1. 0. 0. 1. 1. 0. 0.] [1. 1. 0. 0. 1. 1. 0. 0. 1. 0.]
w1 [5884.88714495 5886.94743875 5888.20371303 5888.65436793 5890.61747146
5891.06962621 5892.58167488 5893.38729426 5897.49478318 5897.84774786] [24104.25966393 24109.72411705 24129.50113778 24280.21605435
24283.04877085 24305.80549338 24316.09746336 24397.36533014
24406.63940199 24409.81308437]
w2 [5886.18276683 5888.26297498 5889.5195007 5889.93114189 5891.91474037
5892.36648557 5893.95794481 5894.66501556 5898.71422072 5899.08735805] [24111.89661746 24131.91662065 24283.05274321 24285.39897797
24306.94213357 24320.07244738 24400.13445832 24410.95654117
24413.72181786 24415.59100489]
Join overlap between lines
w [5885.4555 5885.4565 5885.4761 5885.5938 5885.6133 5887.5166 5887.5366
5887.6738 5887.6934 5888.7734] [24409.082 24411.279 24411.359 24412.172 24412.256 24413.148 24413.232
24413.557 24413.637 24413.638]
f [0. 0. 1. 1. 0. 0. 1. 1. 0. 0.] [1. 1. 0. 0. 1. 1. 0. 0. 1. 0.]
w1 [5884.887144946968, 5886.947438754323, 5890.617471460227, 5892.5816748842335, 5897.494783184072, 5899.126419891105, 5902.411291143676, 5909.990532618923, 5911.763855146146, 5914.01063029059] [22740.753122632865, 22800.10918232332, 22847.049484573385, 23113.926775696007, 23147.31043468467, 23154.64370077695, 23273.807774926565, 23597.36839322469, 23623.576770310137, 23658.566268587627]
w2 [5886.182766831181, 5889.93114189065, 5892.366485569228, 5894.665015558337, 5899.087358054458, 5902.352784790496, 5903.788928489907, 5911.272177257911, 5913.025752719296, 5915.273477624887] [22797.83213320316, 22846.21397425223, 23105.532921502712, 23125.026872052113, 23152.560627058043, 23273.500728229716, 23593.676764792825, 23622.55665449194, 23658.176218557583, 24415.591004887072]
update after overlap
w [5884.88614495 5884.88714495 5886.18276683 5886.18376683 5886.94643875
5886.94743875 5889.93114189 5889.93214189 5890.61647146 5890.61747146] [23622.55665449 23622.55765449 23623.57577031 23623.57677031
23658.17621856 23658.17721856 23658.56526859 23658.56626859
24415.59100489 24415.59200489]
f [0. 1. 1. 0. 0. 1. 1. 0. 0. 1.] [1. 0. 0. 1. 1. 0. 0. 1. 1. 0.]
w1 [5884.887144946968, 5886.947438754323, 5890.617471460227, 5892.5816748842335, 5897.494783184072, 5899.126419891105, 5902.411291143676, 5909.990532618923, 5911.763855146146, 5914.01063029059] [22740.753122632865, 22800.10918232332, 22847.049484573385, 23113.926775696007, 23147.31043468467, 23154.64370077695, 23273.807774926565, 23597.36839322469, 23623.576770310137, 23658.566268587627]
w2 [5886.182766831181, 5889.93114189065, 5892.366485569228, 5894.665015558337, 5899.087358054458, 5902.352784790496, 5903.788928489907, 5911.272177257911, 5913.025752719296, 5915.273477624887] [22797.83213320316, 22846.21397425223, 23105.532921502712, 23125.026872052113, 23152.560627058043, 23273.500728229716, 23593.676764792825, 23622.55665449194, 23658.176218557583, 24415.591004887072]
[4]:
# Plot telluric mask
fig, ax = plt.subplots(1, 1, figsize=(16, 4), constrained_layout=True)
tellmask.plot_mask(ax=ax, zorder=-1, leglabel='Broadened telluric mask')
tellmask0.plot_mask(ax=ax, fscale=0.5, zorder=-1, color='dodgerblue', leglabel='Original (non-broadened) telluric mask')
ax.legend(fontsize='small')
plt.show(), plt.close()
# Zoom in to see line differences
fig, ax = plt.subplots(1, 1, figsize=(16, 4), constrained_layout=True)
tellmask.plot_mask(ax=ax, zorder=-1, leglabel='Broadened telluric mask')
tellmask0.plot_mask(ax=ax, fscale=0.5, zorder=-1, color='dodgerblue', leglabel='Original (non-broadened) telluric mask')
ax.legend(fontsize='small')
ax.set(xlim=(6275, 6330))
# ax.set(xlim=(6275, 6285))
plt.show(), plt.close()
# Zoom in to see line differences
fig, ax = plt.subplots(1, 1, figsize=(16, 4), constrained_layout=True)
tellmask.plot_mask(ax=ax, zorder=-1, leglabel='Broadened telluric mask')
tellmask0.plot_mask(ax=ax, fscale=0.5, zorder=-1, color='dodgerblue', leglabel='Original (non-broadened) telluric mask')
ax.legend(fontsize='small')
# ax.set(xlim=(6275, 6330))
# ax.set(xlim=(6275, 6285))
ax.set(xlim=(23500, 24015))
plt.show(), plt.close()
[4]:
(None, None)
Broadening the lines of a mask by a certain velocity
[5]:
# TODO
tellmask script
Quick start
You can see the arguments that the script takes by running tellmask -h:
[6]:
!tellmask -h
usage: tellmask [-h] [--tpltype {esoskycalc}]
[--fk {ftransmission,trans_o3,trans_ma,trans_rs,trans_ms}]
[--wmin WMIN] [--wmax WMAX] [--lisfcut LISFCUT [LISFCUT ...]]
[--dw DW] [--npixmin NPIXMIN] [--depthmin DEPTHMIN]
[--dirout DIROUT] [--diroutplot DIROUTPLOT]
[--filoutmask FILOUTMASK] [--cmap CMAP] [--pltsv] [--pltsh]
[--pltext PLTEXT [PLTEXT ...]] [--verbose] [--pause]
filtpl
`tellmask_from_esoskycalc.py` Build a telluric mask from a spectrum obtained
with the ESO Sky Model Calculator (https://www.eso.org/observing/etc/skycalc
Noll et al. 2012).
positional arguments:
filtpl Input spectrum file.
options:
-h, --help show this help message and exit
--tpltype {esoskycalc}
Input model type.
--fk {ftransmission,trans_o3,trans_ma,trans_rs,trans_ms}
Flux key to be used.
--wmin WMIN Minimum wavelength of the mask [A]. If None, use
minimum wavelength of the template provided.
--wmax WMAX Maximum wavelength of the mask [A]. If None, use
maximum wavelength of the template provided.
--lisfcut LISFCUT [LISFCUT ...]
Flux threshold(s) to select telluric lines (0 to 1).
I.e. fgood >= fcut, or fbad < fcut.
--dw DW Line "limit" to make a 0110 mask [A].
--npixmin NPIXMIN
--depthmin DEPTHMIN
--dirout DIROUT General output directory. Absolute path.
--diroutplot DIROUTPLOT
Directory inside DIROUT where to store general plots
(DIROUT/DIROUTPLOTS/)
--filoutmask FILOUTMASK
Name of the mask file. If None (default), name of the
input spectrum template changing extension to `.mas`.
--cmap CMAP Colormap to be used for the masks plot.
--pltsv Make and save plots.
--pltsh Show plots.
--pltext PLTEXT [PLTEXT ...]
Extensions of the plots to be saved (e.g. `--pltext
pdf png`)
--verbose
--pause Pause inside python after running.
We are going to run the script with some example model provided here.
These are the example models provided:
[7]:
dirhere = os.path.abspath('')
dirdata = os.path.join(dirhere, '../../popurri/data/esoskycalc/') # Directory with the example data
!echo {dirdata}
!ls {dirdata}
/Users/marina/work/code/popurri/docs/guides/../../popurri/data/esoskycalc/
lasilla_w300-1000_R100000_FWHM3.20bin_vac.fits
lasilla_w300-1000_R100000_FWHM3.20bin_vac_inputconfig.txt
paranal_w300-1000_R138000_FWHM4.50bin_vac.fits
paranal_w300-1000_R138000_FWHM4.50bin_vac_inputconfig.txt
paranal_w900-5400_R100000_FWHM5.0bin_vac.fits
paranal_w900-5400_R100000_FWHM5.0bin_vac_inputconfig.txt
We are going to generate several masks (including tellurics of different depths) using the model lasilla_w300-1000_R100000_FWHM3.20bin_vac.fits.
The next cell runs the script. You can change the dirout argument to a known location to see the outputs easily.
[6]:
filmod = 'lasilla_w300-1000_R100000_FWHM3.20bin_vac.fits'
dirout = os.path.join(dirhere, 'telluric/')
!tellmask {dirdata}/{filmod} --wmin 3600 --wmax 7100 --fk trans_ma --dirout {dirout} --diroutplot {dirout} --pltext png --pltsv --verbose
##################################################
Create telluric mask from a telluric model
##################################################
Input spectrum model: /Users/marina/work/code/popurri/docs/guides/../../popurri/data/esoskycalc//lasilla_w300-1000_R100000_FWHM3.20bin_vac.fits (esoskycalc, using trans_ma flux key)
Include tellurics below: [0.9, 0.95, 0.99, 0.995, 0.999, 0.9995, 0.9999]
Mask w limits: 3600.0 to 7100.0 A
Masks saved in: /Users/marina/work/code/popurri/docs/guides/telluric/
Plots saved in: /Users/marina/work/code/popurri/docs/guides/telluric/
Reading input spectrum /Users/marina/work/code/popurri/docs/guides/../../popurri/data/esoskycalc//lasilla_w300-1000_R100000_FWHM3.20bin_vac.fits
Cutting w from 3600.0 to 7100.0 A
Plotting spectrum
Finding lines
Plot: Removing lines with less than 3 pixels
Plot: Removing lines with more than 0.99995 depth
Plotting initial lines
Making mask including lines with more than {args.lisfcut} depth
Telluric mask saved: /Users/marina/work/code/popurri/docs/guides/telluric/mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.999900_npixmin3.mas
Telluric mask saved: /Users/marina/work/code/popurri/docs/guides/telluric/mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.999500_npixmin3.mas
Telluric mask saved: /Users/marina/work/code/popurri/docs/guides/telluric/mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.999000_npixmin3.mas
Telluric mask saved: /Users/marina/work/code/popurri/docs/guides/telluric/mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.995000_npixmin3.mas
Telluric mask saved: /Users/marina/work/code/popurri/docs/guides/telluric/mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.990000_npixmin3.mas
Telluric mask saved: /Users/marina/work/code/popurri/docs/guides/telluric/mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.950000_npixmin3.mas
Telluric mask saved: /Users/marina/work/code/popurri/docs/guides/telluric/mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.900000_npixmin3.mas
Plotting masks
These are the outputs from the script:
[7]:
!ls {dirout}
lasilla_w300-1000_R100000_FWHM3.20bin_vac_mask_fcut0.900000.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_mask_fcut0.950000.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_mask_fcut0.990000.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_mask_fcut0.995000.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_mask_fcut0.999000.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_mask_fcut0.999500.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_mask_fcut0.999900.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_masks.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_masks_panels.png
lasilla_w300-1000_R100000_FWHM3.20bin_vac_masks_zoomy1.png
mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.900000_npixmin3.mas
mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.950000_npixmin3.mas
mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.990000_npixmin3.mas
mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.995000_npixmin3.mas
mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.999000_npixmin3.mas
mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.999500_npixmin3.mas
mask_lasilla_w300-1000_R100000_FWHM3.20bin_vac_fcut0.999900_npixmin3.mas
spec_lasilla_w300-1000_R100000_FWHM3.20bin_vac.png
spec_lines_lasilla_w300-1000_R100000_FWHM3.20bin_vac_npixmin3_depthmin0.999950.png
spec_trans_comp_lasilla_w300-1000_R100000_FWHM3.20bin_vac.png
The masks generated can be easily used with the methods in telluricutils.
Let’s visualise the plot with the model specturm and all the masks generated:
[8]:
from IPython.display import Image
filmodname = os.path.splitext(os.path.basename(filmod))[0]
fig = Image(filename=(os.path.join(dirout, f'{filmodname}_masks_panels.png')))
fig
[8]:
Here are the same masks all in the same panel:
[9]:
from IPython.display import Image
filmodname = os.path.splitext(os.path.basename(filmod))[0]
fig = Image(filename=(os.path.join(dirout, f'{filmodname}_masks.png')))
fig
[9]:
And this is a zoomed-in version to the top 1% of the model, again with all the masks together:
[10]:
figz = Image(filename=(os.path.join(dirout, f'{filmodname}_masks_zoomy1.png')))
figz
[10]:
In detail
Here we follow what the script does step by step.
[11]:
# TODO