Skip to content

Commit

Permalink
return namedtuple with units
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbarnes committed Aug 23, 2024
1 parent 4ccfcac commit e122b75
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions src/ebtelplusplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,60 @@
ebtelplusplus: Zero-dimensional hydrodynamics of coronal loops
"""
import pathlib
import tempfile
from collections import namedtuple

from __future__ import annotations
import astropy.units as u

from ._core import run
from ebtelplusplus.util import write_xml

from ._core import run as _run_cpp

__all__ = ["run"]


_UNITS_MAPPING = {
'time': 's',
'electron_temperature': 'K',
'ion_temperature': 'K',
'density': 'cm-3',
'electron_pressure': 'dyne cm-2',
'ion_pressure': 'dyne cm-2',
'velocity': 'cm s-1',
'heat': 'erg cm-3 s-1',
'dem_temperature': 'K',
'dem_tr': 'cm-5 K-1',
'dem_corona': 'cm-5 K-1',
'electron_thermal_conduction': 'erg cm-2 s-1',
'ion_thermal_conduction': 'erg cm-2 s-1',
'radiative_loss': 'erg cm-3 s-1',
'tr_corona_radiative_loss_ratio': '',
}

EbtelResult = namedtuple('EbtelResult',
_UNITS_MAPPING.keys(),
defaults=[None,]*len(_UNITS_MAPPING))


def run(config):
"""
Run an ebtel++ simulation
Parameters
----------
config: `dict`
Dictionary of configuration options
Returns
-------
results: `dict`
Dictionary of ebtel results
"""
# TODO: refactor to accept inputs directly and avoid roundtripping config to disk
with tempfile.TemporaryDirectory() as tmpdir:
config_filename = pathlib.Path(tmpdir) / 'ebtelplusplus.tmp.xml'
write_xml(config, config_filename)
results = _run_cpp(str(config_filename))

return EbtelResult(**{k: u.Quantity(v, _UNITS_MAPPING[k]) for k,v in results.items()})

0 comments on commit e122b75

Please sign in to comment.