Skip to content

Commit

Permalink
Make file continuum opacities optional (#197)
Browse files Browse the repository at this point in the history
* fix benchmarks

* change to use mamba and move back to tardis_env3.yml

* use conda environment

* stop densities from being calculated if not requested

* remove benchmarks files from pr

* remove benchmarks config

* fix tests to use specifications from config

* atom data cleanup

* remove deepcopy import
  • Loading branch information
jvshields authored Jun 24, 2024
1 parent 4ee8ecb commit 14e67be
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
76 changes: 72 additions & 4 deletions stardis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def example_kurucz_atomic_data():
return AtomData.from_hdf("kurucz_cd23_chianti_H_He.h5")


@pytest.fixture(scope="session")
def example_kurucz_atomic_data_broadening():
return AtomData.from_hdf("kurucz_cd23_chianti_H_He.h5")


@pytest.fixture(scope="session")
def example_kurucz_atomic_data_parllel():
return AtomData.from_hdf("kurucz_cd23_chianti_H_He.h5")


@pytest.fixture(scope="session")
def example_config():
config_dict = validate_yaml(EXAMPLE_CONF_PATH, schemapath=SCHEMA_PATH)
Expand Down Expand Up @@ -93,6 +103,64 @@ def example_stellar_plasma(
)


@pytest.fixture(scope="session")
def example_stellar_plasma_parallel(
example_stellar_model, example_kurucz_atomic_data_parallel, example_config_parallel
):
example_kurucz_atomic_data_parallel.prepare_atom_data(
np.arange(
1,
np.min(
[
len(
example_stellar_model.composition.elemental_mass_fraction.columns.tolist()
),
example_config_parallel.model.final_atomic_number,
]
)
+ 1,
),
line_interaction_type="macroatom",
nlte_species=[],
continuum_interaction_species=[],
)
return create_stellar_plasma(
example_stellar_model,
example_kurucz_atomic_data_parallel,
example_config_parallel,
)


@pytest.fixture(scope="session")
def example_stellar_plasma_broadening(
example_stellar_model,
example_kurucz_atomic_data_broadening,
example_config_broadening,
):
example_kurucz_atomic_data_broadening.prepare_atom_data(
np.arange(
1,
np.min(
[
len(
example_stellar_model.composition.elemental_mass_fraction.columns.tolist()
),
example_config_broadening.model.final_atomic_number,
]
)
+ 1,
),
line_interaction_type="macroatom",
nlte_species=[],
continuum_interaction_species=[],
)
return create_stellar_plasma(
example_stellar_model,
example_kurucz_atomic_data_broadening,
example_config_broadening,
)


@pytest.fixture(scope="session")
def example_stellar_radiation_field(
example_stellar_model, example_config, example_tracing_nus, example_stellar_plasma
Expand Down Expand Up @@ -121,14 +189,14 @@ def example_stellar_radiation_field_broadening(
example_stellar_model,
example_config_broadening,
example_tracing_nus,
example_stellar_plasma,
example_stellar_plasma_broadening,
):
stellar_radiation_field = RadiationField(
example_tracing_nus, blackbody_flux_at_nu, example_stellar_model
)

calc_alphas(
stellar_plasma=example_stellar_plasma,
stellar_plasma=example_stellar_plasma_broadening,
stellar_model=example_stellar_model,
stellar_radiation_field=stellar_radiation_field,
opacity_config=example_config_broadening.opacity,
Expand All @@ -147,14 +215,14 @@ def example_stellar_radiation_field_parallel(
example_stellar_model,
example_config_parallel,
example_tracing_nus,
example_stellar_plasma,
example_stellar_plasma_broadening,
):
stellar_radiation_field = RadiationField(
example_tracing_nus, blackbody_flux_at_nu, example_stellar_model
)

calc_alphas(
stellar_plasma=example_stellar_plasma,
stellar_plasma=example_stellar_plasma_broadening,
stellar_model=example_stellar_model,
stellar_radiation_field=stellar_radiation_field,
opacity_config=example_config_parallel.opacity,
Expand Down
9 changes: 6 additions & 3 deletions stardis/plasma/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,12 @@ def create_stellar_plasma(
)
plasma_modules += helium_lte_properties

plasma_modules.append(HMinusDensity)
plasma_modules.append(H2Density)
plasma_modules.append(H2PlusDensity)
if hasattr(config.opacity.file, "Hminus_bf"):
plasma_modules.append(HMinusDensity)
if hasattr(config.opacity.file, "H2minus_bf"):
plasma_modules.append(H2Density)
if hasattr(config.opacity.file, "H2plus_bf"):
plasma_modules.append(H2PlusDensity)

if config.opacity.line.vald_linelist.use_linelist:
if config.opacity.line.vald_linelist.shortlist:
Expand Down
6 changes: 4 additions & 2 deletions stardis/radiation_field/opacities/opacities_solvers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def sigma_file(tracing_lambdas, temperatures, fpath, opacity_source=None):
if (
opacity_source == "H2plus_bf"
): # This section specifically ingests the Stancil 1994 h2_plus_bf_S1994.dat table found in data.
h2_plus_bf_table = pd.read_csv(fpath, delimiter="\s+", index_col=0, comment="#")
h2_plus_bf_table = pd.read_csv(
fpath, delimiter=r"\s+", index_col=0, comment="#"
)
h2_plus_bf_table.replace({"-": "e-"}, regex=True, inplace=True)
h2_plus_bf_table = h2_plus_bf_table.astype(float)
file_wavelengths = (h2_plus_bf_table.index.values * u.nm).to(u.AA).value
Expand All @@ -53,7 +55,7 @@ def sigma_file(tracing_lambdas, temperatures, fpath, opacity_source=None):
elif (
opacity_source == "Hminus_ff"
): # This section specifically ingests the Bell and Berrington 1987 h_minus_ff_B1987.dat table found in data.
h_minus_ff_table = pd.read_csv(fpath, delimiter="\s+", comment="#")
h_minus_ff_table = pd.read_csv(fpath, delimiter=r"\s+", comment="#")
h_minus_ff_table.columns = h_minus_ff_table.columns.str.strip(",")

file_wavelengths = h_minus_ff_table[h_minus_ff_table.columns[0]].values
Expand Down
2 changes: 1 addition & 1 deletion stardis/tests/stardis_test_config_parallel.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
stardis_config_version: 1.0
n_threads: -99
n_threads: 0
atom_data: kurucz_cd23_chianti_H_He.h5
model:
type: marcs
Expand Down

0 comments on commit 14e67be

Please sign in to comment.