示例#1
0
def testcase1():
    c_light = speed_of_light * 1e-3

    # TODO get better test case for this
    cwd = dirname(__file__)
    fname = join(cwd, "testcase1.inp")
    sme = SME_Struct.load(fname)
    sme = synthesize_spectrum(sme)

    # Add a second segment (just for testing)
    sme.spec = [sme.spec[0], sme.spec[0]]
    sme.wave = [sme.wave[0], sme.wave[0]]
    sme.synth = [sme.synth[0], sme.synth[0]]
    sme.mask = [sme.mask[0], sme.mask[0]]

    sme.wran = [sme.wran[0], sme.wran[0]]

    rv = 10
    x_syn = sme.wave[0] * (1 - rv / c_light)
    y_syn = sme.synth[0]

    x_syn = np.array([x_syn, x_syn])
    y_syn = np.array([y_syn, y_syn])

    return sme, x_syn, y_syn, rv
示例#2
0
def test_run_with_nlte():
    # NOTE sme structure must have long format for NLTE
    sme = make_minimum_structure()
    sme.nlte.set_nlte("Ca", "marcs2012p_t1.0_Ca.grd")

    sme2 = synthesize_spectrum(sme)

    assert isinstance(sme2.nlte.flags, np.ndarray)
    assert np.issubdtype(sme2.nlte.flags.dtype, np.dtype("bool"))
    assert len(sme2.nlte.flags) == len(sme2.linelist)
    assert np.any(sme2.nlte.flags)
示例#3
0
def test_synthesis_segment(sme_2segments):
    sme = sme_2segments
    # Out of range
    with pytest.raises(IndexError):
        synthesize_spectrum(sme, segments=[3])

    with pytest.raises(IndexError):
        synthesize_spectrum(sme, segments=[-1])

    sme2 = synthesize_spectrum(sme, segments=[0])
    assert len(sme2.synth[0]) != 0
    assert len(sme2.synth[1]) == 0

    assert len(sme2.wave[0]) != 0
    assert len(sme2.wave[1]) == 0

    assert sme2.wave.shape[0] == 2
    assert sme2.wave.shape[1][1] == 0

    orig = np.copy(sme2.synth[0])
    sme2 = synthesize_spectrum(sme2, segments=[1])

    assert sme2.wave.shape[1][0] != 0
    assert sme2.wave.shape[1][1] != 0

    assert np.all(sme2.synth[0] == orig)
示例#4
0
def test_synthesis_simple(sme_2segments):
    sme = sme_2segments
    sme2 = synthesize_spectrum(sme)

    # Check if a result is there it has the expected data type
    assert sme2.synth is not None
    assert isinstance(sme2.synth, Iliffe_vector)
    assert np.all(sme2.synth.ravel() != 0)

    assert sme.wave is not None
    assert isinstance(sme2.wave, Iliffe_vector)
    assert np.issubdtype(sme2.wave.dtype, np.floating)
    assert np.all(sme2.wave.ravel() != 0)

    assert sme.spec is None
示例#5
0
def create_sme_structure(teff=5770, logg=4.4):
    examples_dir = os.path.dirname(os.path.realpath(__file__))
    in_file = os.path.join(examples_dir, "sun_6440_grid.inp")
    # Load your existing SME structure or create your own
    sme = SME.SME_Structure.load(in_file)
    sme.abund = Abund(0.05, "asplund2009")
    sme.linelist = ValdFile(os.path.join(examples_dir, "sun.lin"))
    # Change parameters if your want
    sme.vrad_flag = "none"
    sme.cscale_flag = "none"
    sme.cscale_type = "mask"
    sme.vsini = 0
    sme.vrad = 0
    # Set input parameters
    sme.teff = teff
    sme.logg = logg
    # Start SME solver
    sme = synthesize_spectrum(sme)
    return sme
示例#6
0
文件: parallel.py 项目: AWehrhahn/SME
    # 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

    # Start SME solver
    sme = synthesize_spectrum(sme)

    # Save results
    makedirs(dirname(out_file), exist_ok=True)
    sme.save(out_file)

    # Plot results
    makedirs(dirname(plot_file), exist_ok=True)
    fig = plot_plotly.FinalPlot(sme)
    fig.save(filename=plot_file)
示例#7
0
    fitparameters = ["teff", "logg", "monh", "vmic"]

    # Restrict the linelist to relevant lines
    # for this segment
    s = 18
    wmin, wmax = sme.wran[s]
    sme.linelist = sme.linelist.trim(wmin, wmax, rvel=100)

    # Set radial velocity and continuum settings
    cscale = {}
    x = sme.wave[s] - sme.wave[s][0]

    sme.vrad_flag = "each"
    sme.cscale_type = "match"
    sme.cscale_flag = "cubic"
    sme = synthesize_spectrum(sme, segments=[s])
    cscale["match+cubic"] = np.polyval(sme.cscale[s], x)

    sme.vrad_flag = "each"
    sme.cscale_type = "spline"
    sme.cscale_flag = 3
    sme.cscale = None
    sme.vrad = None
    sme = synthesize_spectrum(sme, segments=[s])
    cscale["spline+3"] = np.copy(sme.cscale[s])

    sme.vrad_flag = "each"
    sme.cscale_flag = "none"
    sme = synthesize_spectrum(sme, segments=[s])

    plot_file = join(dirname(__file__), "images/cont_55cnc.png")
示例#8
0
    # Run SME
    sme = SME.SME_Structure.load(in_file)
    orig = sme.synth.copy()
    sme.cscale_flag = "linear"
    sme.cscale_type = "match+mask"
    sme.cscale[0] = [0, 1]

    rvel = 100
    wmin, wmax = sme.wran[0]
    wmin *= 1 - rvel / 3e5
    wmax *= 1 + rvel / 3e5
    sme.linelist = sme.linelist.trim(wmin, wmax)

    sme.specific_intensities_only = True
    wmod, smod, cmod = synthesize_spectrum(sme, segments=[0])

    orig = readsav(in_file)["sme"]
    sint = orig["SINT"][0]
    wint = orig["JINT"][0]
    wind = orig["WIND"][0]

    sint = sint[0, 0:wind[0]]
    wint = wint[0:wind[0]]

    plt.plot(wint, sint)
    plt.plot(wmod[0], smod[0] * cmod[0])
    plt.show()

    # Plot results
    fig = plot_plotly.FinalPlot(sme, orig=orig)
示例#9
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)