diff --git a/docs/physics/physical_quantities.rst b/docs/physics/physical_quantities.rst index bd0c20bd0a7..cf932426d2f 100644 --- a/docs/physics/physical_quantities.rst +++ b/docs/physics/physical_quantities.rst @@ -12,7 +12,7 @@ inspect the model properties. Runing in interactive Python session ------------------------------- +------------------------------------ With iPython installed launch a session using @@ -25,10 +25,9 @@ and then run your calculation, which is based on your "my_config.yml" file .. code-block:: python from tardis import run_tardis - import yaml - configuration_dict = yaml.load(open('myconfig.yml') - model = run_tardis(configuration_dict) + + model = run_tardis('myconfig.yml') If all goes well, the simulation should run as usual. Afterwards, the diff --git a/docs/running.rst b/docs/running.rst index ea7f7563d41..126b5bf92c3 100644 --- a/docs/running.rst +++ b/docs/running.rst @@ -7,8 +7,8 @@ Running TARDIS To run TARDIS requires two files. The atomic database (for more info refer to :ref:`atomic-data`) and a configuration file (more info at :ref:`config-file`). -Simple Example -============== +Running TARDIS in the commandline +================================= After installing TARDIS just download the example directory ``_ and run TARDIS with: @@ -28,25 +28,33 @@ Then plot the output_spectrum.dat with your favourite plotting program. Here's a .. code-block:: python ipython --pylab - tardis_spec = loadtxt('output_spectrum.dat') - plot(tardis_spec[:,0], tardis_spec[:,1]) + >>> tardis_spec = loadtxt('output_spectrum.dat') + >>> plot(tardis_spec[:,0], tardis_spec[:,1]) More atomic datasets can be downloaded from :ref:`atomic-data-download`. -Scripting TARDIS -================ + + +Running TARDIS interactively +============================ + +To get more information from each run of TARDIS one can run it interactively and +have full access to the model properties .. code-block:: python - from tardis import run_tardis - import yaml - configuration_dict = yaml.load(open('myconfig.yml') - model = run_tardis(configuration_dict) + >>> from tardis import run_tardis + >>> model = run_tardis('myconfig.yml') + +This model can then be used for inspecting the run as described +:ref:`physical_quantities` + Graphical User Interface ======================== -A graphical user interface is being developed for this code using QT. We envision to have this available in the next few minor releases. +A graphical user interface is being developed for this code using QT. +We envision to have this available in the next few minor releases. diff --git a/setup.py b/setup.py index 9ae38efe304..6b237bf770b 100755 --- a/setup.py +++ b/setup.py @@ -34,9 +34,10 @@ URL = metadata.get('url', 'http://astropy.org') # Get the long description from the package's docstring -__import__(PACKAGENAME) -package = sys.modules[PACKAGENAME] -LONG_DESCRIPTION = package.__doc__ +#__import__(PACKAGENAME) +#package = sys.modules[PACKAGENAME] +#LONG_DESCRIPTION = package.__doc__ +LONG_DESCRIPTION = "" # Store the package name in a built-in variable so it's easy # to get from other parts of the setup infrastructure diff --git a/tardis/__init__.py b/tardis/__init__.py index 226fb324ae1..0a4e7df6490 100644 --- a/tardis/__init__.py +++ b/tardis/__init__.py @@ -7,6 +7,7 @@ from ._astropy_init import * # ---------------------------------------------------------------------------- +from tardis.base import run_tardis logger = logging.getLogger('tardis') logger.setLevel(logging.INFO) diff --git a/tardis/base.py b/tardis/base.py new file mode 100644 index 00000000000..b938a15a146 --- /dev/null +++ b/tardis/base.py @@ -0,0 +1,46 @@ +#functions that are important for the general usage of TARDIS + +import yaml + +from tardis.io import config_reader +from tardis import model, simulation, atomic + + +def run_tardis(config, atom_data=None): + """ + This function is one of the core functions to run TARDIS from a given + config object. + + It will return a model object containing + + Parameters + ---------- + + config: ~str or ~dict + filename of configuration yaml file or dictionary + + atom_data: ~str or ~tardis.atomic.AtomData + if atom_data is a string it is interpreted as a path to a file storing + the atomic data. Atomic data to use for this TARDIS simulation. If set to None, the + atomic data will be loaded according to keywords set in the configuration + [default=None] + """ + + try: + config_dict = yaml.load(open(config)) + except TypeError: + config_dict = config + + if atom_data is not None: + try: + atom_data = atomic.AtomData.from_hdf5(atom_data) + except TypeError: + atom_data = atom_data + + tardis_config = config_reader.Configuration.from_config_dict( + config_dict, atom_data=atom_data) + radial1d_mdl = model.Radial1DModel(tardis_config) + + simulation.run_radial1d(radial1d_mdl) + + return radial1d_mdl \ No newline at end of file diff --git a/tardis/core.py b/tardis/core.py deleted file mode 100644 index 7de41a443b9..00000000000 --- a/tardis/core.py +++ /dev/null @@ -1,31 +0,0 @@ -#functions that are important for the general usage of TARDIS - -from tardis.io import config_reader -from tardis import model, simulation - - -def run_tardis(configuration_dict, atom_data=None): - """ - This function is one of the core functions to run TARDIS from a given - config object. - - It will return a model object containing - - Parameters - ---------- - - configuration_dict: ~dict - - atom_data: ~tardis.atomic.AtomData - Atomic data to use for this TARDIS simulation. If set to None, the - atomic data will be loaded according to keywords set in the configuration - [default=None] - """ - - tardis_config = config_reader.Configuration.from_config_dict( - configuration_dict, atom_data=atom_data) - radial1d_mdl = model.Radial1DModel(tardis_config) - - simulation.run_radial1d(radial1d_mdl) - - return radial1d_mdl \ No newline at end of file diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index 70c9eaf529f..74167bf08d7 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -772,7 +772,7 @@ class Configuration(ConfigurationNameSpace): @classmethod def from_yaml(cls, fname, test_parser=False): try: - yaml_dict = yaml.load(file(fname)) + yaml_dict = yaml.load(open(fname)) except IOError as e: logger.critical('No config file named: %s', fname) raise e diff --git a/tardis/tests/test_tardis_full.py b/tardis/tests/test_tardis_full.py index 6619bec67aa..1d1ec0a9983 100644 --- a/tardis/tests/test_tardis_full.py +++ b/tardis/tests/test_tardis_full.py @@ -9,6 +9,8 @@ import os +from tardis import run_tardis + def data_path(fname): return os.path.join(tardis.__path__[0], 'tests', 'data', fname) @@ -31,9 +33,7 @@ def setup(self): self.config_yaml = yaml.load(open('tardis/io/tests/data/tardis_configv1_verysimple.yml')) self.config_yaml['atom_data'] = self.atom_data_filename - self.config = Configuration.from_config_dict(self.config_yaml) - self.model = model.Radial1DModel(self.config) - simulation.run_radial1d(self.model) + self.model = run_tardis(self.config_yaml) def test_spectrum(self):