In [1]:
from mingle.utilities import masking
import numpy as np
from spectrum_overload import Spectrum
from astropy.io import fits
import matplotlib.pyplot as plt
import os
% matplotlib inline
In [2]:
observations = [{"star": "HD4747", "obsnum": "1", "chip": "1"},
{"star": "HD4747", "obsnum": "1", "chip": "2"},
{"star": "HD4747", "obsnum": "1", "chip": "3"},
{"star": "HD4747", "obsnum": "1", "chip": "4"},
{"star": "HD30501", "obsnum": "2a", "chip": "1"},
{"star": "HD30501", "obsnum": "2a", "chip": "2"},
{"star": "HD30501", "obsnum": "2a", "chip": "3"},
{"star": "HD30501", "obsnum": "2a", "chip": "4"},
{"star": "HD30501", "obsnum": "2b", "chip": "1"},
{"star": "HD30501", "obsnum": "2b", "chip": "2"},
{"star": "HD30501", "obsnum": "2b", "chip": "3"},
{"star": "HD30501", "obsnum": "2b", "chip": "4"},
{"star": "HD30501", "obsnum": "3", "chip": "1"},
{"star": "HD30501", "obsnum": "3", "chip": "2"},
{"star": "HD30501", "obsnum": "3", "chip": "3"},
{"star": "HD30501", "obsnum": "3", "chip": "4"},
{"star": "HD211847", "obsnum": "1", "chip": "1"},
{"star": "HD211847", "obsnum": "1", "chip": "2"},
{"star": "HD211847", "obsnum": "1", "chip": "3"},
{"star": "HD211847", "obsnum": "1", "chip": "4"},
{"star": "HD211847", "obsnum": "2", "chip": "1"},
{"star": "HD211847", "obsnum": "2", "chip": "2"},
{"star": "HD211847", "obsnum": "2", "chip": "3"},
{"star": "HD211847", "obsnum": "2", "chip": "4"},]
In [3]:
snrs = []
for obs in observations:
masks = masking.get_maskinfo(obs["star"], obs["obsnum"], obs["chip"])
# Load in a spectrum
name = "{0}-{1}-mixavg-tellcorr_{2}.fits".format(obs["star"], obs["obsnum"], obs["chip"])
data, hdr = fits.getdata(os.path.join("/home/jneal/.handy_spectra/", name), header=True)
spec = Spectrum(xaxis=data["wavelength"], flux=data["flux"], header=hdr)
spec2 = spec.copy()
for mask_limits in masks:
if len(mask_limits) is not 2:
raise ValueError("Mask limits in mask file is incorrect for {0}-{1}_{2}".format(obs["star"], obs["obsnum"], obs["chip"]))
spec2.wav_select(*mask_limits) # Wavelengths to include
snr = np.nanmean(spec.flux) / np.std(spec.flux)
plt.plot(spec.xaxis, spec.flux)
plt.plot(spec2.xaxis, spec2.flux)
if obs["chip"] == "1":
# lim = [2118.8, 2119.4]
lim = [2113.5, 2114.2]
elif obs["chip"] == "2":
lim = [2129, 2135]
elif obs["chip"] == "3":
lim = [2144.9, 2145.35]
else:
lim = [2159.8, 2160.1]
plt.axvline(x=lim[0])
plt.axvline(x=lim[1])
spec.wav_select(*lim)
sec_snr = np.nanmean(spec.flux)/ np.nanstd(spec.flux)
snrs.append(sec_snr)
print("full snr", snr, "Section snr", sec_snr)
plt.show()
In [4]:
print("average snr", np.mean(snrs))
print("median snr", np.median(snrs))
In [5]:
datafile = "/home/jneal/Phd/data/Crires/BDs-DRACS/2017/HD30501-1/Intermediate_steps/CRIRE.2012-04-07T00:08:29.976_1.nod.ms.fits"
datafile = "/home/jneal/Phd/data/Crires/BDs-DRACS/2017/HD30501-1/Intermediate_steps/CRIRE.2012-04-07T00:08:29.976_1.nod.ms.sum.fits"
data = fits.getdata(datafile)
print(data[0])
print(data[1])
data[2]
Out[5]:
In [ ]: