Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added compatability to current version of carsus atomic data #2019

Merged
merged 17 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions tardis/io/atom_data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,70 @@ 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]
except KeyError:
logger.debug(f"Dataframe does not contain {name} column")
nonavailable.append(name)

if "metadata" in store:
carsus_version = (
store["metadata"].loc[("format", "version")].value
)
if carsus_version == "1.0":
Rodot- marked this conversation as resolved.
Show resolved Hide resolved
# 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"
)
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"
Expand Down
6 changes: 5 additions & 1 deletion tardis/plasma/properties/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tardis/plasma/properties/continuum_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Rodot- marked this conversation as resolved.
Show resolved Hide resolved
return gamma_corr


Expand Down