def main(fname_in, fname_out, log_file=None):
    if log_file is not None:
        start_logging(log_file)

    if fname_in.endswith(".sav"):
        fileformat = SavFile
    elif fname_in.endswith(".krz"):
        fileformat = KrzFile
    else:
        raise ValueError(
            f"File format {fname_in} not recognised. Expected one of ['.sav', '.krz']"
        )

    data = fileformat(fname_in)

    result = {
        "info": {
            "format": linelist.lineformat,
            "medium": linelist.medium,
            "citation_info": linelist.citation_info,
        },
        "data": data,
    }

    with open(fname_out, "w") as f:
        json.dump(result, f)

    return result
示例#2
0
def main(fname_in, fname_out, linelist_format="VALD", log_file=None):
    if log_file is not None:
        start_logging(log_file)

    if linelist_format.lower() == "vald":
        linelist = ValdFile(fname_in)
    else:
        raise ValueError(
            f"Unrecognised linelist format f{linelist_format}. Expected one of ['VALD']"
        )

    data = linelist._lines.to_dict(orient="records")

    result = {
        "info": {
            "format": linelist.lineformat,
            "medium": linelist.medium,
            "citation_info": linelist.citation_info,
        },
        "data": data,
    }

    with open(fname_out, "w") as f:
        json.dump(result, f)

    return result
示例#3
0
文件: parallel.py 项目: AWehrhahn/SME
        )
        raise RuntimeError

    # Define the location of all your files
    # here we use different directories for the different
    # products
    target = f"sun_{teff}_{logg}_{monh}"
    examples_dir = dirname(realpath(__file__))
    in_file = join(examples_dir, "sun_6440_grid.inp")
    out_file = join(examples_dir, f"out/{target}.sme")
    plot_file = join(examples_dir, f"plot/{target}.html")
    log_file = join(examples_dir, f"log/{target}.log")

    # Start the logging to the file
    makedirs(dirname(log_file), exist_ok=True)
    util.start_logging(log_file)

    # Load your existing SME structure or create your own
    sme = SME.SME_Structure.load(in_file)

    # Change parameters if your want
    sme.vrad = 0.35
    sme.vrad_flag = "whole"
    sme.cscale_flag = "linear"
    sme.cscale_type = "match"

    # Apply the parameters set via the command line
    sme.teff = teff
    sme.logg = logg
    sme.monh = monh
示例#4
0
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm

from pysme import sme as SME
from pysme import util
from pysme.abund import Abund
from pysme.continuum_and_radial_velocity import match_rv_continuum
from pysme.gui import plot_plotly, plot_pyplot
from pysme.linelist.vald import ValdFile
from pysme.solve import SME_Solver
from pysme.synthesize import synthesize_spectrum

if __name__ == "__main__":
    target = "k2-3_2"
    util.start_logging(f"{target}.log")

    # Get input files
    if len(sys.argv) > 1:
        in_file, vald_file, fitparameters = util.parse_args()
    else:
        examples_dir = "/DATA/ESO/HARPS/K2-3/"
        in_file = os.path.join(examples_dir, "K2-3_red_c.ech")
        vald_file = os.path.expanduser("~/Documents/IDL/SME/harps_red.lin")
        atmo_file = "marcs2012p_t1.0.sav"
        fitparameters = []

    # Load files
    sme = SME.SME_Structure.load(in_file)

    if vald_file is not None:
示例#5
0
def main(fname_in, fname_out, fit_parameters, log_file=None):
    if log_file is not None:
        start_logging(log_file)
    sme = SME_Structure.load(fname_in)
    sme = solve(sme, fit_parameters)
    sme.save(fname_out)
示例#6
0
        with open(filename + "_", "wb") as f:
            pickle.dump(self.scaler, f)

    def load(self, filename):
        self.model = load_model(filename)
        with open(filename + "_", "rb") as f:
            self.scaler = pickle.load(f)


if __name__ == "__main__":
    max_degree = 5
    # int: samples per parameter setting
    n_samples = 5000
    # n_features = 1000
    noise = 0.05
    util.start_logging("neural_network.log")

    # TODO: Need to figure out how to handle different input sizes
    # interpolate, to a reasonable resolution
    # then run the thing for segments of size x

    start = time.time()
    # X, Y = None, None
    # for teff in [5500, 6000, 6500]:
    #     for logg in [4, 4.2, 4.4, 4.6]:
    #         for noise in [0.01, 0.05, 0.1]:
    #             sme = create_sme_structure(teff, logg)
    #             X2, Y2 = create_training_data(
    #                 sme, n_samples, max_degree=max_degree, noise=noise
    #             )
    #             X = np.concatenate((X, X2)) if X is not None else X2
示例#7
0
from pysme.solve import solve
from pysme.synthesize import synthesize_spectrum
from pysme.util import start_logging

if __name__ == "__main__":
    wave, spec = load_solar_spectrum(ravel=False)
    spec = np.clip(spec, 0, 1)

    # Only use from 6022 Å to 7712 Å
    select = slice(500, 700)
    wave = wave[select]
    spec = spec[select]

    log_file = join(dirname(__file__), "logs/sun.log")
    save_file = join(dirname(__file__), "results/sun_compare.sme")
    start_logging(log_file)

    sme = SME_Structure()
    sme.wave = wave
    sme.spec = spec
    sme.uncs = np.sqrt(spec)

    sme.teff = 5500
    sme.logg = 5.0
    sme.abund = Abund(0.2, "asplund2009")
    sme.vmic = 1
    sme.vmac = 3
    sme.vsini = 1.6

    vald_file = join(dirname(__file__), "data/sun_full.lin")
    sme.linelist = ValdFile(vald_file)
示例#8
0
def main(fname_in, fname_out, log_file=None):
    if log_file is not None:
        start_logging(log_file)
    sme = SME_Structure.load(fname_in)
    sme = synthesize_spectrum(sme)
    sme.save(fname_out)