diff --git a/tardis/io/atom_data/base.py b/tardis/io/atom_data/base.py index 28cd820da31..32548134df0 100644 --- a/tardis/io/atom_data/base.py +++ b/tardis/io/atom_data/base.py @@ -165,6 +165,7 @@ def from_hdf(cls, fname=None): fname = resolve_atom_data_fname(fname) with pd.HDFStore(fname, "r") as store: + for name in cls.hdf_names: try: dataframes[name] = store[name] @@ -172,10 +173,53 @@ def from_hdf(cls, fname=None): logger.debug(f"Dataframe does not contain {name} column") nonavailable.append(name) + if "metadata" in store: + carsus_version_str = ( + store["metadata"].loc[("format", "version")].value + ) + carsus_version = tuple(map(int, carsus_version_str.split("."))) + if carsus_version == (1, 0): + # Checks for various collisional data from Carsus files + if "collisions_data" in store: + try: + + dataframes["collision_data_temperatures"] = store[ + "collisions_metadata" + ].temperatures + if "cmfgen" in store["collisions_metadata"].dataset: + dataframes["yg_data"] = store["collisions_data"] + dataframes["collision_data"] = "dummy value" + elif ( + "chianti" + in store["collisions_metadata"].dataset + ): + dataframes["collision_data"] = store[ + "collisions_data" + ] + else: + raise KeyError( + "Atomic Data Collisions Not a Valid Chanti or CMFGEN Carsus Data File" + ) + except KeyError as e: + logger.warn( + "Atomic Data is not a Valid Carsus Atomic Data File" + ) + raise + dataframes["levels"] = store["levels_data"] + dataframes["lines"] = store["lines_data"] + else: + raise ValueError( + f"Current carsus version, {carsus_version}, is not supported." + ) + atom_data = cls(**dataframes) try: - atom_data.uuid1 = store.root._v_attrs["uuid1"].decode("ascii") + atom_data.uuid1 = store.root._v_attrs["uuid1"] + if hasattr(atom_data.uuid1, "decode"): + atom_data.uuid1 = store.root._v_attrs["uuid1"].decode( + "ascii" + ) except KeyError: logger.debug( "UUID not available for Atom Data. Setting value to None" @@ -183,7 +227,9 @@ def from_hdf(cls, fname=None): atom_data.uuid1 = None try: - atom_data.md5 = store.root._v_attrs["md5"].decode("ascii") + atom_data.md5 = store.root._v_attrs["md5"] + if hasattr(atom_data.md5, "decode"): + atom_data.md5 = store.root._v_attrs["md5"].decode("ascii") except KeyError: logger.debug( "MD5 not available for Atom Data. Setting value to None" diff --git a/tardis/plasma/properties/atomic.py b/tardis/plasma/properties/atomic.py index 9447700d0a4..d073c70030b 100644 --- a/tardis/plasma/properties/atomic.py +++ b/tardis/plasma/properties/atomic.py @@ -722,13 +722,17 @@ class YgData(ProcessingPlasmaProperty): def calculate(self, atomic_data, continuum_interaction_species): yg_data = atomic_data.yg_data + if yg_data is None: + raise ValueError( + "Tardis does not support continuum interactions for atomic data sources that do not contain yg_data" + ) mask_selected_species = yg_data.index.droplevel( ["level_number_lower", "level_number_upper"] ).isin(continuum_interaction_species) yg_data = yg_data[mask_selected_species] - t_yg = yg_data.columns.values.astype(float) + t_yg = atomic_data.collision_data_temperatures yg_data.columns = t_yg approximate_yg_data = self.calculate_yg_van_regemorter( atomic_data, t_yg, continuum_interaction_species diff --git a/tardis/plasma/properties/continuum_processes.py b/tardis/plasma/properties/continuum_processes.py index 25efa9c5d57..640568e3764 100644 --- a/tardis/plasma/properties/continuum_processes.py +++ b/tardis/plasma/properties/continuum_processes.py @@ -603,7 +603,9 @@ def calculate( ) num_neg_elements = (gamma_corr < 0).sum().sum() if num_neg_elements: - raise PlasmaException("Negative values in CorrPhotoIonRateCoeff.") + raise PlasmaException( + "Negative values in CorrPhotoIonRateCoeff. Try raising the number of montecarlo packets." + ) return gamma_corr