Deterministic Compartment Model
- radcomp.solve_dcm_from_toml(filepath: str, t_eval: ndarray, prelayer: Prelayer | None = None, voiding_rules: list[radcomp.common.voiding.VoidingRule] | None = None) DetCompModelSol
Solve a deterministic compartment model from a TOML configuration file (except for a possible prelayer).
For more information about the model or how to format the TOML file, see https://github.com/jakeforster/radcomp/blob/main/README.md.
- Parameters:
filepath (str) – Filepath to TOML configuration file.
t_eval (np.ndarray) – Times (h) at which to solve the model. Must be sorted (ascending). Note the first element is the beginning of the integration period.
prelayer (Optional[Prelayer]) – Input time-activity curves for a nuclide that is able to transition to one or more layers in the model.
voiding_rules (Optional[list[VoidingRule]]) – Rules for voiding nuclei from compartments.
- Returns:
Solution for the model.
- Return type:
- radcomp.solve_dcm(trans_rates: ndarray, branching_fracs: ndarray, xfer_coeffs: ndarray, initial_nuclei: ndarray, t_eval: ndarray, prelayer: Prelayer | None = None, layer_names: list[str] | None = None, compartment_names: list[str] | None = None, voiding_rules: list[radcomp.common.voiding.VoidingRule] | None = None) DetCompModelSol
Solve a deterministic compartment model.
For more information about the model, see https://github.com/jakeforster/radcomp/blob/main/README.md.
- Parameters:
trans_rates (numpy.ndarray) – Transition rates (h-1) of nuclides in layers. Shape (
num_layers,).branching_fracs (numpy.ndarray) – Branching fractions (0 to 1). Shape (
num_layers,num_layers). Element [i, j] is for layer j to layer i.xfer_coeffs (numpy.ndarray) – Transfer coefficients (h-1) between compartments. Shape (
num_layers,num_compartments,num_compartments). Element [i, j, k] is for compartment k to compartment j in layer i.initial_nuclei (numpy.ndarray) – Number of nuclei in each compartment in each layer at first element of
t_eval. Shape (num_layers,num_compartments). Element [i, j] is for layer i, compartment j.t_eval (numpy.ndarray) – Times (h) at which to solve the model. Must be sorted (ascending). Note the first element is the beginning of the integration period.
prelayer (Optional[Prelayer]) – Input time-activity curves for a nuclide that is able to transition to one or more layers in the model.
layer_names (Optional[list[str]]) – Names of layers in model.
compartment_names (Optional[list[str]]) – Names of compartments in model.
voiding_rules (Optional[list[VoidingRule]]) – Rules for voiding nuclei from compartments.
- Returns:
Solution for the model.
- Return type:
- class radcomp.DetCompModelSol(trans_rates: ndarray, branching_fracs: ndarray, xfer_coeffs: ndarray, t_eval: ndarray, prelayer: Prelayer | None, layer_names: list[str] | None, compartment_names: list[str] | None, num_layers: int, num_compartments: int, nuclei: ndarray, voided_nuclei: list[numpy.ndarray])
Bases:
objectHolds the solution for a deterministic compartment model.
Provides some convenient functions to inspect the model and its solution.
NB. Users should not create an instance of this class directly; use the functions
solve_dcm()orsolve_dcm_from_toml()to get an instance.- Parameters:
trans_rates (numpy.ndarray) – Transition rates (h-1) of nuclides in layers. Shape (
num_layers,).branching_fracs (numpy.ndarray) – Branching fractions (0 to 1). Shape (
num_layers,num_layers). Element [i, j] is for layer j to layer i.xfer_coeffs (numpy.ndarray) – Transfer coefficients (h-1) between compartments. Shape (
num_layers,num_compartments,num_compartments). Element [i, j, k] is for compartment k to compartment j in layer i.t_eval (numpy.ndarray) – Times (h) at which to solve the model. Must be sorted (ascending).
prelayer (Prelayer | None) – Input time-activity curves for a nuclide that is able to transition to one or more layers in the model.
layer_names (list[str] | None) – Names of layers in model. Length
num_layers.compartment_names (list[str] | None) – Names of compartments in model. Length
num_compartments.num_layers (int) – Number of layers in model (excluding any prelayer).
num_compartments (int) – Number of compartments in model.
nuclei (numpy.ndarray) – Shape (
num_layers,num_compartments, len(t_eval)). The solution. Element [i, j, k] is the number of nuclei in layer i, compartment j at element k oft_eval.voided_nuclei (list[numpy.ndarray]) – Element i is a 3D array containing the number of nuclei voided due to the ith voiding rule. This 3D array has shape (number of voiding times in ith voiding rule,
num_layers,num_compartments). See alsovoided_activity().
- activity() ndarray
Activities (MBq) at times in
t_eval.- Returns:
Shape (
num_layers,num_compartments, len(t_eval)). Element at index [i, j, k] is the activtiy (MBq) in layer i, compartment j at element k oft_eval.- Return type:
numpy.ndarray
- branching_fracs: ndarray
- compartment_names: list[str] | None
- cumulated_activity(t_start: float | None = None, t_end: float | None = None) ndarray
Cumulated activity (MBq h) during
t_eval.Note result is sensitive to choice of
t_eval.- Parameters:
t_start (Optional[float]) – Start time (h) of integration. Default is start of
t_eval.t_end (Optional[float]) – End time (h) of integration. Default is end of
t_eval.
- Returns:
Shape (
num_layers,num_compartments). Element at index [i, j] is the cumulated activity (MBq h) in layer i, compartment j fromt_starttot_end.- Return type:
numpy.ndarray
- halflife() ndarray
Half-lives (h) of nuclides in layers.
Stable nuclides are assigned a half-life of numpy.inf.
- Returns:
Shape (
num_layers,). Element at index i is the half-life (h) of nuclide in layer i.- Return type:
numpy.ndarray
- info_growth() str
Get information about the growth of nuclides in layers.
- Returns:
Information.
- Return type:
str
- info_xfer() str
Get information about transfer coefficients between compartments.
- Returns:
Information.
- Return type:
str
- layer_names: list[str] | None
- nuclei: ndarray
- num_compartments: int
- num_layers: int
- plot() None
Produce plots of time-activity curves or time-nuclei curves.
- save_arrays(filepath: str) None
Save the solution to npz file.
The saved arrays
t_eval,nuclei, and the return ofactivity(). The functionread_arrays()can be used to read an npz file created using this method.- Parameters:
filepath (str) – Filepath of npz file to be created. Must end with “.npz”.
- t_eval: ndarray
- trans_rates: ndarray
- voided_activity()
Activities (MBq) voided due to voiding rules.
See also
voided_nuclei.- Returns:
Element i is a 3D array containing the activity (MBq) voided due to the ith voiding rule. This 3D array has shape (number of voiding times in voiding rule i,
num_layers,num_compartments).- Return type:
list[numpy.ndarray]
- voided_nuclei: list[numpy.ndarray]
- xfer_coeffs: ndarray