Skip to content

Commit

Permalink
use np interpolator instead of scipy (tardis-sn#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshields authored Oct 14, 2024
1 parent 3be28e2 commit b921279
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 4 additions & 3 deletions stardis/plasma/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging

from astropy import constants as const, units as u
from scipy.interpolate import interp1d

from tardis.plasma.base import BasePlasma
from tardis.plasma.properties.base import (
Expand Down Expand Up @@ -118,11 +117,13 @@ class H2PlusDensity(ProcessingPlasmaProperty):
outputs = ("h2_plus_density",)

def calculate(self, ion_number_density, t_rad):
interp_Ks = interp1d(H2_PLUS_K_SAMPLE_TEMPS, H2_PLUS_K_EQUILIBRIUM_CONSTANT)
h_neutral_density = ion_number_density.loc[1, 0]
h_plus_density = ion_number_density.loc[1, 1]
resampled_Ks = np.interp(
t_rad, H2_PLUS_K_SAMPLE_TEMPS, H2_PLUS_K_EQUILIBRIUM_CONSTANT
)
return (
h_neutral_density * h_plus_density / interp_Ks(t_rad) * 1e-19
h_neutral_density * h_plus_density / resampled_Ks * 1e-19
) # scale factor from Stancil 1994 table 1


Expand Down
11 changes: 3 additions & 8 deletions stardis/radiation_field/opacities/opacities_solvers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from astropy import units as u, constants as const
from tardis.util.base import species_string_to_tuple

from scipy.interpolate import interp1d, LinearNDInterpolator
from scipy.interpolate import LinearNDInterpolator


def sigma_file(tracing_lambdas, temperatures, fpath, opacity_source=None):
Expand Down Expand Up @@ -83,16 +83,11 @@ def sigma_file(tracing_lambdas, temperatures, fpath, opacity_source=None):
h_minus_bf_table = pd.read_csv(
fpath, header=None, comment="#", names=["wavelength", "cross_section"]
)
linear_interp_1d_from_file = interp1d(
sigmas = np.interp(
tracing_lambdas,
h_minus_bf_table.wavelength.values,
h_minus_bf_table.cross_section.values,
bounds_error=False,
fill_value=(
h_minus_bf_table.cross_section.iloc[0],
h_minus_bf_table.cross_section.iloc[-1],
),
)
sigmas = linear_interp_1d_from_file(tracing_lambdas)

else:
raise ValueError(f"Unknown opacity_source: {opacity_source}")
Expand Down

0 comments on commit b921279

Please sign in to comment.