Example #1
0
    def test_logging_config(self, atomic_data_fname, caplog, log_state,
                            specific):
        config = Configuration.from_yaml(
            "tardis/io/tests/data/tardis_configv1_verysimple_logger.yml")
        config["atom_data"] = atomic_data_fname

        caplog.clear()
        run_tardis(config=config, log_state=log_state, specific=specific)
        for record in caplog.records:
            if specific == True:
                assert record.levelno == LOGGING_LEVELS[log_state.upper()]
            else:
                assert record.levelno >= LOGGING_LEVELS[log_state.upper()]
        def perform_run(yml):
            spawn_dir = os.path.dirname(yml) + '/'
            file_prefix = yml.split('/')[-1].split('.yml')[0]            
            outfile = spawn_dir + file_prefix
            
            simulation = tardis.run_tardis(yml)  

            if self.show_figs:
                interface.show(simulation)

            if self.make_kromer:
                kromer_output = spawn_dir + file_prefix +'_kromer.png'
                self.make_kromer_plot(simulation, kromer_output)

            D, w, f = self.analyse_and_add_quantities(simulation) 
            
            #Save simulation as hdf.
            simulation.to_hdf(outfile + '.hdf')
            
            #Create .pkl containg the spectrum and derived qquantities.
            with open(outfile + '.pkl', 'w') as out_pkl:
                cPickle.dump(D, out_pkl, protocol=cPickle.HIGHEST_PROTOCOL)            
            
            #Create .dat file containg spectra only for uploading into WISEREP.
            with open(outfile + '.dat'  ,'w') as out_spec:
                for x, y in zip(w[:-1], f[:-1]):
                    out_spec.write(str(x.value) + '    ' + str(y.value) + '\n')
                out_spec.write(str(w[-1].value) + '    ' + str(f[-1].value))

            #Delete the simulation to make sure the memory is being freed.
            del simulation
Example #3
0
    def test_logging_both_specified(self, atomic_data_fname, caplog, log_level,
                                    specific_log_level):
        config = Configuration.from_yaml(
            "tardis/io/tests/data/tardis_configv1_verysimple_logger.yml")
        config["atom_data"] = atomic_data_fname
        config["debug"]["log_level"] = log_level
        config["debug"]["specific_log_level"] = specific_log_level

        caplog.clear()
        run_tardis(
            config=config,
            log_level=log_level,
            specific_log_level=specific_log_level,
        )
        for record in caplog.records:
            if specific_log_level == True:
                assert record.levelno == LOGGING_LEVELS[log_level.upper()]
            else:
                assert record.levelno >= LOGGING_LEVELS[log_level.upper()]
Example #4
0
def run(filename, runid, nepoch):
    mdl = run_tardis(filename)
    complete_file = open('completed_run_%05d_%d.txt' % (runid, nepoch), 'w+')
    #print "completed run file created"
    complete_file.close()
    mdl.runner.spectrum.to_ascii("spec_%05d_%d.dat" % (runid, nepoch))
    #print "save spectra"
    mdl.runner.spectrum_virtual.to_ascii("virtual_spec_%05d_%d.dat" % (runid, nepoch))
    mdl.runner.to_hdf("model_%05d_%d.h5" % (runid, nepoch))
    mdl.plasma.atomic_data.lines.to_hdf("lines_%05d_%d.h5" % (runid, nepoch), "lines")
    mdl.plasma.ion_number_density.to_hdf("ionization_%05d_%d.h5" % (runid, nepoch), "ion_number_density")
Example #5
0
    def setup(self):
        self.atom_data_filename = os.path.expanduser(
            os.path.expandvars(pytest.config.getvalue('atomic-dataset')))
        assert os.path.exists(
            self.atom_data_filename), ("{0} atomic datafiles "
                                       "does not seem to "
                                       "exist".format(self.atom_data_filename))
        self.config_yaml = yaml.load(
            open('tardis/io/tests/data/tardis_configv1_verysimple.yml'))
        self.config_yaml['atom_data'] = self.atom_data_filename

        self.model = run_tardis(self.config_yaml)
Example #6
0
def test_run_tardis_from_config_obj(atomic_data_fname):
    """
    Tests whether the run_tardis function can take in the Configuration object
    as arguments
    """
    config = Configuration.from_yaml(
        "tardis/io/tests/data/tardis_configv1_verysimple.yml")
    config["atom_data"] = atomic_data_fname

    try:
        sim = run_tardis(config)
    except Exception as e:
        pytest.fail(str(e.args[0]))
Example #7
0
    def run_sim_from_grid(self, row_index, **tardiskwargs):
        """
        Runs a full TARDIS simulation using the base self.config
        modified by the user specified row_index.

        Parameters
        ----------
        row_index : int
            Row index in grid.

        Returns
        -------
        sim : tardis.simulation.base.Simulation
            Completed TARDIS simulation object.
        """
        tardis_config = self.grid_row_to_config(row_index)
        sim = tardis.run_tardis(tardis_config, **tardiskwargs)
        return sim
Example #8
0
def model(config_path):
    return run_tardis(config_path)
Example #9
0
from tardis import run_tardis
import numpy as np
from tardis.montecarlo.montecarlo_numba.base import montecarlo_main_loop
import os
import numba
import sys
import yaml

SEED = eval(sys.argv[1].split("=")[1])[0]

yaml_file, params = "tardis_example_single.yml", None

with open(yaml_file) as f:
    params = yaml.safe_load(f)

params["montecarlo"]["single_packet_seed"] = SEED

with open(yaml_file, "w") as f:
    yaml.safe_dump(params, f)

mdl = run_tardis(yaml_file)
Example #10
0
        app = QtGui.QApplication([])
    else:
        app = get_app_qt4()

    tablemodel = SimpleTableModel
    win = Tardis(tablemodel)
    win.show_model(model)

    if importFailed:
        app.exec_()
    else:
        start_event_loop_qt4(app)

        #If the IPython console is being used, this will evaluate to true.
        #In that case the window created will be garbage collected unless a
        #reference to it is maintained after this function exits. So the win is
        #returned.
        if is_event_loop_running_qt4(app):
            return win


if __name__ == '__main__':
    """When this module is executed as script, take arguments, calculate model
    and call the show function.

    """
    yamlfile = sys.argv[1]
    atomfile = sys.argv[2]
    mdl = run_tardis(yamlfile, atomfile)
    show(mdl)
Example #11
0
    if importFailed:
        app = QtGui.QApplication([])
    else:
        app = get_app_qt4()

    tablemodel = SimpleTableModel
    win = Tardis(tablemodel)
    win.show_model(model)

    if importFailed:
        app.exec_()
    else:
        start_event_loop_qt4(app)

        #If the IPython console is being used, this will evaluate to true.
        #In that case the window created will be garbage collected unless a 
        #reference to it is maintained after this function exits. So the win is
        #returned.
        if is_event_loop_running_qt4(app):
            return win

if __name__=='__main__':
    """When this module is executed as script, take arguments, calculate model
    and call the show function.

    """
    yamlfile = sys.argv[1]
    atomfile = sys.argv[2]
    mdl = run_tardis(yamlfile, atomfile)
    show(mdl) 
import scipy.interpolate as intr
import matplotlib.pyplot as pl
import astropy.constants as co
import astropy.units as un
import pandas as pd
import numpy as np

import tardis

def ratiocompare():
    pl.plot(lam,in_L_lam/mc_L_lam)
    pl.xlabel(u"A")
    pl.title("Ratio")
    pl.show()

tar = tardis.run_tardis("simple_example.yml")

freq = tar.runner.spectrum.frequency
lam  = tar.runner.spectrum_virtual.wavelength
mc_L_nu = tar.runner.spectrum_virtual.luminosity_density_nu
mc_L_lam = tar.runner.spectrum_virtual.luminosity_density_lambda

in_L_nu = tar.runner.L_nu
in_L_lam = co.c.to("Angstrom/s")/lam**2 * in_L_nu
BB = tardis.util.intensity_black_body(tar.runner.spectrum_virtual.frequency,6416)
Fnu = BB*np.pi
Lbb_nu = 4*np.pi*tar.runner.r_inner_cgs.min()**2 * Fnu
Lbb_lam = Lbb_nu * co.c.to("Angstrom/s")/lam**2 


if True:
Example #13
0
 def set_saved(self):
     from tardis.gui import interface
     mdl = run_tardis(
         '/home/nilesh/Desktop/MY FILES/tardis_examples/tardis_example.yml')
     interface.show(mdl)
Example #14
0
	def show():
		mdl = run_tardis(self.cfg)
		interface.show(mdl)
Example #15
0
def run_sim(fn, drs='SimFiles/'):
    thvel = fn.split('_')[-1][:-4]
    sim = run_tardis(drs + fn)
    ms.dump_to_hdf(
        sim, '/afs/mpa/data/csogeza/SimResults/sim_vth_' + thvel + '.hdf')