diff --git a/examples/paper/55_Cnc_mask.py b/examples/paper/55_Cnc_mask.py index b6f90fac..c63e2adf 100644 --- a/examples/paper/55_Cnc_mask.py +++ b/examples/paper/55_Cnc_mask.py @@ -715,7 +715,7 @@ def get_mask_from_neural_network(sme): # Set radial velocity and continuum settings # Set RV and Continuum flags - sme.vrad_flag = "each" + sme.vrad_flag = "fix" sme.cscale_flag = 3 sme.cscale_type = "match+mask" @@ -755,5 +755,7 @@ def get_mask_from_neural_network(sme): sme.save(out_file) # Plot results + sme.synth *= sme.telluric fig = plot_plotly.FinalPlot(sme) fig.save(filename=plot_file) + print(f"Finished: {target}") diff --git a/examples/paper/HD_22049.py b/examples/paper/HD_22049.py index 52a84be0..447b8abc 100644 --- a/examples/paper/HD_22049.py +++ b/examples/paper/HD_22049.py @@ -649,12 +649,12 @@ def get_mask_from_neural_network(sme): # raise ValueError("No data file found") # in_file = os.path.join(data_dir, fname) - in_file = os.path.join(examples_dir, f"results/{target}_mask.sme") + in_file = os.path.join(examples_dir, f"results/{target}_mask_new.sme") vald_file = os.path.join(examples_dir, f"data/hd22049.lin") - out_file = os.path.join(examples_dir, f"results/{target}_mask_out.sme") - plot_file = os.path.join(examples_dir, f"results/{target}_mask_out.html") + out_file = os.path.join(examples_dir, f"results/{target}_mask_new_out.sme") + plot_file = os.path.join(examples_dir, f"results/{target}_mask_new_out.html") date_string = datetime.datetime.now().isoformat().replace(":", ".") log_file = os.path.join(examples_dir, f"results/{target}_{date_string}.log") @@ -781,7 +781,7 @@ def get_mask_from_neural_network(sme): # Set radial velocity and continuum settings # Set RV and Continuum flags - sme.vrad_flag = "each" + sme.vrad_flag = "fix" sme.cscale_flag = 2 sme.cscale_type = "match+mask" @@ -808,12 +808,11 @@ def get_mask_from_neural_network(sme): # sme.linelist = sme.linelist.trim(wmin, wmax) # Start SME solver - # sme = synthesize_spectrum(sme, segments=[6]) + # sme = synthesize_spectrum(sme, segments=np.arange(6, 31)) # sme.cscale_flag = "fix" # sme.save(out_file) - - sme = solve(sme, fitparameters, segments=np.arange(2, 31)) + sme = solve(sme, fitparameters, segments=np.arange(6, 31)) print(sme.citation()) @@ -821,6 +820,7 @@ def get_mask_from_neural_network(sme): sme.save(out_file) # Plot results + sme.synth *= sme.telluric fig = plot_plotly.FinalPlot(sme) fig.save(filename=plot_file) print(f"Finished: {target}") diff --git a/examples/paper/L_98-59.py b/examples/paper/L_98-59.py index 19fee602..4d0e067a 100644 --- a/examples/paper/L_98-59.py +++ b/examples/paper/L_98-59.py @@ -811,5 +811,6 @@ def get_mask_from_neural_network(sme): sme.save(out_file) # Plot results + sme.synth *= sme.telluric fig = plot_plotly.FinalPlot(sme) fig.save(filename=plot_file) diff --git a/examples/paper/L_98-59_mask.py b/examples/paper/L_98-59_mask.py index 4abec193..87e8d9c9 100644 --- a/examples/paper/L_98-59_mask.py +++ b/examples/paper/L_98-59_mask.py @@ -626,7 +626,9 @@ def get_mask_from_neural_network(sme): # Define the location of all your files # this will put everything into the example dir target = "L_98-59" - star = StellarDB().load(target) + sdb = StellarDB() + # sdb.auto_fill(target) + star = sdb.load(target) alias = [re.sub(r"[-_ ]", "", s).lower() for s in star["id"]] examples_dir = dirname(realpath(__file__)) @@ -666,7 +668,7 @@ def get_mask_from_neural_network(sme): # Get first guess from literature values sme.teff = star["t_eff"].to_value("K") if "t_eff" in star else 6000 - sme.logg = star["logg"].to_value(1) if "logg" in star else 4 + sme.logg = star["logg"].to_value(1) if "logg" in star else 4.9 monh = star["metallicity"].to_value(1) if "metallicity" in star else 0 sme.abund = Abund(monh, "asplund2009") sme.vmic = ( @@ -754,5 +756,7 @@ def get_mask_from_neural_network(sme): sme.save(out_file) # Plot results + sme.synth *= sme.telluric fig = plot_plotly.FinalPlot(sme) fig.save(filename=plot_file) + print(f"Finished: {target}") diff --git a/examples/paper/L_98-59_predict.py b/examples/paper/L_98-59_predict.py new file mode 100644 index 00000000..7dd51db5 --- /dev/null +++ b/examples/paper/L_98-59_predict.py @@ -0,0 +1,95 @@ +""" Minimum working example of an SME script +""" +import os +import os.path +import re +from os.path import dirname, join, realpath +import datetime + +import matplotlib.pyplot as plt +import numpy as np +from astropy import constants as const +from astropy import coordinates as coord +from astropy.io import fits +from astropy.time import Time +from data_sources.StellarDB import StellarDB +from pysme import sme as SME +from pysme import util +from pysme.abund import Abund +from pysme.gui import plot_plotly +from pysme.iliffe_vector import Iliffe_vector +from pysme.linelist.vald import ValdFile +from pysme.persistence import save_as_idl +from pysme.solve import solve +from pysme.synthesize import synthesize_spectrum +from scipy.linalg import lstsq, solve_banded +from scipy.ndimage.filters import gaussian_filter1d, median_filter +from scipy.optimize import least_squares +from tqdm import tqdm + +if __name__ == "__main__": + # Define the location of all your files + # this will put everything into the example dir + target = "L_98-59" + sdb = StellarDB() + # sdb.auto_fill(target) + star = sdb.load(target) + alias = [re.sub(r"[-_ ]", "", s).lower() for s in star["id"]] + + examples_dir = dirname(realpath(__file__)) + data_dir = join(examples_dir, "data") + + # Find the correct data file for this target + # fname = "ADP.2019-01-30T01:13:58.172.fits" + fname = "L_98-59_mask_out.sme" + in_file = os.path.join(examples_dir, "results", fname) + # in_file = os.path.join(examples_dir, f"results/{target}_mask.sme") + + vald_file = os.path.join(examples_dir, f"data/hd22049.lin") + + out_file = os.path.join(examples_dir, f"results/{target}_mask_out.sme") + plot_file = os.path.join(examples_dir, f"results/{target}.html") + date_string = datetime.datetime.now().isoformat().replace(":", ".") + log_file = os.path.join(examples_dir, f"results/{target}_{date_string}.log") + + # Start the logging to the file + util.start_logging(log_file) + + # err = hdu[1].data["ERR"] + sme = SME.SME_Structure.load(in_file) + + # Set radial velocity and continuum settings + # Set RV and Continuum flags + sme.vrad_flag = "fix" + sme.cscale_flag = "none" + sme.cscale_type = "match" + sme.vrad = -14 + + # Reset observations + sme.wave = None + sme.spec = None + sme.synth = None + sme.telluric = None + # Set new Wavelength ranges of CRIRES+ + # This is for setting L3426 + sme.wran = [ + [2885, 2935], + [3037, 3090], + [3206, 3261], + [3394, 3453], + [3607, 3669], + [3847, 3914], + [4122, 4193], + ] + + # Perfrom the calculation + sme = synthesize_spectrum(sme) + print(sme.citation()) + + # Save results + sme.save(out_file) + + # Plot results + fig = plot_plotly.FinalPlot(sme) + fig.save(filename=plot_file) + print(f"Finished: {target}")