def test_instrument_and_stellar_convolve_TRES(self): from StellarSpectra.grid_tools import TRES instrument = TRES() low, high = instrument.wl_range instrument_fine = TRES() instrument_fine.wl_dict = create_log_lam_grid(low, high, min_vc=0.05 / C.c_kms) log_spec = self.spec.to_LogLambda(instrument=instrument, min_vc=0.1 / C.c_kms) print("Before convolve", log_spec.get_min_v(), "km/s") log_spec2 = log_spec.copy() log_spec.instrument_and_stellar_convolve(instrument, 20) print("After convolve", log_spec.get_min_v(), "km/s") log_spec2.instrument_and_stellar_convolve(instrument_fine, 20) interp = InterpolatedUnivariateSpline(log_spec.wl, log_spec.fl, k=5) fl = interp(log_spec2.wl) assert np.allclose(fl, log_spec2.fl), "Spectral information not preserved."
def setup_class(self): self.DataSpectrum = DataSpectrum.open( "../data/WASP14/WASP-14_2009-06-15_04h13m57s_cb.spec.flux", orders=np.array([22])) self.Instrument = TRES() self.HDF5Interface = HDF5Interface( "../libraries/PHOENIX_submaster.hdf5") stellar_Starting = { "temp": 6000, "logg": 4.05, "Z": -0.4, "vsini": 10.5, "vz": 15.5, "logOmega": -19.665 } stellar_tuple = C.dictkeys_to_tuple(stellar_Starting) cheb_tuple = ("c1", "c2", "c3") cov_tuple = ("sigAmp", "logAmp", "l") region_tuple = ("h", "loga", "mu", "sigma") self.Model = Model(self.DataSpectrum, self.Instrument, self.HDF5Interface, stellar_tuple=stellar_tuple, cheb_tuple=cheb_tuple, cov_tuple=cov_tuple, region_tuple=region_tuple, outdir="")
def test_closeness_TRES(self): ''' First convert self.spec from a Base1DSpectrum to a LogLambdaSpectrum. Then, convert it back to the original wl_grid and see if all of the information is preserved. ''' from StellarSpectra.grid_tools import TRES instrument = TRES() log_spec = self.spec.to_LogLambda(instrument=instrument, min_vc=0.1 / C.c_kms) print(log_spec.get_min_v(), "km/s") interp = InterpolatedUnivariateSpline(log_spec.wl, log_spec.fl, k=5) #truncate original wl and fl to instrument ranges low, high = instrument.wl_range ind = (self.wl >= low) & (self.wl <= high) wl = self.spec.wl[ind] fl = self.spec.fl[ind] fl_back = interp(wl) #import matplotlib.pyplot as plt #fig, ax = plt.subplots(nrows=2, sharex=True) #ax[0].plot(wl, fl) #ax[0].plot(wl, fl_back) #ax[1].plot(wl, fl - fl_back) #plt.show() assert np.allclose(fl, fl_back), "Spectral information lost"
def setup_class(self): from StellarSpectra.grid_tools import HDF5Interface, ModelInterpolator, TRES #libraries/PHOENIX_submaster.hd5 should have the following bounds #{"temp":(6000, 7000), "logg":(3.5,5.5), "Z":(-1.0,0.0), "alpha":(0.0,0.4)} myHDF5Interface = HDF5Interface("../libraries/PHOENIX_submaster.hdf5") myDataSpectrum = DataSpectrum.open( "/home/ian/Grad/Research/Disks/StellarSpectra/StellarSpectra/tests/WASP14/WASP-14_2009-06-15_04h13m57s_cb.spec.flux", orders=np.array([21, 22, 23])) self.DataSpectrum = myDataSpectrum myInterpolator = ModelInterpolator(myHDF5Interface, myDataSpectrum) myInstrument = TRES() self.model = ModelSpectrum(myInterpolator, myInstrument)
def test_instrument_and_stellar_convolve_TRES(self): from StellarSpectra.grid_tools import TRES instrument = TRES() low, high = instrument.wl_range instrument_fine = TRES() instrument_fine.wl_dict = create_log_lam_grid(low, high, min_vc=0.05/C.c_kms) log_spec = self.spec.to_LogLambda(instrument=instrument, min_vc=0.1/C.c_kms) print("Before convolve", log_spec.get_min_v(), "km/s") log_spec2 = log_spec.copy() log_spec.instrument_and_stellar_convolve(instrument, 20) print("After convolve", log_spec.get_min_v(), "km/s") log_spec2.instrument_and_stellar_convolve(instrument_fine, 20) interp = InterpolatedUnivariateSpline(log_spec.wl, log_spec.fl, k=5) fl = interp(log_spec2.wl) assert np.allclose(fl, log_spec2.fl), "Spectral information not preserved."
def main(): from StellarSpectra.spectrum import DataSpectrum from StellarSpectra.grid_tools import TRES myDataSpectrum = DataSpectrum.open( "../../data/WASP14/WASP14-2009-06-14.hdf5", orders=np.array([22])) myInstrument = TRES() myComp = AccuracyComparison(myDataSpectrum, myInstrument, "../../libraries/PHOENIX_submaster.hdf5", "../../libraries/PHOENIX_objgrid6000.hdf5", { "temp": 6000, "logg": 4.5, "Z": -0.5 }, { "temp": 10, "logg": 0.05, "Z": 0.05 }) myComp.plot_quality()
import numpy as np from StellarSpectra.model import Model from StellarSpectra.spectrum import DataSpectrum from StellarSpectra.grid_tools import TRES, HDF5Interface from StellarSpectra import utils myDataSpectrum = DataSpectrum.open("../../data/WASP14/WASP14-2009-06-14.hdf5", orders=np.array([21, 22, 23])) myInstrument = TRES() myHDF5Interface = HDF5Interface("../../libraries/PHOENIX_TRES_F.hdf5") #Load a model using the JSON file myModel = Model.from_json("WASP14_PHOENIX_model0_final.json", myDataSpectrum, myInstrument, myHDF5Interface) myOrderModel = myModel.OrderModels[1] model_flux = myOrderModel.get_spectrum() spec = myModel.get_data() wl = spec.wls[1] fl = spec.fls[1] model_fl = myOrderModel.get_spectrum() residuals = fl - model_fl mask = spec.masks[1] cov = myModel.OrderModels[1].get_Cov().todense() np.save("PHOENIX_covariance_matrix.npy", cov)
def main(): #Use argparse to determine if we've specified a config file import argparse parser = argparse.ArgumentParser( prog="flot_model.py", description="Plot the model and residuals using flot.") parser.add_argument("json", help="*.json file describing the model.") parser.add_argument("params", help="*.yaml file specifying run parameters.") # parser.add_argument("-o", "--output", help="*.html file for output") args = parser.parse_args() import json import yaml if args.json: # #assert that we actually specified a *.json file if ".json" not in args.json: import sys sys.exit("Must specify a *.json file.") if args.params: # #assert that we actually specified a *.yaml file if ".yaml" in args.params: yaml_file = args.params f = open(args.params) config = yaml.load(f) f.close() else: import sys sys.exit("Must specify a *.yaml file.") yaml_file = args.params from StellarSpectra.model import Model from StellarSpectra.spectrum import DataSpectrum from StellarSpectra.grid_tools import TRES, HDF5Interface #Figure out what the relative path is to base import StellarSpectra base = StellarSpectra.__file__[:-26] myDataSpectrum = DataSpectrum.open(base + config['data'], orders=config['orders']) myInstrument = TRES() myHDF5Interface = HDF5Interface(base + config['HDF5_path']) myModel = Model.from_json(args.json, myDataSpectrum, myInstrument, myHDF5Interface) for model in myModel.OrderModels: #If an order has regions, read these out from model_final.json region_dict = model.get_regions_dict() print("Region dict", region_dict) #loop through these to determine the wavelength of each wl_regions = [value["mu"] for value in region_dict.values()] #Make vertical markings at the location of the wl_regions. #Get the data, sigmas, and mask wl, fl, sigma, mask = model.get_data() #Get the model flux flm = model.get_spectrum() #Get chebyshev cheb = model.get_Cheb() name = "Order {}".format(model.order) plot_data = order_json(wl, fl, sigma, mask, flm, cheb) plot_data.update({"wl_regions": wl_regions}) print(plot_data['wl_regions']) render_template(base, plot_data)
def main(): #Use argparse to determine if we've specified a config file import argparse parser = argparse.ArgumentParser( prog="plotly_model.py", description="Plot the model and residuals using plot.ly") parser.add_argument("json", help="*.json file describing the model.") parser.add_argument("params", help="*.yaml file specifying run parameters.") # parser.add_argument("-o", "--output", help="*.html file for output") args = parser.parse_args() import json import yaml if args.json: # #assert that we actually specified a *.json file if ".json" not in args.json: import sys sys.exit("Must specify a *.json file.") if args.params: # #assert that we actually specified a *.yaml file if ".yaml" in args.params: yaml_file = args.params f = open(args.params) config = yaml.load(f) f.close() else: import sys sys.exit("Must specify a *.yaml file.") yaml_file = args.params from StellarSpectra.model import Model from StellarSpectra.spectrum import DataSpectrum from StellarSpectra.grid_tools import TRES, HDF5Interface #Figure out what the relative path is to base import StellarSpectra base = StellarSpectra.__file__[:-26] myDataSpectrum = DataSpectrum.open(base + config['data'], orders=config['orders']) myInstrument = TRES() myHDF5Interface = HDF5Interface(base + config['HDF5_path']) myModel = Model.from_json(args.json, myDataSpectrum, myInstrument, myHDF5Interface) for model in myModel.OrderModels: #Get the data wl, fl = model.get_data() #Get the model flux flm = model.get_spectrum() #Get residuals residuals = model.get_residuals() name = "Order {}".format(model.order) url = plotly_order(name, wl, fl, flm, residuals) print(url)
"/n/holyscratch/panstarrs/iczekala/master_grids/PHOENIX_master.hdf5") myInterpolator = Interpolator(myHDF5Interface, avg_hdr_keys=[ "air", "PHXLUM", "PHXMXLEN", "PHXLOGG", "PHXDUST", "PHXM_H", "PHXREFF", "PHXXI_L", "PHXXI_M", "PHXXI_N", "PHXALPHA", "PHXMASS", "norm", "PHXVER", "PHXTEFF" ]) outKPNO = "/n/home07/iczekala/StellarSpectra/libraries/willie/KPNO/" outKPNOfnu = "/n/home07/iczekala/StellarSpectra/libraries/willie/KPNOfnu/" outTRES = "/n/home07/iczekala/StellarSpectra/libraries/willie/TRES/" outTRESfnu = "/n/home07/iczekala/StellarSpectra/libraries/willie/TRESfnu/" params_hot = {"temp": 6000, "logg": 4.5, "Z": 0.0, "vsini": 8} params_cool = {"temp": 4000, "logg": 4.5, "Z": 0.0, "vsini": 4} KPNOcreator = MasterToFITSIndividual(interpolator=myInterpolator, instrument=KPNO()) KPNOcreator.process_spectrum(params_hot, out_unit="f_nu_log", out_dir=outKPNO) KPNOcreator.process_spectrum(params_cool, out_unit="f_nu_log", out_dir=outKPNO) KPNOcreator.process_spectrum(params_hot, out_unit="f_nu", out_dir=outKPNOfnu) KPNOcreator.process_spectrum(params_cool, out_unit="f_nu", out_dir=outKPNOfnu) TREScreator = MasterToFITSIndividual(interpolator=myInterpolator, instrument=TRES()) TREScreator.process_spectrum(params_hot, out_unit="f_nu_log", out_dir=outTRES) TREScreator.process_spectrum(params_cool, out_unit="f_nu_log", out_dir=outTRES) TREScreator.process_spectrum(params_hot, out_unit="f_nu", out_dir=outTRESfnu) TREScreator.process_spectrum(params_cool, out_unit="f_nu", out_dir=outTRESfnu)
def test_to_LogLambda(self): from StellarSpectra.grid_tools import TRES spec = self.spec.to_LogLambda(instrument=TRES(), min_vc=0.06 / C.c_kms) print(spec.get_min_v(), "km/s")