Testing script on Simulations_140425¶
Test on Simulation 140425.
The full simulation is pointed to by the environment variable
SIM140425PATH=/path/to/Simulations_140425/.
Warning
deprecated, see notebook “Test cases from Simulations 140425”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time-stamp: <2016-03-14 15:18:56 ycopin>
from __future__ import print_function, division
__author__ = "Yannick Copin <y.copin@ipnl.in2p3.fr>"
import os
import numpy as N
import matplotlib.pyplot as P
try:
import seaborn
seaborn.set_style("whitegrid", {"font.family": ["DejaVu Sans"]})
except ImportError:
pass
from inspec.spectrum import SimSpectrum, fit_adaptive, plot_specs
from inspec.sim140425 import read_sim_input, fig_hist_survey
from inspec import tools, synth
datapath = "../inspec/data/"
emilines = tools.parse_json(os.path.join(datapath, "emissionLines.json"))
simpath = os.getenv("SIM140425PATH", "../inspec/data/Simulations_140425/")
simpath = os.path.join(simpath, "Uncontaminated/")
filename = os.path.join(simpath, "uncontaminated_spectra.dat")
metadata = read_sim_input(filename)
colnames = metadata.dtype.names
# Survey histograms
if False:
fig = fig_hist_survey(metadata,
title="%s (%d entries)" % (
filename, len(metadata)))
# Test cases
# 7199, 35992, 39350, 44377, 81628, 120340, 185467: faint Ha
# 202579: faint Ha, Hb and [OIII] not detected
# 76798, 30744, 123934: faint [OIII] (no Hb)
# 6001, 7764, 47401, 159098: Ha outside selected spectral range
nspec = 20
sample = metadata[N.argsort(metadata['fHa'])
[-nspec:]]['idx'] # Top signals
sample = [10568, 15944] # ../data/Simulations_140425/
for i, idx in enumerate(sample, start=1):
print(" {}/{}: ID {} ".format(i, len(sample), idx).center(50, '-'))
# Reading
sdict = SimSpectrum.from_idx(idx, path=os.path.join(simpath, "*/"))
# Merging
merged = SimSpectrum.merge_specs(sdict, rtol=None)
subdata = metadata[N.searchsorted(metadata['idx'], idx)]
merged.writeto("spectrum_%d_merged.fits" % idx,
keywords=dict(zip(colnames, subdata)))
# Polynomial continuum + emission lines
cont, lines = fit_adaptive(merged, pmax=0.05, dmax=3, nmax=5, verbose=2)
# Plot
fig = plot_specs(sdict,
model=(cont, lines),
metadata=subdata,
emilines=emilines)
fig.tight_layout()
# Primer test of flux integration
print(merged)
band = synth.Filter.bandpass("test", 14000, 16000)
print(band)
f, df = band.integrate(merged) # Flux
f /= 1e17 # Scale for the 1e-17 flux normalization
df /= 1e17
print("Flux in {!r}: {:g} +/- {:g}".format(band.name, f, df))
m, dm = band.magn(merged) # AB-magnitude
m += 17 * 2.5 # Offset for the 1e-17 flux normalization
print("AB-magn in {!r}: {:f} +/- {:f}".format(band.name, m, dm))
P.show()
|