tardis.spectrum.base module

class tardis.spectrum.base.SpectrumSolver(*args: Any, **kwargs: Any)[source]

Bases: HDFWriterMixin

Initialize the spectrum solver.

Parameters:
transport_stateMonteCarloTransportState or MonteCarloTransportStateNonhomologous, optional

Transport state used to compute the real-packet spectra.

spectrum_frequency_gridastropy.units.Quantity

Frequency-bin edges for the real- and virtual-packet histograms.

integrator_settingsConfigurationNameSpace, optional

Formal integral settings.

virtual_packet_loggingbool, optional

Keep the escaping virtual packets in vpacket_tracker.

vpacket_spawn_start_frequencyastropy.units.Quantity, optional

Lowest real-packet frequency that spawns virtual packets.

vpacket_spawn_end_frequencyastropy.units.Quantity, optional

Highest real-packet frequency that spawns virtual packets.

vpacket_tau_russianfloat, optional

Optical depth above which virtual packets survive based on vpacket_survival_probability.

vpacket_survival_probabilityfloat, optional

Probability that a vpacket_tau_russian virtual packet survives.

classmethod from_config(config)[source]
get_properties() → dict[str, Any][source]

Get properties for HDF storage, adding logged virtual packets.

Returns:
dict

Property names and values; includes vpacket_tracker_df when virtual packets were logged.

hdf_name = 'spectrum'
hdf_properties = ['montecarlo_virtual_luminosity', 'spectrum_real_packets', 'spectrum_virtual_packets', 'spectrum_real_packets_reabsorbed', 'spectrum_integrated']
property integrator
property montecarlo_emitted_luminosity
property montecarlo_reabsorbed_luminosity
property montecarlo_virtual_luminosity
setup_optional_spectra(transport_state: MonteCarloTransportState | MonteCarloTransportStateNonhomologous, integrator: FormalIntegralSolver | None = None, simulation_state: SimulationState | None = None, transport: MCTransportSolverClassic | MCTransportSolverNonhomologous | None = None, plasma: BasePlasma | None = None, opacity_state: OpacityState | None = None, macro_atom_state: LegacyMacroAtomState | MacroAtomState | None = None) → None[source]

Set up the solver to compute the integrated spectrum

Parameters:
transport_stateMonteCarloTransportState or MonteCarloTransportStateNonhomologous

Transport state used to compute the spectra.

integratorFormalIntegratorSolver, optional

Integrator used to compute the integrated spectrum.

simulation_stateSimulationState, optional

Final simulation state.

transportMCTransportSolverClassic or MCTransportSolverNonhomologous, optional

Completed transport solver used by the formal integral.

plasmaBasePlasma, optional

Final plasma state.

opacity_stateOpacityState, optional

Final opacity state.

macro_atom_stateLegacyMacroAtomState or MacroAtomState, optional

Final macro-atom state.

solve(transport_state)[source]

Solve the spectra

Parameters:
transport_state: MonteCarloTransportState

The transport state to be used to compute the spectra

Returns:
tuple(TARDISSpectrum)

Real, virtual and integrated spectra, if available

solve_virtual_packet_spectrum(transport_state: MonteCarloTransportState | MonteCarloTransportStateNonhomologous, montecarlo_configuration: MonteCarloConfiguration, tracker_full_df: DataFrame | None, number_of_vpackets: int) → None[source]

Compute the virtual spectrum from full real-packet histories.

Parameters:
transport_stateMonteCarloTransportState or MonteCarloTransportStateNonhomologous

Completed classic or non-homologous transport state.

montecarlo_configurationMonteCarloConfiguration

Configuration used for the completed transport calculation.

tracker_full_dfpandas.DataFrame or None

Full real-packet histories of the completed transport, e.g. transport_state.tracker_full_df or one loaded from disk. Must include the next_line_id column.

number_of_vpacketsint

Number of virtual packets spawned per real-packet interaction. Must be positive.

Raises:
ValueError

If number_of_vpackets is not positive, or the full real-packet histories are missing or lack a needed column.

TypeError

If transport_state is not a classic or non-homologous state.

property spectrum_integrated
property spectrum_real_packets
property spectrum_real_packets_reabsorbed
property spectrum_virtual_packets
vpacket_tracker_to_df(last_interaction_type: ArrayLike | None = None) → DataFrame[source]

Convert the logged virtual packets to a DataFrame.

The interaction columns share their names and dtypes with the real-packet tracker_last_interaction_df; each row describes the real-packet event that spawned the virtual packet.

Parameters:
last_interaction_typearray-like, optional

Interaction type column to use instead of categorical interaction type names. Used for HDF output, which cannot store categoricals.

Returns:
pandas.DataFrame

One row per escaping virtual packet, indexed by vpacket_id, with columns last_interaction_type, radius, shell_id, before_nu, line_absorb_id and line_emit_id for the spawning event, and nus, energies, initial_mus and initial_rs for the virtual packet.

Raises:
ValueError

If no virtual packets were logged.