Skip to content

Commit

Permalink
Fix atom data attribute setting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfullard committed Aug 15, 2024
1 parent 375e519 commit 1362f7e
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tardis/io/atom_data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ def from_hdf(cls, fname=None):

atom_data = cls(**dataframes)

cls.set_attributes_from_store(store, atom_data.uuid1, "uuid1")
cls.set_attributes_from_store(store, atom_data.md5, "md5")
cls.set_attributes_from_store(
store, atom_data.version, "database_version"
atom_data.uuid1 = cls.get_attributes_from_store(store, "uuid1")
atom_data.md5 = cls.get_attributes_from_store(store, "md5")
atom_data.version = cls.get_attributes_from_store(
store, "database_version"
)

# TODO: strore data sources as attributes in carsus
Expand Down Expand Up @@ -650,25 +650,25 @@ def _check_selected_atomic_numbers(self):
def __repr__(self):
return f"<Atomic Data UUID={self.uuid1} MD5={self.md5} Lines={self.lines.line_id.count():d} Levels={self.levels.energy.count():d}>"

def set_attributes_from_store(store, attribute, store_key):
"""Sets arbitrary atom data attributes, throws error and sets to None
def get_attributes_from_store(store, store_key):
"""Gets atom_data attributes, throws error and sets to None
if they are not available.
Parameters
----------
atom_data : AtomData
The atom data to modify
store : pd.HDFStore
Data source
property : str
Property to modify
store_key : str
HDFStore value to check
"""
try:
attribute = store.root._v_attrs[store_key]
if hasattr(attribute, "decode"):
attribute = (store.root._v_attrs[attribute].decode("ascii"),)
except KeyError:
logger.debug(
f"{attribute} not available for Atom Data. Setting value to None"
f"{store_key} not available for Atom Data. Setting value to None"
)
attribute = None

return attribute

0 comments on commit 1362f7e

Please sign in to comment.