Skip to content

Commit

Permalink
[1.0.8] - 2022-10-6
Browse files Browse the repository at this point in the history
### Added
- forced molecule name in Loader with *molecule* keyword
### Changed
- increased loading performance for Dace data
### Fixed
- ascii conversion for strings in ExoMol data
  • Loading branch information
LorenzoMugnai committed Oct 6, 2022
1 parent 72962a4 commit 4d3d160
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 16 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.0.8] - 2022-10-6
### Added
- forced molecule name in Loader with *molecule* keyword
### Changed
- increased loading performance for Dace data
### Fixed
- ascii conversion for strings in ExoMol data

## [1.0.5] - 2021-05-11
### Added
- support for DACE opacities original data
Expand All @@ -24,6 +32,7 @@ First RAPOC release


[Unreleased]: https://github.com/ExObsSim/Rapoc
[1.0.8]: https://github.com/ExObsSim/Rapoc-public/compare/v1.0.5...v1.0.8
[1.0.5]: https://github.com/ExObsSim/Rapoc-public/compare/v1.0.4...v1.0.5
[1.0.4]: https://github.com/ExObsSim/Rapoc-public/compare/v1.0.0...v1.0.4
[1.0.0]: https://github.com/ExObsSim/Rapoc-public/releases/tag/v1.0.0
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![PyPI version](https://badge.fury.io/py/rapoc.svg)](https://badge.fury.io/py/rapoc)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/ExObsSim/Rapoc-public?color=gree&label=GitHub%20release)
[![Downloads](https://pepy.tech/badge/rapoc)](https://pepy.tech/project/rapoc)
[![Documentation Status](https://readthedocs.org/projects/rapoc-public/badge/?version=latest)](https://rapoc-public.readthedocs.io/en/latest/?badge=latest)
![GitHub](https://img.shields.io/github/license/ExObsSim/Rapoc-public)

Expand Down
4 changes: 3 additions & 1 deletion docs/source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,6 @@ webencodings==0.5.1
Werkzeug==1.0.1
wrapt==1.12.1
xlrd==1.2.0
xlwt==1.3.0
xlwt==1.3.0
nbsphinx
sphinx_rtd_theme
10 changes: 10 additions & 0 deletions docs/source/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ After this, two classes can be produced, one for Rosseland and the other for Pla
ross = Rosseland(input_data=input_file)
plan = Planck(input_data=input_file)
Identifying the molecule
++++++++++++++++++++++++++
Normally, the molecule name is automatically extracted from the input data.
However, if the molecule name is not present in the input data, it can be manually set using the `molecule` keyword argument:

.. code-block:: python
ross = Rosseland(input_data=input_file, molecule='H2O')
plan = Planck(input_data=input_file, molecule='H2O')
Calculating the mean opacities
------------------------------

Expand Down
35 changes: 25 additions & 10 deletions rapoc/__about__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
import os.path

from datetime import date

__all__ = [
'__pkg_name__',
"__title__",
"__summary__",
"__url__",
"__commit__",
"__author__",
"__email__",
"__license__",
"__copyright__",
"__branch__",
"__commit__",
"__base_dir__"
]

try:
base_dir = os.path.dirname(os.path.abspath(__file__))
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
except NameError:
base_dir = None

__title__ = "rapoc"
__summary__ = "Rosseland And Planck Opacity Converter"
__url__ = "https://github.com/ExObsSim/Rapoc-public"

if base_dir is not None and os.path.exists(os.path.join(base_dir, ".commit")):
with open(os.path.join(base_dir, ".commit")) as fp:
__commit__ = fp.read().strip()
__base_dir__ = base_dir
__branch__ = None
if base_dir is not None and os.path.exists(os.path.join(base_dir, ".git")):
git_folder = os.path.join(base_dir, ".git")
with open(os.path.join(git_folder, "HEAD")) as fp:
ref = fp.read().strip()
ref_dir = ref[5:]
__branch__ = ref[16:]
try:
with open(os.path.join(git_folder, ref_dir)) as fp:
__commit__ = fp.read().strip()
except FileNotFoundError:
__commit__ = None
else:
__commit__ = None

__pkg_name__ = "rapoc"
__title__ = "RAPOC"
__summary__ = "Rosseland And Planck Opacity Converter"
__url__ = "https://github.com/ExObsSim/Rapoc-public"
__author__ = "Lorenzo V. Mugnai, Darius Modirrousta-Galian"
__email__ = "lorenzo.mugnai@uniroma1.it"

__license__ = "BSD-3-Clause"
__copyright__ = "2020 %s" % __author__
__copyright__ = '2020-{:d}, {}'.format(date.today().year, __author__)
6 changes: 6 additions & 0 deletions rapoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
__license__,
__summary__,
__title__,
__pkg_name__,
__url__,
__branch__,
__base_dir__
)
from .__version__ import __version__

Expand All @@ -18,8 +21,11 @@
"__license__",
"__summary__",
"__title__",
"__pkg_name__",
"__url__",
"__version__",
"__branch__",
"__base_dir__"
]

from . import models
Expand Down
2 changes: 1 addition & 1 deletion rapoc/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.5'
__version__ = '1.0.8'
2 changes: 1 addition & 1 deletion rapoc/loaders/exoMolFileLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _close(self, opened_file):
opened_file.close()

def _read_molecule_name(self, opened_file):
return opened_file['mol_name'][()][0]
return opened_file['mol_name'][()][0].decode('ascii')

def _get_mol_mass(self, mol):
from molmass import Formula
Expand Down
12 changes: 9 additions & 3 deletions rapoc/loaders/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ class FileLoader:
'''

def __init__(self, filename):
def __init__(self, filename, molecule=None):
'''
Parameters
----------
filename: str
data file name
molecule: str
forced molecule name
'''
self.filename = filename
self._forced_molname = molecule

def read_content(self):
'''
Reads the file content and returns the needed valued for the opacity models.
Reads the file content and returns the needed values for the opacity models.
Returns
-------
Expand All @@ -36,7 +39,10 @@ def read_content(self):
data opacities grid in si units
'''
opened_file = self._open()
mol = self._read_molecule_name(opened_file)
if self._forced_molname is not None:
mol = self._forced_molname
else:
mol = self._read_molecule_name(opened_file)
mol_mass = self._get_mol_mass(mol)
pressure_grid = self._read_pressure_grid(opened_file)
temperature_grid = self._read_temperature_grid(opened_file)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def test_wavenumber_grid(self):
def test_opacity(self):
self.assertEqual(self.opacity.unit, u.m ** 2 / u.kg)

class ExoMolLoaderMolNameTest(unittest.TestCase):
loaded = ExoMolFileLoader(filename=exomol_file, molecule='H3O')
mol, mol_mass, pressure_grid, temperature_grid, wavenumber_grid, opacity, force_t = loaded.read_content()

def test_mol(self):
self.assertEqual(self.mol, 'H3O')

class DaceLoaderTest(unittest.TestCase):
loaded = DACEFileLoader(filename=dace_file)
Expand Down

0 comments on commit 4d3d160

Please sign in to comment.