Skip to content

Commit

Permalink
Avoid redundant reads of atomic data
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Jul 17, 2024
1 parent 93c7b5d commit 82baf2a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pynonthermal/spencerfano.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SpencerFanoSolver:
sourcevec: npt.NDArray[np.float64]
E_init_ev: float
sfmatrix: npt.NDArray[np.float64]
adata_polars: pd.DataFrame

def __init__(
self,
Expand Down Expand Up @@ -82,6 +83,8 @@ def __init__(
# The solution will be scaled to the true deposition rate later
self.E_init_ev = np.dot(self.engrid, self.sourcevec) * self.deltaen

self.adata_polars = None

if self.verbose:
print(
f"\nSetting up Spencer-Fano equation with {npts} energy points from"
Expand Down Expand Up @@ -163,15 +166,18 @@ def add_excitation(
)

def add_ion_ltepopexcitation(self, Z, ion_stage, n_ion, temperature=3000, adata_polars=None):
if adata_polars is None:
if adata_polars is not None:
self.adata_polars = adata_polars

if self.adata_polars is None:
# use ARTIS atomic data read by the artistools package to get the levels
adata_polars = at.atomic.get_levels_polars(
self.adata_polars = at.atomic.get_levels_polars(
Path(pynonthermal.DATADIR, "artis_files"),
get_transitions=True,
derived_transitions_columns=["epsilon_trans_ev", "lambda_angstroms", "lower_g", "upper_g"],
)

ion = adata_polars.filter(pl.col("Z") == Z).filter(pl.col("ion_stage") == ion_stage)
ion = self.adata_polars.filter(pl.col("Z") == Z).filter(pl.col("ion_stage") == ion_stage)

dfpops_thision = ion["levels"].item()

Expand Down

0 comments on commit 82baf2a

Please sign in to comment.