Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As simpler run_tardis #205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/physics/physical_quantities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inspect the model properties.


Runing in interactive Python session
------------------------------
------------------------------------

With iPython installed launch a session using

Expand All @@ -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
Expand Down
30 changes: 19 additions & 11 deletions docs/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<https://www.dropbox.com/s/svvyr5i7m8ouzdt/tardis_example.tar.gz>`_
and run TARDIS with:
Expand All @@ -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.

7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tardis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ._astropy_init import *
# ----------------------------------------------------------------------------

from tardis.base import run_tardis

logger = logging.getLogger('tardis')
logger.setLevel(logging.INFO)
Expand Down
46 changes: 46 additions & 0 deletions tardis/base.py
Original file line number Diff line number Diff line change
@@ -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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mklauser You were interested in duck-typing. This is a classic example. You could do a type check to see if is as string, but one simply opts to give it to the python open command and then sees if it works. This means also unicode strings can work, or other things that open can read.

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
31 changes: 0 additions & 31 deletions tardis/core.py

This file was deleted.

2 changes: 1 addition & 1 deletion tardis/io/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tardis/tests/test_tardis_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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):
Expand Down