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

[Restructure/plasma] Refactor the simulation state initialization #2664

Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d583510
change numberdensity to input
wkerzendorf Apr 30, 2024
7aaba5d
fixed number density
wkerzendorf May 4, 2024
32b22ea
some fixes
wkerzendorf May 5, 2024
261bbad
removing density
wkerzendorf May 6, 2024
df3c406
remove atomic and isotope mass
wkerzendorf May 6, 2024
d05e819
add isotopic_number_density
wkerzendorf May 6, 2024
61f3db5
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf May 6, 2024
e804942
add opacities package
wkerzendorf May 6, 2024
e573f16
Update imports in property_collections.py, base.py, test_numba_interf…
wkerzendorf May 7, 2024
73f2ddc
Add calculate_transition_probabilities function to util.py in macro_a…
wkerzendorf May 7, 2024
52d5523
Add calculate_transition_probabilities function to util.py in macro_a…
wkerzendorf May 9, 2024
9530fee
Remove unused imports and update plasma properties
wkerzendorf May 9, 2024
2fb7f92
add __init__ to macroatom
wkerzendorf May 9, 2024
6ac3e88
blackify tardis
wkerzendorf May 10, 2024
801c92b
blackified
wkerzendorf May 10, 2024
ae0650d
chore: Update imports and remove unused code
wkerzendorf May 10, 2024
69dc1b5
chore: Add PlanckRadiationField and DilutePlanckRadiationField classes
wkerzendorf May 10, 2024
448d5c4
chore: Update imports and remove unused code
wkerzendorf May 10, 2024
c1dc52d
removed density
wkerzendorf May 13, 2024
f053967
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf May 20, 2024
17c033c
Merge branch 'restructure/plasma_prepare' into restructure/plasma_opa…
wkerzendorf May 23, 2024
5e02054
ruff output
wkerzendorf Jun 6, 2024
28c4348
cleanup and adding object mode
wkerzendorf Jun 6, 2024
cfffe5b
starting to make radiation_field a thing
wkerzendorf Jun 7, 2024
4e68723
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jun 7, 2024
41779e2
switched over to old tau_sobolev calculation
wkerzendorf Jun 9, 2024
0d1bc4d
renamed function to indicate numba use
wkerzendorf Jun 9, 2024
7cc84a2
Merge branch 'restructure/plasma_opacities' into restructure/plasma_r…
wkerzendorf Jun 9, 2024
c924749
address comments
wkerzendorf Jun 10, 2024
ad5a314
Merge branch 'restructure/plasma_opacities' into restructure/plasma_r…
wkerzendorf Jun 10, 2024
af7e39e
added dilute planckian radiation field
wkerzendorf Jun 11, 2024
36fa4b6
refactor: Convert species lists to proper format in assemble_plasma f…
wkerzendorf Jun 13, 2024
4bc0dd7
moved radiation field into plasma. Resulting in some renames
wkerzendorf Jun 14, 2024
863f281
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jun 19, 2024
2f042f2
some fixes
wkerzendorf Jun 19, 2024
d849f85
black montecarlo
wkerzendorf Jun 19, 2024
3379062
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jun 19, 2024
6feefbe
Merge branch 'restructure/plasma_opacities' into restructure/plasma_r…
wkerzendorf Jun 19, 2024
1786436
chore: Initialize atom data and simulation state in `initialization.py`
wkerzendorf Jun 19, 2024
5740708
updating the documentation
wkerzendorf Jun 19, 2024
63e0e0c
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jul 23, 2024
818c6d4
remove parse_input.py
wkerzendorf Jul 23, 2024
3ec64f1
chore: Refactor radiation field configuration parsing and state creation
wkerzendorf Jul 23, 2024
f1f0cdd
revert astropy_helpers
wkerzendorf Jul 23, 2024
2a7d460
remove astropy_helpers
wkerzendorf Jul 23, 2024
dbc34ac
removed test.txt
wkerzendorf Jul 23, 2024
251d1cb
blackified code
wkerzendorf Jul 23, 2024
e80b15c
Merge branch 'restructure/plasma_radiation_field' into restructure/si…
wkerzendorf Jul 23, 2024
d49a49c
cleanup simulation from merges
wkerzendorf Jul 23, 2024
adbaf7f
fix
wkerzendorf Jul 24, 2024
bb19fdb
remove unused Input
wkerzendorf Jul 24, 2024
aca1099
added description
wkerzendorf Jul 24, 2024
44ffcf9
Merge branch 'restructure/plasma_radiation_field' into restructure/si…
wkerzendorf Jul 24, 2024
54ffe68
blackiefied codebase
wkerzendorf Jul 24, 2024
9800fc8
blackify code
wkerzendorf Jul 24, 2024
5914618
Merge branch 'restructure/plasma_radiation_field' into restructure/si…
wkerzendorf Jul 24, 2024
d19e423
chore: Refactor atom data parsing and simulation state initialization
wkerzendorf Jul 24, 2024
b3bf356
restructure logger
wkerzendorf Jul 24, 2024
2353c89
Merge remote-tracking branch 'upstream/master' into restructure/simul…
wkerzendorf Jul 24, 2024
d22b2dd
merge changes
wkerzendorf Jul 24, 2024
1355971
blackify
wkerzendorf Jul 25, 2024
c402d41
ruffify
wkerzendorf Jul 25, 2024
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
960 changes: 960 additions & 0 deletions docs/physics/nlte/nlte_rates.ipynb

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions docs/physics/plasma/construction_simple_plasma.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Constructing a simple plasma"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/wkerzend/python/tardis/tardis/__init__.py:20: UserWarning: Astropy is already imported externally. Astropy should be imported after TARDIS.\n",
" warnings.warn(\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bbbd27367e48465696aa4e40f25b8496",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Iterations: 0/? [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6830a2c86f754397999e6801ccca1001",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Packets: 0/? [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from astropy import units as u\n",
"from tardis.radiation_field.planck_rad_field import DilutePlanckianRadiationField\n",
"#from tardis.plasma.properties.plasma_input import T"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"temperatures_rad = np.ones(10) * 10000 * u.K\n",
"dilution_factor = np.ones(10) * 0.1"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"d_radfield = DilutePlanckianRadiationField(temperature=temperatures_rad, dilution_factor=dilution_factor)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"test = DilutePlanckianRadFieldInput()\n",
"test.set_value(d_radfield)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
13 changes: 3 additions & 10 deletions tardis/io/model/parse_radiation_field_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os

import numpy as np
from astropy import units as u
Expand All @@ -8,9 +7,7 @@
from tardis.io.model.parse_geometry_configuration import (
parse_structure_from_config,
)
from tardis.model.radiation_field_state import (
DiluteBlackBodyRadiationFieldState,
)
from tardis.plasma.radiation_field import DilutePlanckianRadiationField

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -42,7 +39,7 @@
AssertionError
If the length of t_radiative or dilution_factor is not compatible with the geometry.
"""
(

Check warning on line 42 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L42

Added line #L42 was not covered by tests
density_time,
velocity,
density,
Expand All @@ -50,26 +47,24 @@
temperature,
) = parse_structure_from_config(config)

if temperature is None:
if config.plasma.initial_t_rad > 0 * u.K:
temperature = (

Check warning on line 52 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L50-L52

Added lines #L50 - L52 were not covered by tests
np.ones(geometry.no_of_shells) * config.plasma.initial_t_rad
)
else:
temperature = calculate_t_radiative_from_t_inner(

Check warning on line 56 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L56

Added line #L56 was not covered by tests
geometry, packet_source
)

assert len(temperature) == geometry.no_of_shells

Check warning on line 60 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L60

Added line #L60 was not covered by tests

if dilution_factor is None:
dilution_factor = calculate_geometric_dilution_factor(geometry)

Check warning on line 63 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L62-L63

Added lines #L62 - L63 were not covered by tests

assert len(dilution_factor) == geometry.no_of_shells

Check warning on line 65 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L65

Added line #L65 was not covered by tests

return DiluteBlackBodyRadiationFieldState(
temperature, dilution_factor, geometry
)
return DilutePlanckianRadiationField(temperature, dilution_factor, geometry)

Check warning on line 67 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L67

Added line #L67 was not covered by tests


def parse_radiation_field_state_from_csvy(
Expand All @@ -95,46 +90,44 @@
DiluteThermalRadiationFieldState
The parsed radiation field state.
"""
t_radiative = None
dilution_factor = None

Check warning on line 94 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L93-L94

Added lines #L93 - L94 were not covered by tests

if hasattr(csvy_model_data, "columns") and (

Check warning on line 96 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L96

Added line #L96 was not covered by tests
"t_rad" in csvy_model_data.columns
):
t_rad_field_index = [

Check warning on line 99 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L99

Added line #L99 was not covered by tests
field["name"] for field in csvy_model_config.datatype.fields
].index("t_rad")
t_rad_unit = u.Unit(

Check warning on line 102 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L102

Added line #L102 was not covered by tests
csvy_model_config.datatype.fields[t_rad_field_index]["unit"]
)
t_radiative = csvy_model_data["t_rad"].iloc[1:].values * t_rad_unit

Check warning on line 105 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L105

Added line #L105 was not covered by tests

elif config.plasma.initial_t_rad > 0 * u.K:
t_radiative = (

Check warning on line 108 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L107-L108

Added lines #L107 - L108 were not covered by tests
np.ones(geometry.no_of_shells) * config.plasma.initial_t_rad
)
else:
t_radiative = calculate_t_radiative_from_t_inner(

Check warning on line 112 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L112

Added line #L112 was not covered by tests
geometry, packet_source
)

if np.any(t_radiative < 1000 * u.K):
logging.critical(

Check warning on line 117 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L116-L117

Added lines #L116 - L117 were not covered by tests
"Radiative temperature is too low in some of the shells, temperatures below 1000K "
f"(e.g., T_rad = {t_radiative[np.argmin(t_radiative)]} in shell {np.argmin(t_radiative)} in your model) "
"are not accurately handled by TARDIS.",
)

if hasattr(csvy_model_data, "columns") and (

Check warning on line 123 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L123

Added line #L123 was not covered by tests
"dilution_factor" in csvy_model_data.columns
):
dilution_factor = csvy_model_data["dilution_factor"].iloc[1:].values

Check warning on line 126 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L126

Added line #L126 was not covered by tests
else:
dilution_factor = calculate_geometric_dilution_factor(geometry)

Check warning on line 128 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L128

Added line #L128 was not covered by tests

return DiluteBlackBodyRadiationFieldState(
t_radiative, dilution_factor, geometry
)
return DilutePlanckianRadiationField(t_radiative, dilution_factor, geometry)

Check warning on line 130 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L130

Added line #L130 was not covered by tests


def calculate_t_radiative_from_t_inner(geometry, packet_source):
Expand All @@ -153,12 +146,12 @@
Quantity
The calculated radiative temperature.
"""
lambda_wien_inner = const.b_wien / packet_source.temperature
t_radiative = const.b_wien / (

Check warning on line 150 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L149-L150

Added lines #L149 - L150 were not covered by tests
lambda_wien_inner
* (1 + (geometry.v_middle - geometry.v_inner_boundary) / const.c)
)
return t_radiative

Check warning on line 154 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L154

Added line #L154 was not covered by tests


def calculate_geometric_dilution_factor(geometry):
Expand All @@ -174,7 +167,7 @@
np.array
The dilution factors for the inout geometry
"""
return 0.5 * (

Check warning on line 170 in tardis/io/model/parse_radiation_field_configuration.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/parse_radiation_field_configuration.py#L170

Added line #L170 was not covered by tests
1
- np.sqrt(
1
Expand Down
2 changes: 1 addition & 1 deletion tardis/io/model/readers/csvy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
-------
yaml_dict : dictionary
YAML part of the csvy file
data : pandas.dataframe
data : pandas.DataFrame
csv data from csvy file
"""
with open(fname) as fh:
Expand Down Expand Up @@ -111,14 +111,14 @@
isotope_mass_fraction : pandas.MultiIndex
"""

mass_fraction_col_names = [

Check warning on line 114 in tardis/io/model/readers/csvy.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/readers/csvy.py#L114

Added line #L114 was not covered by tests
name for name in csvy_data.columns if is_valid_nuclide_or_elem(name)
]
df = csvy_data.loc[:, mass_fraction_col_names]

Check warning on line 117 in tardis/io/model/readers/csvy.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/readers/csvy.py#L117

Added line #L117 was not covered by tests

df = df.transpose()

mass_fractions = pd.DataFrame(

Check warning on line 121 in tardis/io/model/readers/csvy.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/readers/csvy.py#L121

Added line #L121 was not covered by tests
columns=np.arange(df.shape[1]),
index=pd.Index([], name="atomic_number"),
dtype=np.float64,
Expand All @@ -127,20 +127,20 @@
isotope_index = pd.MultiIndex(
[[]] * 2, [[]] * 2, names=["atomic_number", "mass_number"]
)
isotope_mass_fractions = pd.DataFrame(

Check warning on line 130 in tardis/io/model/readers/csvy.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/readers/csvy.py#L130

Added line #L130 was not covered by tests
columns=np.arange(df.shape[1]), index=isotope_index, dtype=np.float64
)

for element_symbol_string in df.index[0:]:
if element_symbol_string in Z_DICT.values():
z = elem_to_Z(element_symbol_string)
mass_fractions.loc[z, :] = df.loc[element_symbol_string].tolist()

Check warning on line 137 in tardis/io/model/readers/csvy.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/readers/csvy.py#L137

Added line #L137 was not covered by tests
else:
nuc = Nuclide(element_symbol_string)
z = nuc.Z
mass_no = nuc.A
isotope_mass_fractions.loc[(z, mass_no), :] = df.loc[

Check warning on line 142 in tardis/io/model/readers/csvy.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/readers/csvy.py#L142

Added line #L142 was not covered by tests
element_symbol_string
].tolist()

return mass_fractions.index, mass_fractions, isotope_mass_fractions

Check warning on line 146 in tardis/io/model/readers/csvy.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/model/readers/csvy.py#L146

Added line #L146 was not covered by tests
4 changes: 2 additions & 2 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@

@property
def t_radiative(self):
return self.radiation_field_state.t_radiative[
return self.radiation_field_state.temperature[

Check warning on line 149 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L149

Added line #L149 was not covered by tests
self.geometry.v_inner_boundary_index : self.geometry.v_outer_boundary_index
]

@t_radiative.setter
def t_radiative(self, new_t_radiative):
if len(new_t_radiative) == self.no_of_shells:
self.radiation_field_state.t_radiative[
self.radiation_field_state.temperature[

Check warning on line 156 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L156

Added line #L156 was not covered by tests
self.geometry.v_inner_boundary_index : self.geometry.v_outer_boundary_index
] = new_t_radiative
else:
Expand Down Expand Up @@ -289,17 +289,17 @@
"""
time_explosion = config.supernova.time_explosion.cgs

geometry = parse_geometry_from_config(config, time_explosion)

Check warning on line 292 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L292

Added line #L292 was not covered by tests

composition, electron_densities = parse_composition_from_config(

Check warning on line 294 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L294

Added line #L294 was not covered by tests
atom_data, config, time_explosion, geometry
)

packet_source = parse_packet_source_from_config(

Check warning on line 298 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L298

Added line #L298 was not covered by tests
config, geometry, legacy_mode_enabled
)

radiation_field_state = parse_radiation_field_state_from_config(

Check warning on line 302 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L302

Added line #L302 was not covered by tests
config,
geometry,
dilution_factor=None,
Expand Down Expand Up @@ -382,11 +382,11 @@

electron_densities = None

geometry = parse_geometry_from_csvy(

Check warning on line 385 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L385

Added line #L385 was not covered by tests
config, csvy_model_config, csvy_model_data, time_explosion
)

composition = parse_composition_from_csvy(

Check warning on line 389 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L389

Added line #L389 was not covered by tests
atom_data,
csvy_model_config,
csvy_model_data,
Expand All @@ -394,11 +394,11 @@
geometry,
)

packet_source = parse_packet_source_from_config(

Check warning on line 397 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L397

Added line #L397 was not covered by tests
config, geometry, legacy_mode_enabled
)

radiation_field_state = parse_radiation_field_state_from_csvy(

Check warning on line 401 in tardis/model/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/model/base.py#L401

Added line #L401 was not covered by tests
config, csvy_model_config, csvy_model_data, geometry, packet_source
)

Expand Down
File renamed without changes.
123 changes: 123 additions & 0 deletions tardis/plasma/nlte/nlte_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import logging

Check warning on line 1 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L1

Added line #L1 was not covered by tests

import numpy as np
from scipy import interpolate

Check warning on line 4 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L3-L4

Added lines #L3 - L4 were not covered by tests

logger = logging.getLogger(__name__)

Check warning on line 6 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L6

Added line #L6 was not covered by tests


class NLTEData:
def __init__(self, atom_data, nlte_species):
self.atom_data = atom_data
self.lines = atom_data.lines.reset_index()
self.nlte_species = nlte_species

Check warning on line 13 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L9-L13

Added lines #L9 - L13 were not covered by tests

if nlte_species:
logger.info("Preparing the NLTE data")
self._init_indices()
if atom_data.collision_data is not None:
self._create_collision_coefficient_matrix()

Check warning on line 19 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L15-L19

Added lines #L15 - L19 were not covered by tests

def _init_indices(self):
self.lines_idx = {}
self.lines_level_number_lower = {}
self.lines_level_number_upper = {}
self.A_uls = {}
self.B_uls = {}
self.B_lus = {}

Check warning on line 27 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L21-L27

Added lines #L21 - L27 were not covered by tests

for species in self.nlte_species:
lines_idx = np.where(

Check warning on line 30 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L29-L30

Added lines #L29 - L30 were not covered by tests
(self.lines.atomic_number == species[0])
& (self.lines.ion_number == species[1])
)
self.lines_idx[species] = lines_idx
self.lines_level_number_lower[

Check warning on line 35 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L34-L35

Added lines #L34 - L35 were not covered by tests
species
] = self.lines.level_number_lower.values[lines_idx].astype(int)
self.lines_level_number_upper[

Check warning on line 38 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L38

Added line #L38 was not covered by tests
species
] = self.lines.level_number_upper.values[lines_idx].astype(int)

self.A_uls[species] = self.atom_data.lines.A_ul.values[lines_idx]
self.B_uls[species] = self.atom_data.lines.B_ul.values[lines_idx]
self.B_lus[species] = self.atom_data.lines.B_lu.values[lines_idx]

Check warning on line 44 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L42-L44

Added lines #L42 - L44 were not covered by tests

def _create_collision_coefficient_matrix(self):
self.C_ul_interpolator = {}
self.delta_E_matrices = {}
self.g_ratio_matrices = {}
collision_group = self.atom_data.collision_data.groupby(

Check warning on line 50 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L46-L50

Added lines #L46 - L50 were not covered by tests
level=["atomic_number", "ion_number"]
)
for species in self.nlte_species:
no_of_levels = self.atom_data.levels.loc[species].energy.count()
C_ul_matrix = np.zeros(

Check warning on line 55 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L53-L55

Added lines #L53 - L55 were not covered by tests
(
no_of_levels,
no_of_levels,
len(self.atom_data.collision_data_temperatures),
)
)
delta_E_matrix = np.zeros((no_of_levels, no_of_levels))
g_ratio_matrix = np.zeros((no_of_levels, no_of_levels))

Check warning on line 63 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L62-L63

Added lines #L62 - L63 were not covered by tests

for (

Check warning on line 65 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L65

Added line #L65 was not covered by tests
(
atomic_number,
ion_number,
level_number_lower,
level_number_upper,
),
line,
) in collision_group.get_group(species).iterrows():
# line.columns : delta_e, g_ratio, temperatures ...
C_ul_matrix[

Check warning on line 75 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L75

Added line #L75 was not covered by tests
level_number_lower, level_number_upper, :
] = line.values[2:]
delta_E_matrix[level_number_lower, level_number_upper] = line[

Check warning on line 78 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L78

Added line #L78 was not covered by tests
"delta_e"
]
# TODO TARDISATOMIC fix change the g_ratio to be the otherway round - I flip them now here.
g_ratio_matrix[level_number_lower, level_number_upper] = (

Check warning on line 82 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L82

Added line #L82 was not covered by tests
1 / line["g_ratio"]
)
self.C_ul_interpolator[species] = interpolate.interp1d(

Check warning on line 85 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L85

Added line #L85 was not covered by tests
self.atom_data.collision_data_temperatures, C_ul_matrix
)
self.delta_E_matrices[species] = delta_E_matrix

Check warning on line 88 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L88

Added line #L88 was not covered by tests

self.g_ratio_matrices[species] = g_ratio_matrix

Check warning on line 90 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L90

Added line #L90 was not covered by tests

def get_collision_matrix(self, species, t_electrons):

Check warning on line 92 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L92

Added line #L92 was not covered by tests
"""
Creat collision matrix by interpolating the C_ul values for
the desired temperatures.
"""
c_ul_matrix = self.C_ul_interpolator[species](t_electrons)
no_of_levels = c_ul_matrix.shape[0]
c_ul_matrix[np.isnan(c_ul_matrix)] = 0.0

Check warning on line 99 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L97-L99

Added lines #L97 - L99 were not covered by tests

# TODO in tardisatomic the g_ratio is the other way round - here I'll flip it in prepare_collision matrix

c_lu_matrix = (

Check warning on line 103 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L103

Added line #L103 was not covered by tests
c_ul_matrix
* np.exp(
-self.delta_E_matrices[species].reshape(
(no_of_levels, no_of_levels, 1)
)
/ t_electrons.reshape((1, 1, t_electrons.shape[0]))
)
* self.g_ratio_matrices[species].reshape(
(no_of_levels, no_of_levels, 1)
)
)
return c_ul_matrix + c_lu_matrix.transpose(1, 0, 2)

Check warning on line 115 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L115

Added line #L115 was not covered by tests


class NLTEMatrixFactory:
def __init__(self, nlte_species):
pass

Check warning on line 120 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L118-L120

Added lines #L118 - L120 were not covered by tests

def generate_indices(self):
pass

Check warning on line 123 in tardis/plasma/nlte/nlte_data.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/nlte/nlte_data.py#L122-L123

Added lines #L122 - L123 were not covered by tests
13 changes: 7 additions & 6 deletions tardis/plasma/properties/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
from abc import ABCMeta, abstractmethod

from abc import ABCMeta, abstractmethod, abstractproperty
import numpy as np
import pandas as pd


__all__ = [
"BasePlasmaProperty",
"BaseAtomicDataProperty",
Expand All @@ -19,7 +18,7 @@
logger = logging.getLogger(__name__)


class BasePlasmaProperty(object, metaclass=ABCMeta):
class BasePlasmaProperty(metaclass=ABCMeta):
"""
Attributes
----------
Expand All @@ -31,7 +30,8 @@
Used to label nodes when plotting graphs
"""

@abstractproperty
@property
@abstractmethod
def outputs(self):
pass

Expand Down Expand Up @@ -114,7 +114,7 @@
for i, output in enumerate(self.outputs):
setattr(self, output, new_values[i])
else:
logger.info("{} has been frozen!".format(self.name))
logger.info(f"{self.name} has been frozen!")

Check warning on line 117 in tardis/plasma/properties/base.py

View check run for this annotation

Codecov / codecov/patch

tardis/plasma/properties/base.py#L117

Added line #L117 was not covered by tests

@abstractmethod
def calculate(self, *args, **kwargs):
Expand Down Expand Up @@ -144,7 +144,8 @@
track all transition probabilities and to later combine them.
"""

@abstractproperty
@property
@abstractmethod
def transition_probabilities_outputs(self):
pass

Expand Down
Loading
Loading