seapopym.function.compiled_functions package
Submodules
seapopym.function.compiled_functions.biomass_compiled_functions module
This module contains the compiled (JIT) functions used by the biomass generator.
- seapopym.function.compiled_functions.biomass_compiled_functions.biomass_sequence(recruited: ndarray, mortality: ndarray, initial_conditions: ndarray | None) ndarray
Compute the biomass of the recruited individuals.
- Formula :
B(t) = R(t) + (M(t) * B(t-1))
Parameters
- recruitednp.ndarray
The number of recruited individuals. Minimum dims : (F, T, <Y, X, …>). Type : np.float64
- mortalitynp.ndarray
The mortality rate of the recruited individuals. Minimum dims : (F, T, <Y, X, …>). Type : np.float64
- initial_conditionsnp.ndarray
The initial biomass. Minimum dims : (F, <Y, X, …>). Type : np.float64 If None, the initial biomass is set to np.zeros(recruited[:, 0, …].shape).
Warning
Be sure to use floats for the input arrays.
seapopym.function.compiled_functions.production_compiled_functions module
This module contains the compiled (JIT) functions used by the production generator.
- seapopym.function.compiled_functions.production_compiled_functions.ageing(production: ndarray, nb_timestep_by_cohort: ndarray) ndarray
Age production across cohorts by transferring fractions to next age classes.
Implements cohort aging by moving a fraction of production from each cohort to the next age class. The transfer fraction is 1/nb_timestep_by_cohort, representing the proportion that graduates to the next cohort at each timestep. The remaining production stays in the current cohort.
Parameters
- productionnp.ndarray
Production data to age across cohorts. Shape: […, Cohort] where last dimension represents age classes.
- nb_timestep_by_cohortnp.ndarray
Number of timesteps each cohort spans before aging to the next. Shape: [Cohort]. Higher values mean slower aging.
Returns
- aged_productionnp.ndarray
Production after aging process, same shape as input. Each cohort contains: staying production + incoming production from younger cohort.
Notes
The last (oldest) cohort receives transfers but doesn’t transfer out
Transfer coefficient = 1.0 / nb_timestep_by_cohort[cohort]
First cohort only receives new production (no incoming transfers)
- seapopym.function.compiled_functions.production_compiled_functions.expand_dims(data: ndarray, dim_len: int) ndarray
Expand array with a new cohort dimension, initializing first cohort with input data.
Creates a new array with an additional dimension of length dim_len representing cohorts. The input data is placed in the first cohort (index 0), while all other cohorts are initialized to zero. This is used to convert primary production data into cohort-structured data for age-based modeling.
Parameters
- datanp.ndarray
Input data to expand, typically primary production for a single timestep. Shape: [X, Y] (spatial dimensions)
- dim_lenint
Length of the new cohort dimension to add.
Returns
- expanded_datanp.ndarray
Expanded data with new cohort dimension. Shape: [X, Y, Cohort] where Cohort has length dim_len
Notes
Only the first cohort (index 0) contains the input data. All other cohorts are initialized to 0.0.
- seapopym.function.compiled_functions.production_compiled_functions.production(primary_production: ndarray, mask_temperature: ndarray, timestep_number: ndarray, initial_production: ndarray | None = None) ndarray
Compute total recruited production from primary production with cohort aging.
Simulates production recruitment over time by processing primary production through cohort-based aging dynamics. At each timestep, production either gets recruited (based on recruitment mask) or ages into older cohorts. The function returns the total recruited production summed across all cohorts.
Parameters
- primary_productionnp.ndarray
Input primary production for each timestep. Shape: [T, X, Y] where T is time, X, Y are spatial dimensions.
- mask_temperaturenp.ndarray
Recruitment mask determining when production can be recruited. Shape: [T, X, Y, Cohort]. True values allow recruitment.
- timestep_numbernp.ndarray
Number of timesteps each cohort spans. Shape: [Cohort]. Controls aging rate between cohorts.
- initial_productionnp.ndarray | None, default=None
Pre-existing production in cohorts from previous simulation. Shape: [X, Y, Cohort]. If None, starts with zero initial conditions.
Returns
- total_recruitednp.ndarray
Total recruited production summed across all cohorts. Shape: [T, X, Y].
Notes
This version stores full cohort data during computation then sums at the end. For memory-optimized computation, use production_space_optimized.
- seapopym.function.compiled_functions.production_compiled_functions.production_export_initial(primary_production: ndarray, mask_temperature: ndarray, timestep_number: ndarray, initial_production: ndarray | None = None) tuple[ndarray, ndarray]
Compute recruited production and export final pre-production state for continuity.
Performs the same recruitment calculation as production but additionally returns the unrecruited production state at the end of the simulation. This final state can be used as initial conditions for subsequent simulation runs, enabling seamless chaining of simulations.
Parameters
- primary_productionnp.ndarray
Input primary production for each timestep. Shape: [T, X, Y] where T is time, X, Y are spatial dimensions.
- mask_temperaturenp.ndarray
Recruitment mask determining when production can be recruited. Shape: [T, X, Y, Cohort]. True values allow recruitment.
- timestep_numbernp.ndarray
Number of timesteps each cohort spans. Shape: [Cohort]. Controls aging rate between cohorts.
- initial_productionnp.ndarray | None, default=None
Pre-existing production in cohorts from previous simulation. Shape: [X, Y, Cohort]. If None, starts with zero initial conditions.
Returns
- total_recruitednp.ndarray
Total recruited production summed across all cohorts. Shape: [T, X, Y].
- final_preproductionnp.ndarray
Unrecruited production state at the end of the simulation. Shape: [X, Y, Cohort]. Can be used as initial_production for next run.
Notes
The final pre-production state contains production that accumulated but wasn’t recruited by the end of the simulation. This is essential for simulation continuity when running multi-year simulations in chunks.
- seapopym.function.compiled_functions.production_compiled_functions.production_export_preproduction(primary_production: ndarray, mask_temperature: ndarray, timestep_number: ndarray, initial_production: ndarray | None = None) tuple[ndarray, ndarray]
Compute recruited production and export full pre-production time series.
Performs recruitment calculation while tracking and exporting the complete pre-production (unrecruited) state at every timestep. This provides detailed diagnostic information about production dynamics, including cohort-specific accumulation and aging processes throughout the simulation.
Parameters
- primary_productionnp.ndarray
Input primary production for each timestep. Shape: [T, X, Y] where T is time, X, Y are spatial dimensions.
- mask_temperaturenp.ndarray
Recruitment mask determining when production can be recruited. Shape: [T, X, Y, Cohort]. True values allow recruitment.
- timestep_numbernp.ndarray
Number of timesteps each cohort spans. Shape: [Cohort]. Controls aging rate between cohorts.
- initial_productionnp.ndarray | None, default=None
Pre-existing production in cohorts from previous simulation. Shape: [X, Y, Cohort]. If None, starts with zero initial conditions.
Returns
- total_recruitednp.ndarray
Total recruited production summed across all cohorts. Shape: [T, X, Y].
- preproduction_timeseriesnp.ndarray
Complete pre-production state for all timesteps and cohorts. Shape: [T, X, Y, Cohort]. Includes final aged state at last timestep.
Notes
Memory intensive: stores full [T, X, Y, Cohort] pre-production data
Useful for detailed analysis of recruitment timing and cohort dynamics
The last timestep contains the final aged pre-production state
- seapopym.function.compiled_functions.production_compiled_functions.production_space_optimized(primary_production: ndarray, mask_temperature: ndarray, timestep_number: ndarray, initial_production: ndarray | None = None) ndarray
Memory-optimized computation of total recruited production with cohort aging.
Performs the same calculation as production but with reduced memory footprint. Instead of storing full cohort data then summing, this function computes the cohort sum at each timestep, reducing memory usage by a factor equal to the number of cohorts.
Parameters
- primary_productionnp.ndarray
Input primary production for each timestep. Shape: [T, X, Y] where T is time, X, Y are spatial dimensions.
- mask_temperaturenp.ndarray
Recruitment mask determining when production can be recruited. Shape: [T, X, Y, Cohort]. True values allow recruitment.
- timestep_numbernp.ndarray
Number of timesteps each cohort spans. Shape: [Cohort]. Controls aging rate between cohorts.
- initial_productionnp.ndarray | None, default=None
Pre-existing production in cohorts from previous simulation. Shape: [X, Y, Cohort]. If None, starts with zero initial conditions.
Returns
- total_recruitednp.ndarray
Total recruited production summed across all cohorts. Shape: [T, X, Y].
Notes
Memory usage: O(T*X*Y) instead of O(T*X*Y*Cohort)
Performance: Slightly faster due to immediate summation and better cache usage
Functionally equivalent to production but more memory efficient