Skip to content

Commit

Permalink
Backport PR #210: Fix version checking (#211)
Browse files Browse the repository at this point in the history
Co-authored-by: Will Barnes <[email protected]>
  • Loading branch information
meeseeksmachine and wtbarnes authored Jan 4, 2023
1 parent bda42b1 commit f970729
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ def pytest_addoption(parser):
parser.addoption('--idl-executable', action='store', default=None)
parser.addoption('--idl-codebase-root', action='store', default=None)
parser.addoption('--include-all-files', action='store', default=False)
parser.addoption('--skip-version-check', action='store_true', default=False,
help='Do not check CHIANTI version')
5 changes: 4 additions & 1 deletion fiasco/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ def hdf5_dbase_root(ascii_dbase_tree, tmpdir_factory, request):
test_files = TEST_FILES
# Optionally use a different URL for the database (e.g. for testing different versions)
ascii_dbase_url = request.config.getoption('--ascii-dbase-url')
# Optionally disable version checking. This is useful when testing newer/older versions
# of CHIANTI
check_chianti_version = not request.config.getoption('--skip-version-check')
# Finally, run the database setup
check_database(path,
ascii_dbase_root=ascii_dbase_tree,
ask_before=False,
ascii_dbase_url=ascii_dbase_url,
check_chianti_version=False,
check_chianti_version=check_chianti_version,
files=test_files)
return path

Expand Down
2 changes: 1 addition & 1 deletion fiasco/io/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __call__(cls, *args, **kwargs):
elif filetype_name in subclass_dict:
return subclass_dict[filetype_name](*args, **kwargs)
else:
log.warning(f'Unrecognized filename and extension {args[0]}', stacklevel=2)
log.debug(f'Unrecognized filename and extension {args[0]}', stacklevel=2)
return type.__call__(cls, *args, **kwargs)


Expand Down
15 changes: 11 additions & 4 deletions fiasco/io/generic.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
Base class for file parser
"""
import astropy
import astropy.units as u
import h5py
import numpy as np
import os
import pathlib
import warnings

from astropy.table import QTable
from astropy.utils.exceptions import AstropyUserWarning

import fiasco

Expand Down Expand Up @@ -55,9 +57,14 @@ def parse(self):
self.preprocessor(table, line, i)

df = QTable(data=list(map(list, zip(*table))), names=self.headings)
for name, unit, dtype in zip(self.headings, self.units, self.dtypes):
df[name].unit = unit
df[name] = df[name].astype(dtype)
# This cataches a warning thrown when we convert a staggered array into
# a unitful column. This happens in several of the scups files for the
# bt_t, bt_type, bt_upsilon columns.
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=AstropyUserWarning)
for name, unit, dtype in zip(self.headings, self.units, self.dtypes):
df[name].unit = unit
df[name] = df[name].astype(dtype)

df.meta['footer'] = self.extract_footer(lines)
df.meta['chianti_version'] = self.chianti_version
Expand Down
2 changes: 1 addition & 1 deletion fiasco/ions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __repr__(self):
Number of Levels: {n_levels}
Number of Transitions: {n_transitions}
Temperature range: [{self.temperature[0].to(u.MK):.3f}, {self.temperature[-1].to(u.MK)}:.3f]
Temperature range: [{self.temperature[0].to(u.MK):.3f}, {self.temperature[-1].to(u.MK):.3f}]
HDF5 Database: {self.hdf5_dbase_root}
Using Datasets:
Expand Down
2 changes: 1 addition & 1 deletion fiasco/util/setup_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def check_database(hdf5_dbase_root, **kwargs):


def check_database_version(hdf5_dbase_root):
dl = DataIndexer.create_indexer(hdf5_dbase_root, '/')
dl = DataIndexer.create_indexer(hdf5_dbase_root, '/h/h_1/elvlc')
if dl.version not in SUPPORTED_VERSIONS:
raise UnsupportedVersionError(
f'CHIANTI {dl.version} is not in the list of supported versions {SUPPORTED_VERSIONS}.')
Expand Down

0 comments on commit f970729

Please sign in to comment.