Skip to content

Commit

Permalink
scripts for paper
Browse files Browse the repository at this point in the history
  • Loading branch information
AWehrhahn committed May 21, 2021
1 parent 36b95c8 commit c26fb28
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 10 deletions.
4 changes: 3 additions & 1 deletion examples/paper/55_Cnc_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}")
14 changes: 7 additions & 7 deletions examples/paper/HD_22049.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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"

Expand All @@ -808,19 +808,19 @@ 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())

# Save results
sme.save(out_file)

# Plot results
sme.synth *= sme.telluric
fig = plot_plotly.FinalPlot(sme)
fig.save(filename=plot_file)
print(f"Finished: {target}")
1 change: 1 addition & 0 deletions examples/paper/L_98-59.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 6 additions & 2 deletions examples/paper/L_98-59_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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}")
95 changes: 95 additions & 0 deletions examples/paper/L_98-59_predict.py
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit c26fb28

Please sign in to comment.