Skip to content

Commit

Permalink
Fixes packet source re-init for custom sources
Browse files Browse the repository at this point in the history
Also adjusts notebook to deal with quantity-based packet frequencies
  • Loading branch information
andrewfullard committed Jun 12, 2024
1 parent 850ded4 commit 3164f60
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
3 changes: 1 addition & 2 deletions docs/io/optional/how_to_custom_source.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
" truncation_frequency = (\n",
" u.Quantity(self.truncation_wavelength, u.Angstrom)\n",
" .to(u.Hz, equivalencies=u.spectral())\n",
" .value\n",
" )\n",
"\n",
" # Draw nus from blackbody distribution and reject based on truncation_frequency.\n",
Expand Down Expand Up @@ -220,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
21 changes: 2 additions & 19 deletions tardis/io/model/parse_packet_source_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
)


def initialize_packet_source(
config, geometry, packet_source, legacy_mode_enabled
):
def initialize_packet_source(packet_source, config, geometry):
"""
Initialize the packet source based on config and geometry
Expand All @@ -31,18 +29,6 @@ def initialize_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,
legacy_mode_enabled=legacy_mode_enabled,
)
else:
packet_source = BlackBodySimpleSource(
base_seed=config.montecarlo.seed,
legacy_mode_enabled=legacy_mode_enabled,
)

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

return packet_source


Expand Down Expand Up @@ -89,6 +74,4 @@ def parse_packet_source_from_config(config, geometry, legacy_mode_enabled):
legacy_mode_enabled=legacy_mode_enabled,
)

return initialize_packet_source(
config, geometry, packet_source, legacy_mode_enabled
)
return initialize_packet_source(packet_source, config, geometry)
4 changes: 3 additions & 1 deletion tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ def from_config(cls, config, atom_data, legacy_mode_enabled=False):

geometry = parse_geometry_from_config(config, time_explosion)

composition, electron_densities = parse_composition_from_config(atom_data, config, time_explosion, geometry)
composition, electron_densities = parse_composition_from_config(
atom_data, config, time_explosion, geometry
)

packet_source = parse_packet_source_from_config(
config, geometry, legacy_mode_enabled
Expand Down
6 changes: 2 additions & 4 deletions tardis/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,10 @@ def from_config(
atom_data=atom_data,
legacy_mode_enabled=legacy_mode_enabled,
)
# Override with custom packet source from function argument if present
if packet_source is not None:
simulation_state.packet_source = initialize_packet_source(
config,
simulation_state.geometry,
packet_source,
legacy_mode_enabled,
packet_source, config, simulation_state.geometry
)
if "plasma" in kwargs:
plasma = kwargs["plasma"]
Expand Down

0 comments on commit 3164f60

Please sign in to comment.