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/estimators #2500

Closed
wants to merge 199 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
314cf30
restructure of geometry
wkerzendorf Sep 28, 2023
d353133
add radial1d boundary logic
wkerzendorf Oct 4, 2023
2475551
black format
wkerzendorf Oct 4, 2023
e6d1697
several fixes
wkerzendorf Oct 4, 2023
3c53cda
fix epsilon
wkerzendorf Oct 4, 2023
6dce2b4
add testing of boundaries
wkerzendorf Oct 4, 2023
1fdcea8
change the r_inner_active
wkerzendorf Oct 4, 2023
56e9da5
first integration with `from_config` working
wkerzendorf Oct 7, 2023
f6743d7
hunting down density indexing bug
wkerzendorf Oct 8, 2023
b55b21d
all model tests (without csvy) pass
wkerzendorf Oct 8, 2023
ed978d9
more fixes
wkerzendorf Oct 9, 2023
cae9c19
fix of model to simulation_state
wkerzendorf Oct 9, 2023
d829e73
fix inner boundary packet error
wkerzendorf Oct 9, 2023
9592a97
fix some leftovers
wkerzendorf Oct 10, 2023
4da6869
final fix for csvy
wkerzendorf Oct 10, 2023
f381d2e
blackify
wkerzendorf Oct 10, 2023
e59741d
restructure to readers and remove some leftover code
wkerzendorf Oct 11, 2023
a42dd55
further cleanup
wkerzendorf Oct 11, 2023
3288c6c
first start of the restructure
wkerzendorf Oct 11, 2023
518a8f9
add comment about removing quantitiness
wkerzendorf Oct 11, 2023
c78b6de
add velocity check
wkerzendorf Oct 11, 2023
006ca9d
add new abundance functions
wkerzendorf Oct 12, 2023
9c680a8
remove default units
wkerzendorf Oct 12, 2023
268bd23
add new matter module
wkerzendorf Oct 12, 2023
6b03e93
several restructures. move decay from io to tardis/model/matter
wkerzendorf Oct 12, 2023
3114413
mid restructure
wkerzendorf Oct 13, 2023
217dcf2
slow progress on abundance refactor
wkerzendorf Oct 16, 2023
78055b4
include effective_element_masses
wkerzendorf Oct 22, 2023
73f5175
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Oct 22, 2023
b96d717
further updates
wkerzendorf Nov 2, 2023
08ea21d
fix of csvy readers
wkerzendorf Nov 2, 2023
f0fc7c2
last fixes to custom abundance widget
wkerzendorf Nov 4, 2023
fe7c415
restructuring the radiation field
wkerzendorf Nov 5, 2023
226fb57
some cleanup
wkerzendorf Nov 5, 2023
cbd025e
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 5, 2023
afb9613
cleanup
wkerzendorf Nov 5, 2023
daf12a5
further cleanup
wkerzendorf Nov 5, 2023
f2d26a8
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 5, 2023
7575512
clearnup
wkerzendorf Nov 5, 2023
dc34343
changes
wkerzendorf Nov 6, 2023
37d36e1
remove matter base.py
wkerzendorf Nov 8, 2023
4a77a4a
removing matter
wkerzendorf Nov 8, 2023
dbd47cc
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 8, 2023
f4be8c6
Fix zero division handling in normalize_trans_probs (which breaks to_…
chvogl Nov 10, 2023
f12775d
Use correct references_idx for levels
chvogl Nov 10, 2023
a9398ed
Convert probabilities to float64
chvogl Nov 10, 2023
d1792bf
fixed last tests
wkerzendorf Nov 20, 2023
c757848
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 20, 2023
1f42760
first commit for regression_data
wkerzendorf Nov 20, 2023
5b1c7b2
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 20, 2023
398631a
add several parsers
wkerzendorf Nov 20, 2023
ed60c0f
add composition
wkerzendorf Nov 20, 2023
8723fdf
remove isotopemassfractions
wkerzendorf Nov 20, 2023
08874ca
some small fixes
wkerzendorf Nov 20, 2023
d89b957
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 20, 2023
1da7ed0
fixed w, t_rad to dilution_factor, t_radiative
wkerzendorf Nov 20, 2023
9f28ecd
add setters for w, t_rad
wkerzendorf Nov 20, 2023
0d85540
several fixes for instantiating the right t_rads.
wkerzendorf Nov 21, 2023
7161791
add the from_config atom_data
wkerzendorf Nov 21, 2023
4f4aad6
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 21, 2023
f65a2d7
fixing model.ipynb
wkerzendorf Nov 21, 2023
cbfe685
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 21, 2023
b961734
fix some more tests
wkerzendorf Nov 21, 2023
63a86fb
start of montecarlo restructure
wkerzendorf Nov 21, 2023
1d46d45
large scale changes
wkerzendorf Nov 22, 2023
9a21714
further disentangling state and solver
wkerzendorf Nov 23, 2023
1c38607
fix tests
wkerzendorf Nov 23, 2023
c99e9d4
fix some of the issues wdigets
wkerzendorf Nov 23, 2023
4c0b49a
assert mass fractions positive.
wkerzendorf Nov 23, 2023
7474e66
update estimators
wkerzendorf Nov 23, 2023
6735fad
add packet collection
wkerzendorf Nov 23, 2023
2135c5a
move spectrum to mct_state
wkerzendorf Nov 23, 2023
8e0de5c
add radiation_field_state
wkerzendorf Nov 23, 2023
ba9cdf6
Merge branch 'restructure/radiation_field' into restructure/transport…
wkerzendorf Nov 23, 2023
8fd5633
Refactor packet initialization in
wkerzendorf Nov 24, 2023
305e89d
Update model_nparray_attrs in test_base.py and fix
wkerzendorf Nov 24, 2023
de63d0f
Fix temperature assertion in
wkerzendorf Nov 24, 2023
0f4608a
Fix Integrator
wkerzendorf Nov 26, 2023
098cc76
Fix SDEC plot for MCTState
wkerzendorf Nov 26, 2023
455a820
Fix variable names in transport module
wkerzendorf Nov 26, 2023
9de8b34
Refactor the to_hdf code.
wkerzendorf Nov 27, 2023
5159c30
Refactor Monte Carlo transport solver
wkerzendorf Nov 27, 2023
fcd34bb
Fix isotope mass fraction typo and t_radiatve duplicate definition
wkerzendorf Nov 27, 2023
1e3a035
Document remove functionality for effective element masses
wkerzendorf Nov 27, 2023
af1f114
Fix variable name in
wkerzendorf Nov 27, 2023
203bae0
Refactor test names and variable names in
wkerzendorf Nov 27, 2023
56aaa8c
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 27, 2023
1f419b6
restructuring montecarlo state
wkerzendorf Nov 28, 2023
2a50667
Refactor gamma ray simulation setup and test
wkerzendorf Nov 29, 2023
b17b7c7
fix gamma ray tests
wkerzendorf Nov 29, 2023
a479cf6
Add model_isotope_time_0 property to abundances
wkerzendorf Nov 29, 2023
6d64b2d
Add test for montecarlo main loop with vpacket
wkerzendorf Nov 29, 2023
b92158d
Refactor config_reader and config_validator
wkerzendorf Nov 29, 2023
e56ddcc
Fix model_isotope_time_0 property in
wkerzendorf Nov 29, 2023
29fa091
Refactor simulation module to use pathlib
wkerzendorf Nov 29, 2023
8dff14e
remove bad comment and refactor with ruff
wkerzendorf Nov 29, 2023
fcb5dba
Fix variable name in test_simulation_state_mass()
wkerzendorf Nov 29, 2023
7da18f3
Fix unit conversion in calculate_cell_masses
wkerzendorf Nov 29, 2023
1bb7266
Fix logger debug message in CSV reader and update
wkerzendorf Nov 29, 2023
821f4ce
black formatting
wkerzendorf Nov 29, 2023
2257093
Refactor code to use composition variable in
wkerzendorf Nov 29, 2023
e105e71
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 30, 2023
75840d3
Refactor imports in atom_web_download.py and
wkerzendorf Nov 30, 2023
59d5eff
fix for documentation not builiding
wkerzendorf Dec 4, 2023
1f65771
add fix for model_isotope_time_0
wkerzendorf Dec 4, 2023
dd6ba4f
fix grid test
wkerzendorf Dec 4, 2023
5391968
restructure the grid
wkerzendorf Dec 4, 2023
9706437
final change
wkerzendorf Dec 4, 2023
512d737
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Dec 4, 2023
c6d3a59
add stuff
wkerzendorf Dec 4, 2023
d9a191c
add vpacket_log
wkerzendorf Dec 4, 2023
ee4e6c6
transfer over to VPacketCollection constructor
wkerzendorf Dec 4, 2023
b31561e
Refactor model_reader.py and shell_info.py
wkerzendorf Dec 4, 2023
f438ec3
Update damping constants and variable names
wkerzendorf Dec 4, 2023
e7acaac
Refactor vpacket tracking in montecarlo_radial1d
wkerzendorf Dec 4, 2023
ef8cf30
fix w in several places in tardis
wkerzendorf Dec 4, 2023
361e0b7
slowly fixing radiation_field changes
wkerzendorf Dec 4, 2023
bfcf19a
fixing montecarlo tests
wkerzendorf Dec 4, 2023
d5cb35d
Merge remote-tracking branch 'origin/restructure/radiation_field' int…
wkerzendorf Dec 4, 2023
ca4b267
slowly fixing vpacket_tracker
wkerzendorf Dec 4, 2023
6244535
last fix
wkerzendorf Dec 4, 2023
3c8f3da
change hdf from model to simulation_state
wkerzendorf Dec 4, 2023
815b0d8
fixing model->simulation-state
wkerzendorf Dec 4, 2023
5925f6e
Merge remote-tracking branch 'upstream/master' into restructure/radia…
wkerzendorf Dec 4, 2023
81ebd21
Fix model_reader.py imports and formatting issues
wkerzendorf Dec 4, 2023
e24f1fa
Refactor variable names for clarity and
wkerzendorf Dec 4, 2023
50d3ec3
Update variable names in model.ipynb
wkerzendorf Dec 4, 2023
566d279
Update variable name for average temperature
wkerzendorf Dec 4, 2023
f068e64
Merge branch 'restructure/radiation_field' into restructure/transport…
wkerzendorf Dec 5, 2023
86a4974
Fix file paths in test_grid.py, test_base.py,
wkerzendorf Dec 5, 2023
145a9fc
Fix transport dictionary comparison
wkerzendorf Dec 5, 2023
871b849
Merge branch 'restructure/radiation_field' into tests/regression_data
wkerzendorf Dec 7, 2023
eb0e055
Implement regression data configurations
wkerzendorf Dec 9, 2023
d0c26dd
Refactor snapshot fixtures and add regression data
wkerzendorf Dec 9, 2023
67236a4
Update to new testing framework
wkerzendorf Dec 10, 2023
5e04422
Merge remote-tracking branch 'origin/restructure/radiation_field' int…
wkerzendorf Dec 10, 2023
e18bfe0
Refactor imports and fixtures in conftest.py and
wkerzendorf Dec 10, 2023
a68a006
Make regression-data optional
wkerzendorf Dec 10, 2023
f219356
Fix regression data synchronization in plasma
wkerzendorf Dec 10, 2023
a949f49
Refactor variable names in model reader and
wkerzendorf Dec 10, 2023
56a948d
Refactor store_model_to_hdf to
wkerzendorf Dec 10, 2023
2e6caac
Refactor HDF file handling and model reader
wkerzendorf Dec 11, 2023
1cc8004
add docstr
wkerzendorf Dec 11, 2023
e5dedcc
Merge branch 'restructure/radiation_field' into tests/regression_data
wkerzendorf Dec 11, 2023
537e7d3
Merge branch 'tests/regression_data' into restructure/transport_solver
wkerzendorf Dec 11, 2023
051a62b
Merge branch 'restructure/transport_solver' into restructure/separate…
wkerzendorf Dec 11, 2023
0044907
Merge remote-tracking branch 'upstream/master' into tests/regression_…
wkerzendorf Dec 11, 2023
f1151c3
Remove syrupy_extensions.py
wkerzendorf Dec 11, 2023
c85d64e
Refactor code and remove unused imports and
wkerzendorf Dec 14, 2023
dc1cffe
Merge remote-tracking branch 'upstream/master' into restructure/trans…
wkerzendorf Dec 15, 2023
5a902a4
Fix test_base and test_simulation
wkerzendorf Dec 15, 2023
a7c1c1e
Merge branch 'restructure/transport_solver' into restructure/separate…
wkerzendorf Dec 15, 2023
b0e6eac
setting up regression with github actions
wkerzendorf Dec 15, 2023
6cc25b7
Update LFS cache IDs for refdata and regression
wkerzendorf Dec 16, 2023
ccf0a99
Fix test_montecarlo_radial1d function
wkerzendorf Dec 16, 2023
71f1317
Update sync_hdf_store method in RegressionData class
wkerzendorf Dec 16, 2023
0a1ae4a
Refactor test_base.py for improved accuracy and precision
wkerzendorf Dec 16, 2023
74cf7a2
update docstrings
wkerzendorf Dec 16, 2023
173b0f0
Merge branch 'tests/regression_data' into restructure/transport_solver
wkerzendorf Dec 16, 2023
57d4055
Refactor transport state access in test_base.py
wkerzendorf Dec 20, 2023
fb09b33
Fix warnings and add HDF output in sdec_plot.ipynb and cleanup regres…
wkerzendorf Dec 20, 2023
3e86d61
Update demo.hdf file
wkerzendorf Dec 21, 2023
c9c9ee0
Fix negative values in last_interaction_types
wkerzendorf Dec 24, 2023
69e85cf
Update URL for atomic data repository
wkerzendorf Dec 24, 2023
8c7759a
Refactor code for improved readability and maintainability
wkerzendorf Dec 24, 2023
a0a23a0
Refactor code to remove unnecessary array conversion
wkerzendorf Dec 24, 2023
5ff5432
Refactor code to remove unnecessary conversion to numpy array in test…
wkerzendorf Dec 24, 2023
16afba3
Merge branch 'tests/regression_data' into restructure/transport_solver
wkerzendorf Dec 24, 2023
e541eb2
Merge branch 'restructure/transport_solver' into restructure/separate…
wkerzendorf Dec 24, 2023
829d609
Refactor vpacket tracking in montecarlo_main_loop
wkerzendorf Dec 26, 2023
a49c259
Update packet_collection and vpacket_tracker
wkerzendorf Dec 29, 2023
45eb023
fixup of code
wkerzendorf Dec 30, 2023
0c36b9b
Add packet functionality to VPacketCollection
wkerzendorf Dec 30, 2023
c1137e0
ruffify test_sdec_plot
wkerzendorf Dec 30, 2023
2261b1b
Update estimator_statistics module
wkerzendorf Dec 31, 2023
70a2dc5
Add bound-free estimator utility functions and classes
wkerzendorf Dec 31, 2023
458ee16
Work ongoing
wkerzendorf Jan 4, 2024
77897f4
ongoing work
wkerzendorf Jan 4, 2024
2565b9e
ongoing work
wkerzendorf Jan 4, 2024
cc3f04a
Merge remote-tracking branch 'upstream/pr/2469' into restructure/esti…
wkerzendorf Jan 4, 2024
f9cddad
Update code in various files
wkerzendorf Jan 4, 2024
de6ccc8
Fix photo ion calculation and radiation field intensity calculation
wkerzendorf Jan 5, 2024
d233bfd
Co-authored-by: Christian Vogl <cvogl@mpa-garching.mpg.de>
wkerzendorf Jan 5, 2024
af9c4a2
Delete unused files and workspace configuration
wkerzendorf Jan 5, 2024
214f9e5
Add Visual Studio Code workspace file to .gitignore
wkerzendorf Jan 5, 2024
97683a8
Remove unused import in parse_input.py
wkerzendorf Jan 6, 2024
0cceb79
Update VPACKET_TAU_RUSSIAN constant
wkerzendorf Jan 6, 2024
ca18310
Refactor montecarlo_main_loop and FormalIntegrator classes
wkerzendorf Jan 6, 2024
984a1a2
Merge branch 'restructure/separate_transport_state' into restructure/…
wkerzendorf Jan 6, 2024
813376c
Fix import statement in base.py
wkerzendorf Jan 6, 2024
c7581b8
Merge branch 'restructure/separate_transport_state' into restructure/…
wkerzendorf Jan 6, 2024
6b4b490
Add import statement for radfield_mc_estimators
wkerzendorf Jan 6, 2024
fb9c8cd
add new solvers
wkerzendorf Jan 12, 2024
0064c8c
Merge branch 'master' into pr/2500
andrewfullard Jan 22, 2024
1235772
Fix most tests
andrewfullard Jan 22, 2024
c32312a
Remove unused util
andrewfullard Jan 29, 2024
aa15361
Fixes downbranch tests
andrewfullard Jan 29, 2024
105cfbe
Fix plasma continuum test name
andrewfullard Jan 29, 2024
b2a384f
Fix excess quantity in RPacket definition
andrewfullard Jan 29, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ pip-wheel-metadata/

# Mac OSX
.DS_Store

# Visual Studio Code
*.code-workspace
1 change: 1 addition & 0 deletions astropy_helpers
Submodule astropy_helpers added at 9f82aa
4 changes: 2 additions & 2 deletions docs/physics/update_and_conv/update_and_conv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
},
"outputs": [],
"source": [
"j_estimator = transport.transport_state.estimators.j_estimator * (u.erg * u.cm) \n",
"j_estimator = transport.transport_state.j_estimator * (u.erg * u.cm) \n",
"j_estimator"
]
},
Expand All @@ -324,7 +324,7 @@
},
"outputs": [],
"source": [
"nu_bar_estimator = transport.transport_state.estimators.nu_bar_estimator * (u.erg * u.cm * u.Hz)\n",
"nu_bar_estimator = transport.transport_state.nu_bar_estimator * (u.erg * u.cm * u.Hz)\n",
"nu_bar_estimator"
]
},
Expand Down
2 changes: 1 addition & 1 deletion tardis/energy_input/tests/test_energy_source.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import numpy as np
import numpy.testing as npt
import pytest

from tardis.energy_input.samplers import (
create_energy_cdf,
Expand Down
116 changes: 100 additions & 16 deletions tardis/io/atom_data/base.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# atomic model


import logging
from collections import OrderedDict

import numpy as np
import pandas as pd

from scipy import interpolate
from collections import OrderedDict
from astropy import units as u
from tardis import constants as const
from astropy.units import Quantity
from scipy import interpolate

from tardis import constants as const
from tardis.io.atom_data.util import resolve_atom_data_fname
from tardis.plasma.properties.continuum_processes import (
get_ground_state_multi_index,
)


class AtomDataNotPreparedError(Exception):
Expand All @@ -24,7 +25,7 @@ class AtomDataMissingError(Exception):
logger = logging.getLogger(__name__)


class AtomData(object):
class AtomData:
"""
Class for storing atomic data

Expand Down Expand Up @@ -167,7 +168,6 @@ def from_hdf(cls, fname=None):
Path to the HDFStore file or name of known atom data file
(default: None)
"""

dataframes = dict()
nonavailable = list()

Expand Down Expand Up @@ -208,7 +208,7 @@ def from_hdf(cls, fname=None):
"Atomic Data Collisions Not a Valid Chanti or CMFGEN Carsus Data File"
)
except KeyError as e:
logger.warn(
logger.warning(
"Atomic Data is not a Valid Carsus Atomic Data File"
)
raise
Expand Down Expand Up @@ -253,7 +253,7 @@ def from_hdf(cls, fname=None):
)
atom_data.version = None

# ToDo: strore data sources as attributes in carsus
# TODO: strore data sources as attributes in carsus

logger.info(
f"Reading Atom Data with: UUID = {atom_data.uuid1} MD5 = {atom_data.md5} "
Expand Down Expand Up @@ -373,8 +373,9 @@ def _check_related(self):
def prepare_atom_data(
self,
selected_atomic_numbers,
line_interaction_type="scatter",
nlte_species=[],
line_interaction_type,
nlte_species,
continuum_interaction_species,
):
"""
Prepares the atom data to set the lines, levels and if requested macro
Expand Down Expand Up @@ -437,6 +438,84 @@ def prepare_atom_data(
.values
)

self.prepare_macro_atom_data(
line_interaction_type,
tmp_lines_lower2level_idx,
tmp_lines_upper2level_idx,
)
if len(continuum_interaction_species) > 0:
self.prepare_continuum_interaction_data(
continuum_interaction_species
)

self.nlte_data = NLTEData(self, nlte_species)

def prepare_continuum_interaction_data(self, continuum_interaction_species):
"""
Prepares the atom data for the continuum interaction

Parameters
----------
continuum_interaction : ContinuumInteraction
The continuum interaction object
"""
# photoionization_data = atomic_data.photoionization_data.set_index(
# ["atomic_number", "ion_number", "level_number"]
# )
mask_selected_species = self.photoionization_data.index.droplevel(
"level_number"
).isin(continuum_interaction_species)
self.photoionization_data = self.photoionization_data[
mask_selected_species
]
self.photo_ion_block_references = np.pad(
self.photoionization_data.nu.groupby(level=[0, 1, 2])
.count()
.values.cumsum(),
[1, 0],
)
self.photo_ion_unique_index = self.photoionization_data.index.unique()
self.nu_ion_threshold = (
self.photoionization_data.groupby(level=[0, 1, 2]).first().nu
)
self.energy_photo_ion_lower_level = self.levels.loc[
self.photo_ion_unique_index
].energy

source_idx = self.macro_atom_references.loc[
self.photo_ion_unique_index
].references_idx
destination_idx = self.macro_atom_references.loc[
get_ground_state_multi_index(self.photo_ion_unique_index)
].references_idx
self.photo_ion_levels_idx = pd.DataFrame(
{
"source_level_idx": source_idx.values,
"destination_level_idx": destination_idx.values,
},
index=self.photo_ion_unique_index,
)

self.level2continuum_edge_idx = pd.Series(
np.arange(len(self.nu_ion_threshold)),
self.nu_ion_threshold.sort_values(ascending=False).index,
name="continuum_idx",
)

level_idxs2continuum_idx = self.photo_ion_levels_idx.copy()
level_idxs2continuum_idx[
"continuum_idx"
] = self.level2continuum_edge_idx
self.level_idxs2continuum_idx = level_idxs2continuum_idx.set_index(
["source_level_idx", "destination_level_idx"]
)

def prepare_macro_atom_data(
self,
line_interaction_type,
tmp_lines_lower2level_idx,
tmp_lines_upper2level_idx,
):
if (
self.macro_atom_data_all is not None
and not line_interaction_type == "scatter"
Expand Down Expand Up @@ -505,6 +584,13 @@ def prepare_atom_data(
)

if line_interaction_type == "macroatom":
self.lines_lower2macro_reference_idx = (
self.macro_atom_references.loc[
tmp_lines_lower2level_idx, "references_idx"
]
.astype(np.int64)
.values
)
# Sets all
tmp_macro_destination_level_idx = pd.MultiIndex.from_arrays(
[
Expand Down Expand Up @@ -548,8 +634,6 @@ def prepare_atom_data(
self.selected_atomic_numbers, level=0
)

self.nlte_data = NLTEData(self, nlte_species)

def _check_selected_atomic_numbers(self):
selected_atomic_numbers = self.selected_atomic_numbers
available_atomic_numbers = np.unique(
Expand All @@ -571,7 +655,7 @@ def __repr__(self):
return f"<Atomic Data UUID={self.uuid1} MD5={self.md5} Lines={self.lines.line_id.count():d} Levels={self.levels.energy.count():d}>"


class NLTEData(object):
class NLTEData:
def __init__(self, atom_data, nlte_species):
self.atom_data = atom_data
self.lines = atom_data.lines.reset_index()
Expand Down
7 changes: 6 additions & 1 deletion tardis/io/tests/test_atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def test_atom_data_lines(lines):


def test_atomic_reprepare(kurucz_atomic_data):
kurucz_atomic_data.prepare_atom_data([14, 20])
kurucz_atomic_data.prepare_atom_data(
[14, 20],
line_interaction_type="scatter",
nlte_species=[],
continuum_interaction_species=[],
)
lines = kurucz_atomic_data.lines.reset_index()
assert lines["atomic_number"].isin([14, 20]).all()
assert len(lines.loc[lines["atomic_number"] == 14]) > 0
Expand Down
4 changes: 3 additions & 1 deletion tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
parse_packet_source,
)
from tardis.montecarlo.packet_source import BlackBodySimpleSource
from tardis.model.radiation_field_state import DiluteThermalRadiationFieldState
from tardis.model.radiation_field_state import (
DiluteBlackBodyRadiationFieldState,
)
from tardis.util.base import is_valid_nuclide_or_elem

logger = logging.getLogger(__name__)
Expand Down
17 changes: 5 additions & 12 deletions tardis/model/parse_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from tardis.model.geometry.radial1d import HomologousRadial1DGeometry
from tardis.model.matter.composition import Composition
from tardis.model.matter.decay import IsotopicMassFraction
from tardis.model.radiation_field_state import DiluteThermalRadiationFieldState
from tardis.model.radiation_field_state import (
DiluteBlackBodyRadiationFieldState,
)
from tardis.montecarlo.packet_source import (
BlackBodySimpleSource,
BlackBodySimpleSourceRelativistic,
Expand Down Expand Up @@ -572,7 +574,7 @@ def parse_radiation_field_state(
]
assert len(dilution_factor) == geometry.no_of_shells

return DiluteThermalRadiationFieldState(t_radiative, dilution_factor)
return DiluteBlackBodyRadiationFieldState(t_radiative, dilution_factor)


def initialize_packet_source(config, geometry, packet_source):
Expand All @@ -598,14 +600,6 @@ def initialize_packet_source(config, geometry, packet_source):
ValueError
If both t_inner and luminosity_requested are None.
"""
if config.montecarlo.enable_full_relativity:
packet_source = BlackBodySimpleSourceRelativistic(
base_seed=config.montecarlo.seed,
time_explosion=config.supernova.time_explosion,
)
else:
packet_source = BlackBodySimpleSource(base_seed=config.montecarlo.seed)

luminosity_requested = config.supernova.luminosity_requested
if config.plasma.initial_t_inner > 0.0 * u.K:
packet_source.radius = geometry.r_inner[0]
Expand All @@ -620,7 +614,6 @@ def initialize_packet_source(config, geometry, packet_source):
raise ValueError(
"Both t_inner and luminosity_requested cannot be None."
)

return packet_source


Expand Down Expand Up @@ -687,7 +680,7 @@ def parse_csvy_radiation_field_state(
else:
dilution_factor = calculate_geometric_dilution_factor(geometry)

return DiluteThermalRadiationFieldState(t_radiative, dilution_factor)
return DiluteBlackBodyRadiationFieldState(t_radiative, dilution_factor)


def calculate_t_radiative_from_t_inner(geometry, packet_source):
Expand Down
27 changes: 23 additions & 4 deletions tardis/model/radiation_field_state.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from tardis.montecarlo.montecarlo_numba.numba_interface import OpacityState


import numpy as np
from astropy import units as u

from tardis.util.base import intensity_black_body

from typing import Union


class DiluteThermalRadiationFieldState:
class DiluteBlackBodyRadiationFieldState:
"""
Represents the state of a dilute thermal radiation field.

Expand All @@ -30,3 +31,21 @@ def __init__(
assert np.all(dilution_factor > 0)
self.t_radiative = t_radiative
self.dilution_factor = dilution_factor

def calculate_mean_intensity(self, nu: Union[u.Quantity, np.ndarray]):
"""
Calculate the intensity of the radiation field at a given frequency.

Parameters
----------
nu : u.Quantity
Frequency at which the intensity is to be calculated

Returns
-------
intensity : u.Quantity
Intensity of the radiation field at the given frequency
"""
return self.dilution_factor * intensity_black_body(
nu[np.newaxis].T, self.t_radiative
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this transpose happening here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the number of nues vs the number of shells - what comes out is a 2D frame

16 changes: 9 additions & 7 deletions tardis/montecarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
from tardis.io.logger import montecarlo_tracking as mc_tracker
from tardis.io.util import HDFWriterMixin
from tardis.montecarlo import montecarlo_configuration
from tardis.montecarlo.estimators.radfield_mc_estimators import (
initialize_estimator_statistics,
)
from tardis.montecarlo.montecarlo_configuration import (
configuration_initialize,
)
from tardis.montecarlo.montecarlo_numba import (
montecarlo_main_loop,
numba_config,
)
from tardis.montecarlo.montecarlo_numba.estimators import initialize_estimators
from tardis.montecarlo.montecarlo_numba.formal_integral import FormalIntegrator
from tardis.montecarlo.montecarlo_numba.numba_interface import (
NumbaModel,
Expand Down Expand Up @@ -97,8 +99,8 @@ def __init__(
mc_tracker.DEBUG_MODE = debug_packets
mc_tracker.BUFFER = logger_buffer

if self.spectrum_method == "integrated":
self.optional_hdf_properties.append("spectrum_integrated")
# if self.spectrum_method == "integrated":
# self.optional_hdf_properties.append("spectrum_integrated")

def initialize_transport_state(
self,
Expand All @@ -116,7 +118,7 @@ def initialize_transport_state(
packet_collection = self.packet_source.create_packets(
no_of_packets, seed_offset=iteration
)
estimators = initialize_estimators(
estimators = initialize_estimator_statistics(
plasma.tau_sobolevs.shape, gamma_shape
)

Expand Down Expand Up @@ -182,7 +184,7 @@ def run(
transport_state.geometry_state,
numba_model,
transport_state.opacity_state,
transport_state.estimators,
transport_state.radfield_mc_estimators,
transport_state.spectrum_frequency.value,
number_of_vpackets,
iteration=iteration,
Expand Down Expand Up @@ -231,8 +233,8 @@ def legacy_return(self):
return (
self.transport_state.packet_collection.output_nus,
self.transport_state.packet_collection.output_energies,
self.transport_state.estimators.j_estimator,
self.transport_state.estimators.nu_bar_estimator,
self.transport_state.j_estimator,
self.transport_state.nu_bar_estimator,
self.transport_state.last_line_interaction_in_id,
self.transport_state.last_line_interaction_out_id,
self.transport_state.last_interaction_type,
Expand Down
Loading
Loading