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

add linelist exposure to atom data and reader #2427

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
35 changes: 14 additions & 21 deletions tardis/io/atom_data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class AtomData(object):
"photoionization_data",
"yg_data",
"two_photon_data",
"linelist",
]

# List of tuples of the related dataframes.
Expand Down Expand Up @@ -165,10 +166,9 @@ 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.select(name)
dataframes[name] = store[name]
except KeyError:
logger.debug(f"Dataframe does not contain {name} column")
nonavailable.append(name)
Expand All @@ -182,7 +182,6 @@ def from_hdf(cls, fname=None):
# Checks for various collisional data from Carsus files
if "collisions_data" in store:
try:

dataframes["collision_data_temperatures"] = store[
"collisions_metadata"
].temperatures
Expand Down Expand Up @@ -211,6 +210,8 @@ def from_hdf(cls, fname=None):
raise ValueError(
f"Current carsus version, {carsus_version}, is not supported."
)
if "linelist" in store:
dataframes["linelist"] = store["linelist"]

atom_data = cls(**dataframes)

Expand Down Expand Up @@ -273,8 +274,8 @@ def __init__(
photoionization_data=None,
yg_data=None,
two_photon_data=None,
linelist=None,
):

self.prepared = False

# CONVERT VALUES TO CGS UNITS
Expand All @@ -287,33 +288,25 @@ def __init__(
if u.u.cgs == const.u.cgs:
atom_data.loc[:, "mass"] = Quantity(
atom_data["mass"].values, "u"
).cgs.value
).cgs
else:
atom_data.loc[:, "mass"] = (
atom_data["mass"].values * const.u.cgs.value
)
atom_data.loc[:, "mass"] = atom_data["mass"].values * const.u.cgs

# Convert ionization energies to CGS
ionization_data = ionization_data.squeeze()
ionization_data[:] = Quantity(ionization_data[:], "eV").cgs.value
ionization_data[:] = Quantity(ionization_data[:], "eV").cgs

# Convert energy to CGS
levels.loc[:, "energy"] = Quantity(
levels["energy"].values, "eV"
).cgs.value
levels.loc[:, "energy"] = Quantity(levels["energy"].values, "eV").cgs

# Create a new columns with wavelengths in the CGS units
lines["wavelength_cm"] = Quantity(
lines["wavelength"], "angstrom"
).cgs.value
lines["wavelength_cm"] = Quantity(lines["wavelength"], "angstrom").cgs

# SET ATTRIBUTES

self.atom_data = atom_data
self.ionization_data = ionization_data
self.levels = levels
# Not sure why this is need - WEK 17 Sep 2023
self.levels.energy = self.levels.energy.astype(np.float64)
self.lines = lines

# Rename these (drop "_all") when `prepare_atom_data` is removed!
Expand All @@ -333,6 +326,9 @@ def __init__(

self.two_photon_data = two_photon_data

if linelist is not None:
self.linelist = linelist

self._check_related()

self.symbol2atomic_number = OrderedDict(
Expand Down Expand Up @@ -426,7 +422,6 @@ def prepare_atom_data(
self.macro_atom_data_all is not None
and not line_interaction_type == "scatter"
):

self.macro_atom_data = self.macro_atom_data_all.loc[
self.macro_atom_data_all["atomic_number"].isin(
self.selected_atomic_numbers
Expand Down Expand Up @@ -530,9 +525,7 @@ def prepare_atom_data(
self.macro_atom_data.loc[:, "destination_level_idx"] = -1

if self.yg_data is not None:
self.yg_data = self.yg_data.reindex(
self.selected_atomic_numbers, level=0
)
self.yg_data = self.yg_data.loc[self.selected_atomic_numbers]

self.nlte_data = NLTEData(self, nlte_species)

Expand Down