Individual-Based Model (IBM) API Reference¶
The IBM module tracks populations of super-individuals with explicit body size, age, energy reserves, and spatial location. Each super-individual represents a cohort of real organisms. The IBM integrates into Ecosim's derivative loop: IBM groups override the standard ODE derivative for their functional group while the rest of the food web runs normally.
See the IBM Parameterization Guide for practical tuning advice.
Base Classes¶
Core data structures: SuperIndividual, IBMGroup (abstract base),
IBMStepResult, and SpatialContext.
pypath.ibm.base ¶
Base data structures for the IBM (Individual-Based Model) module.
Provides the foundational dataclasses and abstract base class used by all IBM group implementations in PyPath. These structures define how individual organisms (super-individuals) are represented and how IBM groups interface with the Ecosim population dynamics engine.
Classes:
| Name | Description |
|---|---|
SuperIndividual |
Represents a cohort of biologically identical organisms. |
IBMStepResult |
Return type for a single IBM integration step. |
IBMGroup |
Abstract base class that all concrete IBM implementations must subclass. |
LifeStage ¶
Bases: IntEnum
Life stage codes used by IBM super-individuals.
Source code in pypath/ibm/base.py
32 33 34 35 36 37 38 39 | |
SuperIndividual
dataclass
¶
A super-individual representing a cohort of identical organisms.
Each super-individual tracks the state of n_represented biologically identical fish (or other organisms). This is the fundamental unit of the IBM module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Unique identifier for this super-individual. |
required |
n_represented
|
float
|
Number of real individuals this super-individual represents. |
required |
weight
|
float
|
Individual body weight (grams). |
required |
length
|
float
|
Individual body length (cm). |
required |
age
|
float
|
Age (years). |
required |
energy_reserve
|
float
|
Energy reserve (grams-equivalent, initialized as weight * 0.1). |
required |
patch_idx
|
int
|
Spatial patch index where this super-individual currently resides. |
required |
is_mature
|
bool
|
Whether this super-individual has reached sexual maturity. |
required |
sex
|
int
|
Sex code (0 = female, 1 = male, or other coding as needed). |
required |
life_stage
|
int
|
Life stage code (0=egg, 1=yolk_sac, 2=larva, 3=juvenile, 4=adult). |
4
|
degree_days
|
float
|
Accumulated thermal development in degree-days (°C·day), egg stage only. |
0.0
|
starvation_days
|
float
|
Consecutive days without sufficient feeding. |
0.0
|
yolk_energy_kj
|
float
|
Yolk energy in kJ (only meaningful for life_stage 0-1). |
0.0
|
Source code in pypath/ibm/base.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
total_biomass_tonnes ¶
total_biomass_tonnes() -> float
Return total biomass represented by this super-individual in tonnes.
Computed as n_represented * weight / 1e6, assuming weight is in
grams and 1 tonne = 1e6 grams.
Returns:
| Type | Description |
|---|---|
float
|
Total biomass in metric tonnes. |
Source code in pypath/ibm/base.py
96 97 98 99 100 101 102 103 104 105 106 107 | |
IBMStepResult
dataclass
¶
Result of a single IBM integration step.
Returned by :meth:IBMGroup.compute_step to communicate the IBM
state back to the Ecosim integration loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
biomass
|
float
|
Total group biomass (tonnes) after this step. |
required |
production
|
float
|
Net production during this step (tonnes). |
required |
consumption_by_prey
|
ndarray
|
1-D array of shape |
required |
mortality_count
|
float
|
Number of individuals that died during this step. |
required |
recruitment_count
|
float
|
Number of new individuals recruited during this step. |
required |
Source code in pypath/ibm/base.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
SpatialContext
dataclass
¶
Spatial data passed to IBM groups during Ecospace simulations.
When an IBM group is part of a spatial simulation, this context provides the patch-level environmental information needed for movement decisions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adjacency
|
Any
|
Sparse adjacency matrix of shape |
required |
habitat_quality
|
ndarray
|
Per-patch habitat quality for this group, shape |
required |
food_density
|
ndarray
|
Per-patch total prey biomass, shape |
required |
predator_density
|
ndarray
|
Per-patch total predator biomass, shape |
required |
n_patches
|
int
|
Number of spatial patches. |
required |
Source code in pypath/ibm/base.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
IBMGroup ¶
Bases: ABC
Abstract base class for IBM group implementations.
Every IBM-managed functional group must subclass IBMGroup and
implement all four abstract methods. The Ecosim integration loop
calls these methods to delegate dynamics to the IBM engine while
keeping the rest of the food-web coupled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_index
|
int
|
One-based index of this group in the Ecopath/Ecosim model (0 is reserved for the "Outside" placeholder). |
required |
n_groups
|
int
|
Total number of functional groups in the model (used to size consumption arrays). |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
group_index |
int
|
One-based index of this group. |
n_groups |
int
|
Total number of groups in the model. |
individuals |
List[SuperIndividual]
|
Population of super-individuals managed by this group. |
Source code in pypath/ibm/base.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
compute_step
abstractmethod
¶
compute_step(prey_available: ndarray, predation_pressure: float, env_forcing: Dict[str, Any], dt: float, spatial_context: Optional['SpatialContext'] = None) -> IBMStepResult
Advance the IBM population by one time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prey_available
|
ndarray
|
1-D array of shape |
required |
predation_pressure
|
float
|
Total predation mortality pressure on this group from other predators in the Ecosim food web. |
required |
env_forcing
|
Dict[str, Any]
|
Dictionary of environmental forcing values (temperature, etc.). |
required |
dt
|
float
|
Time step size (years). |
required |
spatial_context
|
SpatialContext
|
Spatial patch data for Ecospace simulations. When |
None
|
Returns:
| Type | Description |
|---|---|
IBMStepResult
|
Aggregated results of this time step. |
Source code in pypath/ibm/base.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
get_aggregate_biomass
abstractmethod
¶
get_aggregate_biomass() -> float
Return the total biomass (tonnes) of all super-individuals.
Returns:
| Type | Description |
|---|---|
float
|
Sum of biomass across all super-individuals. |
Source code in pypath/ibm/base.py
234 235 236 237 238 239 240 241 242 | |
get_consumption_by_prey
abstractmethod
¶
get_consumption_by_prey() -> np.ndarray
Return the consumption vector by prey group.
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D array of shape |
Source code in pypath/ibm/base.py
244 245 246 247 248 249 250 251 252 253 | |
initialize_from_ecosim
abstractmethod
¶
initialize_from_ecosim(biomass: float, params: Dict[str, Any], n_super_individuals: int = 500) -> None
Initialize the IBM population from Ecosim equilibrium state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
biomass
|
float
|
Initial total biomass (tonnes) from Ecopath. |
required |
params
|
Dict[str, Any]
|
Species-specific biological parameters. |
required |
n_super_individuals
|
int
|
Number of super-individuals to create (default 500). |
500
|
Source code in pypath/ibm/base.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
Bioenergetics¶
Wisconsin bioenergetics model: Q10 temperature scaling, allometric metabolism, assimilation, and growth. Drives individual weight and energy reserve changes each timestep.
Key functions:
growth_step()— single-individual energy budget and weight updategrowth_step_batch()— vectorized batch processing for all individuals (uses NumPy arrays, significantly faster for large populations)q10_temperature_factor()— Q10 temperature scalingmetabolism()— weight-dependent metabolic rate with temperature correctionallometric_length()— weight-to-length conversionBioenergParams— dataclass with all bioenergetics parameters
pypath.ibm.bioenergetics ¶
Wisconsin bioenergetics model for the IBM integration.
Implements the energy-budget approach used to drive individual fish growth in the Individual-Based Model. Each super-individual's weight and energy reserve are updated each timestep based on consumption, metabolism, specific dynamic action (SDA), and (for mature fish) reproduction costs.
The core equation follows the Wisconsin model framework:
net_energy = assimilated_consumption - metabolism - SDA - reproduction_cost
Temperature dependence is modelled with a Q10 formulation, and allometric scaling converts weight to length.
Functions:
| Name | Description |
|---|---|
q10_temperature_factor |
Compute Q10 temperature scaling factor. |
allometric_length |
Convert weight to length using an allometric power law. |
metabolism |
Compute standard metabolic rate. |
assimilation |
Compute assimilated consumption. |
growth_step |
Advance weight and energy reserve by one timestep. |
Classes:
| Name | Description |
|---|---|
BioenergParams |
Dataclass holding all bioenergetics parameters for a species. |
BioenergParams
dataclass
¶
Parameters for the Wisconsin bioenergetics model.
Holds species-specific constants that govern metabolism, assimilation, growth, and reproduction in the IBM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ra
|
float
|
Metabolic rate intercept (g O2 / g fish / day at reference temperature). |
required |
rb
|
float
|
Metabolic rate weight exponent (typically negative, indicating per-gram metabolic rate decreases with body size). |
required |
q10
|
float
|
Q10 temperature coefficient -- the factor by which metabolic rate increases for every 10 degree C rise in temperature. |
required |
t_ref
|
float
|
Reference temperature (degrees C) at which |
required |
sda_fraction
|
float
|
Specific dynamic action fraction (0-1). The proportion of consumption allocated to the energetic cost of digestion. |
required |
unassimilated_fraction
|
float
|
Fraction of consumption that is not assimilated (0-1), i.e. lost as faeces and excretion. |
required |
a_length
|
float
|
Allometric coefficient for the weight-to-length conversion (length = a_length * weight ** b_length). |
required |
b_length
|
float
|
Allometric exponent for the weight-to-length conversion. |
required |
energy_density
|
float
|
Energy content per gram of fish tissue (kJ/g). Used to convert net energy (kJ) to weight change (g). Default is 5.0. |
5.0
|
reproduction_fraction
|
float
|
Fraction of net surplus energy allocated to reproduction when the individual is mature. Default is 0.3. |
0.3
|
Source code in pypath/ibm/bioenergetics.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
q10_temperature_factor ¶
q10_temperature_factor(temp: float, t_ref: float, q10: float) -> float
Compute the Q10 temperature scaling factor.
The Q10 model scales a rate measured at t_ref to a new temperature
temp using the formula:
factor = q10 ** ((temp - t_ref) / 10.0)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp
|
float
|
Current water temperature (degrees C). |
required |
t_ref
|
float
|
Reference temperature (degrees C). |
required |
q10
|
float
|
Q10 coefficient (dimensionless, typically 1.5 -- 3.0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Multiplicative scaling factor (1.0 at |
Source code in pypath/ibm/bioenergetics.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
allometric_length ¶
allometric_length(weight: float, a: float, b: float) -> float
Convert body weight to body length using an allometric power law.
Computes length = a * weight ** b. Returns 0.0 if weight is zero
or negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
Individual body weight (grams). |
required |
a
|
float
|
Allometric coefficient. |
required |
b
|
float
|
Allometric exponent. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Body length (cm), or 0.0 if weight <= 0. |
Source code in pypath/ibm/bioenergetics.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
metabolism ¶
metabolism(weight: float, temperature: float, params: BioenergParams) -> float
Compute the standard metabolic rate for an individual.
Uses the allometric form with Q10 temperature dependence:
rate = ra * weight^rb * q10_factor
The result is in the same units as ra (g O2 / g fish / day) and
represents the per-gram daily metabolic cost scaled for temperature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
Individual body weight (grams). |
required |
temperature
|
float
|
Current water temperature (degrees C). |
required |
params
|
BioenergParams
|
Bioenergetics parameters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Metabolic rate (g O2 / g fish / day, temperature-adjusted). |
Source code in pypath/ibm/bioenergetics.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
assimilation ¶
assimilation(consumption: float, params: BioenergParams) -> float
Compute the assimilated portion of consumption.
Removes the unassimilated fraction (faeces + excretion) from total consumption:
assimilated = consumption * (1 - unassimilated_fraction)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
consumption
|
float
|
Total consumption (energy or mass units). |
required |
params
|
BioenergParams
|
Bioenergetics parameters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Assimilated consumption. |
Source code in pypath/ibm/bioenergetics.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
growth_step ¶
growth_step(weight: float, energy_reserve: float, consumption: float, temperature: float, is_mature: bool, dt: float, params: BioenergParams) -> tuple[float, float]
Advance an individual's weight and energy reserve by one timestep.
Implements the Wisconsin bioenergetics budget for a single integration step. The energy budget is:
assim = assimilation(consumption)
sda = consumption * sda_fraction
met = metabolism(weight, temperature) * dt * 365
net = assim - met - sda
reproduction_cost = net * reproduction_fraction (if mature and net > 0)
weight_change = net / energy_density
The dt * 365 factor converts the daily metabolic rate (ra) to
the appropriate fraction of a year represented by dt.
Surplus energy is added to the energy reserve; deficits drain the reserve first before reducing body weight. Weight is clamped to a minimum of 0.1 grams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
Current individual body weight (grams). |
required |
energy_reserve
|
float
|
Current energy reserve (dimensionless index). |
required |
consumption
|
float
|
Total consumption during this timestep. |
required |
temperature
|
float
|
Current water temperature (degrees C). |
required |
is_mature
|
bool
|
Whether the individual has reached sexual maturity. |
required |
dt
|
float
|
Timestep size (fraction of a year). |
required |
params
|
BioenergParams
|
Bioenergetics parameters. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
Source code in pypath/ibm/bioenergetics.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
growth_step_batch ¶
growth_step_batch(weights: ndarray, energy_reserves: ndarray, consumptions: ndarray, temperature: 'float | np.ndarray', is_mature: ndarray, dt: float, params: BioenergParams) -> tuple[np.ndarray, np.ndarray]
Vectorized growth step for all individuals at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
ndarray
|
Body weights (grams), shape |
required |
energy_reserves
|
ndarray
|
Energy reserves, shape |
required |
consumptions
|
ndarray
|
Total consumption per individual, shape |
required |
temperature
|
float or ndarray
|
Water temperature (degrees C). Scalar or per-individual array. |
required |
is_mature
|
ndarray
|
Boolean array, shape |
required |
dt
|
float
|
Timestep (fraction of a year). |
required |
params
|
BioenergParams
|
Bioenergetics parameters. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
|
Source code in pypath/ibm/bioenergetics.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
thornton_lessem ¶
thornton_lessem(temp: float, CQ: float, CTO: float, CTM: float, CTL: float, CK1: float, CK4: float) -> float
Thornton-Lessem temperature function (Fish Bioenergetics 3.0/4.0).
Produces a dome-shaped temperature response curve widely used in fish bioenergetics models (Thornton & Lessem 1978). The result f(T) ranges from ~CK1 at CQ (cold extreme) to ~0.98 near CTO-CTM (optimum) to ~CK4 at CTL (hot extreme).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp
|
float
|
Current water temperature (degrees C). |
required |
CQ
|
float
|
Lower temperature where rate = CK1 fraction of maximum (~T_min). |
required |
CTO
|
float
|
Temperature where ascending limb reaches 0.98 of max (~T_opt). |
required |
CTM
|
float
|
Temperature where descending limb is still 0.98 of max (> CTO). |
required |
CTL
|
float
|
Upper temperature where rate = CK4 fraction of maximum (~T_max). |
required |
CK1
|
float
|
Small fraction of max at CQ (typically 0.01-0.05). |
required |
CK4
|
float
|
Small fraction of max at CTL (typically 0.01-0.05). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Temperature scaling factor in [0, ~0.98], dome-shaped. |
Source code in pypath/ibm/bioenergetics.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
oxygen_scalar ¶
oxygen_scalar(o2: float, pcrit: float) -> float
Compute oxygen limitation scalar.
Returns 1.0 when dissolved oxygen is at or above the critical threshold
(pcrit), and scales linearly to 0.0 as oxygen approaches zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
o2
|
float
|
Dissolved oxygen concentration (mg/L). |
required |
pcrit
|
float
|
Critical oxygen threshold (mg/L) below which limitation begins. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Oxygen scalar in [0, 1]. |
Source code in pypath/ibm/bioenergetics.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
growth_step_batch_ontogenetic ¶
growth_step_batch_ontogenetic(weights: ndarray, energy_reserves: ndarray, consumptions: ndarray, temperature: 'float | np.ndarray', is_mature: ndarray, dt: float, bioenerg_params: BioenergParams, larval_params: 'LarvalParams') -> tuple[np.ndarray, np.ndarray]
Vectorized growth step with ontogenetic (size-dependent) interpolation.
Extends the Wisconsin bioenergetics model with sigmoid-interpolated
activity multiplier, assimilation efficiency, and basal metabolism split
(Rs + Ra). At large (adult) body sizes the results converge to those of
:func:growth_step_batch when larval_params.rs_a * (1 + am_max) == ra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
ndarray
|
Body weights (grams), shape |
required |
energy_reserves
|
ndarray
|
Energy reserves, shape |
required |
consumptions
|
ndarray
|
Total consumption per individual, shape |
required |
temperature
|
float or ndarray
|
Water temperature (degrees C). Scalar or per-individual array. |
required |
is_mature
|
ndarray
|
Boolean array, shape |
required |
dt
|
float
|
Timestep (fraction of a year). |
required |
bioenerg_params
|
BioenergParams
|
Standard bioenergetics parameters. |
required |
larval_params
|
LarvalParams
|
Ontogenetic interpolation parameters. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
|
Source code in pypath/ibm/bioenergetics.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
Predation¶
Size-structured predation mortality using a log-normal selectivity curve. Distributes Ecosim group-level mortality across super-individuals based on body length.
pypath.ibm.predation ¶
Size-structured predation module for the IBM.
Distributes Ecosim group-level predation mortality across IBM super-individuals based on body size using a log-normal selectivity curve. Larger or smaller fish relative to the optimal prey length experience proportionally less predation pressure, reflecting size-dependent vulnerability to predators.
Functions:
| Name | Description |
|---|---|
size_selectivity |
Log-normal selectivity based on prey body length. |
distribute_mortality |
Allocate group-level mortality across super-individuals. |
apply_predation_mortality |
Apply predation mortality and return surviving individuals. |
Classes:
| Name | Description |
|---|---|
PredationParams |
Dataclass holding size-selectivity parameters. |
PredationParams
dataclass
¶
Parameters for size-structured predation selectivity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimal_prey_length
|
float
|
Prey body length (cm) at which predation selectivity is maximised. |
required |
selectivity_sd
|
float
|
Standard deviation of the log-normal selectivity curve (in log-space units). Larger values yield a flatter curve. |
required |
Source code in pypath/ibm/predation.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
size_selectivity ¶
size_selectivity(length: float, params: PredationParams) -> float
Compute log-normal size selectivity for a given prey length.
The selectivity peaks at 1.0 when length equals
params.optimal_prey_length and decays symmetrically in log-space
as the prey deviates from the optimal size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
Body length of the prey (cm). |
required |
params
|
PredationParams
|
Predation selectivity parameters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Selectivity value in [0.0, 1.0]. Returns 0.0 if length <= 0. |
Source code in pypath/ibm/predation.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
distribute_mortality ¶
distribute_mortality(individuals: List[SuperIndividual], total_mortality_rate: float, dt: float, params: PredationParams) -> List[float]
Distribute group-level mortality across super-individuals by size.
Deaths are allocated proportionally to each individual's
selectivity-weighted abundance (n_represented * selectivity).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
List[SuperIndividual]
|
Current population of super-individuals. |
required |
total_mortality_rate
|
float
|
Annual mortality rate for the functional group (yr^-1). |
required |
dt
|
float
|
Time-step size (years). |
required |
params
|
PredationParams
|
Size-selectivity parameters. |
required |
Returns:
| Type | Description |
|---|---|
List[float]
|
Number of deaths for each super-individual. Each entry is
capped at the individual's |
Source code in pypath/ibm/predation.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
apply_predation_mortality ¶
apply_predation_mortality(individuals: List[SuperIndividual], total_mortality_rate: float, dt: float, params: PredationParams) -> List[SuperIndividual]
Apply predation mortality and return surviving super-individuals.
Creates shallow copies of the input individuals, reduces their
n_represented by the allocated deaths, and removes any
individual whose n_represented drops to zero or below.
The original individuals list is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
List[SuperIndividual]
|
Current population of super-individuals (not modified). |
required |
total_mortality_rate
|
float
|
Annual mortality rate for the functional group (yr^-1). |
required |
dt
|
float
|
Time-step size (years). |
required |
params
|
PredationParams
|
Size-selectivity parameters. |
required |
Returns:
| Type | Description |
|---|---|
List[SuperIndividual]
|
Surviving super-individuals with updated |
Source code in pypath/ibm/predation.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
Reproduction¶
Stochastic spawning with weight-dependent fecundity and Cushing match/mismatch larval survival. Mature females produce eggs; surviving larvae become new recruit super-individuals.
pypath.ibm.reproduction ¶
Stochastic reproduction module for the IBM.
Implements spawning, fecundity calculation, and the Cushing match/mismatch hypothesis for larval survival in Baltic smelt. Mature females produce eggs proportional to body weight, and larval survival depends on the temporal overlap between hatching and zooplankton peak abundance.
Functions:
| Name | Description |
|---|---|
calculate_fecundity |
Weight-dependent egg production per female. |
larval_survival_probability |
Gaussian match/mismatch survival for larvae. |
spawn |
Determine total egg production for a super-individual. |
create_recruits |
Create new super-individual recruits from surviving larvae. |
Classes:
| Name | Description |
|---|---|
ReproductionParams |
Dataclass holding reproduction and larval survival parameters. |
ReproductionParams
dataclass
¶
Parameters for stochastic reproduction and larval survival.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fecundity_coefficient
|
float
|
Coefficient in the fecundity-weight relationship (eggs = coefficient * weight ^ exponent). |
required |
fecundity_exponent
|
float
|
Exponent in the fecundity-weight relationship. |
required |
larval_base_survival
|
float
|
Base survival probability at perfect match (0-1). |
required |
zooplankton_match_window
|
float
|
Width of the Gaussian match/mismatch window (days). |
required |
maturity_energy_threshold
|
float
|
Minimum energy reserve (kJ) required for spawning. |
required |
spawning_temp_threshold
|
float
|
Minimum water temperature (C) for spawning to occur. |
required |
larval_duration_days
|
int
|
Duration of the larval phase (days). |
required |
recruit_weight
|
float
|
Body weight (g) of a newly recruited individual. |
required |
recruit_length
|
float
|
Body length (cm) of a newly recruited individual. |
required |
Source code in pypath/ibm/reproduction.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
calculate_fecundity ¶
calculate_fecundity(weight: float, params: ReproductionParams) -> float
Calculate egg production for a single female of a given weight.
Uses a power-law relationship: eggs = coefficient * weight ^ exponent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
Individual body weight (g). |
required |
params
|
ReproductionParams
|
Reproduction parameters containing fecundity coefficient and exponent. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Number of eggs produced. Returns 0.0 if weight <= 0. |
Source code in pypath/ibm/reproduction.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
larval_survival_probability ¶
larval_survival_probability(spawn_day: float, zoo_peak_day: float, params: ReproductionParams) -> float
Compute larval survival probability using the Cushing match/mismatch hypothesis.
Survival follows a Gaussian function of the temporal mismatch between spawning and the zooplankton peak:
survival = base_survival * exp(-0.5 * (mismatch / match_window)^2)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spawn_day
|
float
|
Day of year when spawning occurs. |
required |
zoo_peak_day
|
float
|
Day of year of the zooplankton abundance peak. |
required |
params
|
ReproductionParams
|
Reproduction parameters containing base survival and match window. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Survival probability in (0, base_survival]. |
Source code in pypath/ibm/reproduction.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
spawn ¶
spawn(individual: SuperIndividual, temperature: float, params: ReproductionParams) -> float
Determine total egg production for a super-individual.
Only mature females (is_mature=True, sex=0) spawn, and only
when temperature and energy reserves meet the required thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
SuperIndividual
|
The super-individual attempting to spawn. |
required |
temperature
|
float
|
Current water temperature (C). |
required |
params
|
ReproductionParams
|
Reproduction parameters. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total number of eggs produced (n_represented * fecundity_per_female). Returns 0.0 if spawning conditions are not met. |
Source code in pypath/ibm/reproduction.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
create_recruits ¶
create_recruits(total_eggs: float, spawn_day: float, zoo_peak_day: float, patch_idx: int, next_id: int, params: ReproductionParams, n_super_individuals: int = 1) -> List[SuperIndividual]
Create new super-individual recruits from surviving larvae.
Calculates the number of surviving larvae using
:func:larval_survival_probability, then distributes the survivors
evenly across n_super_individuals new :class:SuperIndividual
objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_eggs
|
float
|
Total number of eggs produced. |
required |
spawn_day
|
float
|
Day of year when spawning occurred. |
required |
zoo_peak_day
|
float
|
Day of year of the zooplankton abundance peak. |
required |
patch_idx
|
int
|
Spatial patch index where recruits are placed. |
required |
next_id
|
int
|
Starting ID for the new super-individuals. |
required |
params
|
ReproductionParams
|
Reproduction parameters. |
required |
n_super_individuals
|
int
|
Number of super-individuals to create (default 1). |
1
|
Returns:
| Type | Description |
|---|---|
List[SuperIndividual]
|
New recruit super-individuals. Empty list if total survivors < 1. |
Source code in pypath/ibm/reproduction.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
Behavior (Spatial Movement & Adaptive Foraging)¶
Score-based stochastic patch selection over a sparse adjacency graph, plus profitability-based adaptive prey allocation.
pypath.ibm.behavior ¶
Behavior module for the IBM: spatial movement and adaptive foraging.
Handles two key behaviors for IBM super-individuals:
-
Spatial movement between ECOSPACE patches, using a weighted score of habitat quality, food density, and predator avoidance to compute movement probabilities across a sparse adjacency graph.
-
Adaptive foraging (prey selection), where super-individuals allocate consumption proportionally to prey profitability while respecting availability constraints.
Functions:
| Name | Description |
|---|---|
calculate_movement_probabilities |
Compute per-patch movement probabilities for a super-individual. |
move_individual |
Move a super-individual to a new patch based on movement probabilities. |
should_migrate |
Determine whether migration conditions are met. |
adaptive_forage |
Allocate consumption across prey groups by profitability. |
Classes:
| Name | Description |
|---|---|
MovementParams |
Dataclass holding spatial movement parameters. |
ForagingParams |
Dataclass holding adaptive foraging parameters. |
MovementParams
dataclass
¶
Parameters controlling spatial movement between patches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_speed
|
float
|
Base movement probability scaling (0-1). Low values increase the inertia bonus, making the individual more likely to stay. |
required |
habitat_weight
|
float
|
Weight for habitat quality in the movement score (0-1). |
required |
food_weight
|
float
|
Weight for food density in the movement score (0-1). |
required |
predator_weight
|
float
|
Weight for predator avoidance in the movement score (0-1). |
required |
migration_temp_threshold
|
float
|
Temperature (degrees C) above which spring migration can occur. |
required |
migration_months
|
tuple
|
Months (1-12) during which migration can occur. |
(3, 4, 5)
|
Source code in pypath/ibm/behavior.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
ForagingParams
dataclass
¶
Parameters controlling adaptive prey selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
energy_content
|
ndarray
|
Energy per gram of each prey group (kJ/g). Shape |
required |
handling_time
|
ndarray
|
Handling time per gram of each prey group. Shape |
required |
Source code in pypath/ibm/behavior.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
calculate_movement_probabilities ¶
calculate_movement_probabilities(current_patch: int, adjacency: csr_matrix, habitat_quality: ndarray, food_density: ndarray, predator_density: ndarray, params: MovementParams) -> np.ndarray
Compute per-patch movement probabilities for a super-individual.
For each reachable patch (current patch plus its neighbors in the sparse adjacency matrix), a weighted score is computed as:
score = habitat_weight * habitat_quality
+ food_weight * food_density
+ predator_weight * (1 / (1 + predator_density))
The current patch receives an inertia bonus proportional to
(1 - base_speed), making the individual more sedentary when
base_speed is low.
Scores are normalized to probabilities summing to 1.0. If all scores are zero, the individual stays in its current patch with probability 1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_patch
|
int
|
Index of the patch currently occupied. |
required |
adjacency
|
csr_matrix
|
Sparse adjacency matrix (n_patches x n_patches). |
required |
habitat_quality
|
ndarray
|
Per-patch habitat quality, shape |
required |
food_density
|
ndarray
|
Per-patch food density, shape |
required |
predator_density
|
ndarray
|
Per-patch predator density, shape |
required |
params
|
MovementParams
|
Movement parameters. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Probability array of shape |
Source code in pypath/ibm/behavior.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
move_individual ¶
move_individual(individual: SuperIndividual, adjacency: csr_matrix, habitat_quality: ndarray, food_density: ndarray, predator_density: ndarray, params: MovementParams, rng: Optional[Generator] = None) -> SuperIndividual
Move a super-individual to a new patch based on movement probabilities.
Computes movement probabilities via :func:calculate_movement_probabilities
and uses np.random.choice (or the supplied RNG) to select a destination
patch. Returns a copy of the individual with updated patch_idx; the
original is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
SuperIndividual
|
The super-individual to move. |
required |
adjacency
|
csr_matrix
|
Sparse adjacency matrix. |
required |
habitat_quality
|
ndarray
|
Per-patch habitat quality. |
required |
food_density
|
ndarray
|
Per-patch food density. |
required |
predator_density
|
ndarray
|
Per-patch predator density. |
required |
params
|
MovementParams
|
Movement parameters. |
required |
rng
|
Generator
|
Random number generator. If |
None
|
Returns:
| Type | Description |
|---|---|
SuperIndividual
|
A copy with potentially updated |
Source code in pypath/ibm/behavior.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
should_migrate ¶
should_migrate(temperature: float, month: int, params: MovementParams) -> bool
Determine whether migration conditions are met.
Migration occurs when the temperature is strictly above the threshold and the current month is in the configured migration months.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
float
|
Current water temperature (degrees C). |
required |
month
|
int
|
Current month (1-12). |
required |
params
|
MovementParams
|
Movement parameters containing threshold and migration months. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if migration conditions are met. |
Source code in pypath/ibm/behavior.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
adaptive_forage ¶
adaptive_forage(prey_available: Dict[int, float], max_consumption: float, individual_length: float, params: ForagingParams) -> Dict[int, float]
Allocate consumption across prey groups by profitability.
Profitability of each prey group is defined as:
profitability = (energy_content / handling_time) * availability
Consumption is allocated proportionally to profitability, subject to availability constraints (cannot eat more than available for any group). When a group is availability-constrained, the surplus is redistributed to the remaining groups in a second pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prey_available
|
Dict[int, float]
|
Available biomass per prey group index. |
required |
max_consumption
|
float
|
Maximum total consumption for this individual. |
required |
individual_length
|
float
|
Body length of the individual (cm). Currently unused but reserved for future size-dependent foraging selectivity. |
required |
params
|
ForagingParams
|
Foraging parameters. |
required |
Returns:
| Type | Description |
|---|---|
Dict[int, float]
|
Consumption by prey group index. |
Source code in pypath/ibm/behavior.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
EwE Integration¶
Bridge between the IBM and Ecosim/Ecospace derivative systems.
apply_ibm_to_derivative() overrides the Ecosim derivative for IBM
groups and subtracts IBM consumption from prey derivatives.
pypath.ibm.integration ¶
IBM-Ecosim derivative override integration.
Provides the bridge functions that allow IBM-managed functional groups to override the standard Ecosim derivative calculation. When an IBM group is active, these functions extract the relevant food-web data from the Ecosim consumption matrix, delegate the dynamics to the IBM engine, and write the results back into the derivative vector.
Functions:
| Name | Description |
|---|---|
extract_prey_availability |
Extract non-zero prey consumption rates for a given predator. |
extract_predation_pressure |
Sum total predation on a given prey from all living predators. |
check_ibm_mass_balance |
Validate that an IBM step result is physically plausible. |
apply_ibm_to_derivative |
Override the Ecosim derivative for an IBM group in-place. |
extract_prey_availability ¶
extract_prey_availability(QQ: ndarray, predator_idx: int, n_groups: int) -> Dict[int, float]
Extract non-zero prey consumption rates for a predator.
Reads column predator_idx of the consumption matrix QQ and
returns a dictionary mapping each prey index to its consumption rate,
excluding entries that are exactly zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
QQ
|
ndarray
|
Consumption matrix of shape |
required |
predator_idx
|
int
|
1-based index of the predator group. |
required |
n_groups
|
int
|
Total number of functional groups (excluding the 0-index padding). |
required |
Returns:
| Type | Description |
|---|---|
Dict[int, float]
|
Mapping |
Source code in pypath/ibm/integration.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
extract_predation_pressure ¶
extract_predation_pressure(QQ: ndarray, prey_idx: int, n_living: int) -> float
Sum total predation on a prey group from all living predators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
QQ
|
ndarray
|
Consumption matrix of shape |
required |
prey_idx
|
int
|
1-based index of the prey group. |
required |
n_living
|
int
|
Number of living groups in the model. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Sum of |
Source code in pypath/ibm/integration.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
check_ibm_mass_balance ¶
check_ibm_mass_balance(result: 'IBMStepResult', tolerance: float = 0.05) -> Tuple[bool, float]
Validate that an IBM step result is physically plausible.
Checks that biomass is non-negative and that no consumption entry is negative. The relative error returned is the magnitude of the largest violation (or 0.0 if none).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
IBMStepResult
|
The result from an IBM integration step. |
required |
tolerance
|
float
|
Maximum acceptable relative error (default 0.05). |
0.05
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, float]
|
|
Source code in pypath/ibm/integration.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
apply_ibm_to_derivative ¶
apply_ibm_to_derivative(deriv: ndarray, QQ: ndarray, BB: ndarray, ibm_group: 'IBMGroup', forcing: dict, dt: float, spatial_context: Optional['SpatialContext'] = None) -> None
Override the Ecosim derivative for an IBM-managed group in-place.
Calls the IBM group's compute_step method with prey availability
and predation pressure extracted from the current Ecosim state, then
writes the resulting biomass change into the derivative vector and
subtracts IBM consumption from prey derivatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deriv
|
ndarray
|
Derivative vector (modified in-place). Shape |
required |
QQ
|
ndarray
|
Consumption matrix |
required |
BB
|
ndarray
|
Current biomass vector |
required |
ibm_group
|
IBMGroup
|
The IBM group instance that will compute the step. |
required |
forcing
|
dict
|
Environmental forcing dictionary passed through to |
required |
dt
|
float
|
Time step size in years. |
required |
spatial_context
|
SpatialContext or None
|
Spatial context for multi-patch IBM movement. When provided, it is
forwarded to |
None
|
Source code in pypath/ibm/integration.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
Smelt Implementation¶
Concrete IBMGroup implementation for Baltic smelt (Osmerus eperlanus),
combining all sub-modules into a 5-phase compute_step(). Use as a
template for building custom IBM species.
pypath.ibm.smelt ¶
SmeltIBM concrete implementation for Baltic smelt (Osmerus eperlanus).
Orchestrates all IBM behavior modules -- bioenergetics, predation, foraging, reproduction, and growth -- into a single cohesive IBM group that can be injected into the Ecosim derivative loop.
The SmeltIBM is initialized from Ecopath equilibrium biomass and creates an age-structured population of super-individuals using Von Bertalanffy growth curves. Each time step, it runs up to five phases:
- Forage + Grow: adaptive foraging followed by Wisconsin bioenergetics.
- Reproduce: mature females spawn; surviving larvae become recruits.
- Predation mortality: size-structured mortality from Ecosim predators.
- Bookkeeping: add recruits, age individuals, remove senescent fish.
- Spatial movement (optional): move individuals between patches.
Classes:
| Name | Description |
|---|---|
SmeltParams |
Composite parameter dataclass combining all IBM sub-module parameters. |
SmeltIBM |
Concrete IBMGroup implementation for Baltic smelt. |
SmeltParams
dataclass
¶
Composite parameters for the SmeltIBM.
Combines all sub-module parameter sets plus species-specific Von Bertalanffy growth parameters for Baltic smelt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bioenerg
|
BioenergParams
|
Wisconsin bioenergetics model parameters. |
required |
predation
|
PredationParams
|
Size-structured predation selectivity parameters. |
required |
foraging
|
ForagingParams
|
Adaptive prey-selection parameters. |
required |
movement
|
MovementParams
|
Spatial movement parameters. |
required |
reproduction
|
ReproductionParams
|
Spawning and larval survival parameters. |
required |
vbgf_k_mean
|
float
|
Mean Von Bertalanffy growth coefficient K (yr^-1). |
0.3
|
vbgf_k_sd
|
float
|
Standard deviation of K across individuals. |
0.05
|
vbgf_linf_mean
|
float
|
Mean asymptotic body length Linf (cm). |
25.0
|
vbgf_linf_sd
|
float
|
Standard deviation of Linf across individuals. |
3.0
|
max_age
|
float
|
Maximum age (years) before natural senescence removal. |
10.0
|
Source code in pypath/ibm/smelt.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
baltic_defaults
classmethod
¶
baltic_defaults() -> 'SmeltParams'
Return default parameters for Baltic smelt (Osmerus eperlanus).
These are literature-based defaults suitable for the Baltic Sea ecosystem. All sub-parameter sets are populated with species- specific values.
Returns:
| Type | Description |
|---|---|
SmeltParams
|
Fully populated parameter object. |
Source code in pypath/ibm/smelt.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
baltic_defaults_els
classmethod
¶
baltic_defaults_els() -> 'SmeltParams'
Return Baltic smelt defaults with early life stages enabled.
Creates a standard baltic_defaults() parameter set and adds
default EggParams, YolkSacParams, LarvalParams, and OxygenParams
for mechanistic egg-to-larva modeling.
Returns:
| Type | Description |
|---|---|
SmeltParams
|
Fully populated parameter object with ELS enabled. |
Source code in pypath/ibm/smelt.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
baltic_defaults_zonal
classmethod
¶
baltic_defaults_zonal() -> 'SmeltParams'
Return Baltic smelt defaults with ELS and zonal model enabled.
Creates a baltic_defaults_els() parameter set and adds default
ZoneParams for the 3-zone Curonian Lagoon spatial model.
Returns:
| Type | Description |
|---|---|
SmeltParams
|
Fully populated parameter object with ELS + zones enabled. |
Source code in pypath/ibm/smelt.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
SmeltIBM ¶
Bases: IBMGroup
Concrete IBM group implementation for Baltic smelt.
Orchestrates bioenergetics, predation, foraging, and reproduction modules for an age-structured population of super-individuals representing Osmerus eperlanus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_index
|
int
|
One-based index of this group in the Ecopath/Ecosim model (0 is reserved for the "Outside" placeholder). |
required |
n_groups
|
int
|
Total number of functional groups in the model. |
required |
params
|
SmeltParams
|
Species-specific parameters for all IBM sub-modules. |
required |
Source code in pypath/ibm/smelt.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
initialize_from_ecosim ¶
initialize_from_ecosim(biomass: float, params: Dict[str, Any], n_super_individuals: int = 500) -> None
Initialize an age-structured population from Ecosim equilibrium.
Creates n_super_individuals super-individuals with ages
distributed from 0.5 to max_age. Lengths are computed from the
Von Bertalanffy growth function, weights from inverse allometry,
and n_represented from an exponential survival curve scaled
so that total biomass matches the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
biomass
|
float
|
Initial total biomass (tonnes) from Ecopath. |
required |
params
|
Dict[str, Any]
|
Additional species-specific parameters (currently unused;
all parameters come from |
required |
n_super_individuals
|
int
|
Number of super-individuals to create (default 500). |
500
|
Source code in pypath/ibm/smelt.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
get_aggregate_biomass ¶
get_aggregate_biomass() -> float
Return total biomass (tonnes) across all super-individuals.
Returns:
| Type | Description |
|---|---|
float
|
Sum of |
Source code in pypath/ibm/smelt.py
364 365 366 367 368 369 370 371 372 | |
get_consumption_by_prey ¶
get_consumption_by_prey() -> np.ndarray
Return the consumption vector from the last time step.
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D array of shape |
Source code in pypath/ibm/smelt.py
374 375 376 377 378 379 380 381 382 383 | |
compute_step ¶
compute_step(prey_available: ndarray, predation_pressure: float, env_forcing: Dict[str, Any], dt: float, spatial_context: Optional[SpatialContext] = None) -> IBMStepResult
Advance the SmeltIBM population by one time step.
Executes up to five phases:
- Forage + Grow: For each individual, compute adaptive foraging allocation, then update weight and energy via bioenergetics.
- Reproduce: Mature females spawn; surviving larvae create recruits.
- Predation mortality: Apply size-structured predation.
- Bookkeeping: Age individuals, add recruits, remove senescent fish.
- Spatial movement (optional): Move individuals between patches when a spatial context is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prey_available
|
ndarray
|
1-D array of shape |
required |
predation_pressure
|
float
|
Total predation mortality rate on this group (yr^-1). |
required |
env_forcing
|
Dict[str, Any]
|
Environmental forcing with keys like |
required |
dt
|
float
|
Time step size (fraction of a year). |
required |
spatial_context
|
SpatialContext
|
Spatial patch data for Ecospace simulations. When |
None
|
Returns:
| Type | Description |
|---|---|
IBMStepResult
|
Aggregated results of this time step. |
Source code in pypath/ibm/smelt.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |