MizerParams
MizerParams(_r_obj, _env)Python wrapper around an R MizerParams object.
MizerParams is the main model-configuration object in mizer. In Python it acts as the starting point for running projections and inspecting the initial state of a model.
Examples
Create a small community model and inspect its initial biomass:
import pymizer as mz
params = mz.new_community_params(no_w=20)
biomass = params.biomass()Attributes
| Name | Description |
|---|---|
| r | Access the underlying R object. |
Methods
| Name | Description |
|---|---|
| abundance | Return species abundance in the initial state. |
| biomass | Return species biomass in the initial state. |
| community_slope | Return the fitted community size-spectrum slope in the initial state. |
| copy | Return another wrapper for the same underlying object. |
| diet | Return diet composition in the initial state. |
| feeding_level | Return feeding level in the initial state. |
| growth_curves | Return species growth curves as a pandas DataFrame. |
| initial_n | Return the initial fish abundance density spectrum. |
| initial_n_resource | Return the initial resource spectrum. |
| interaction_matrix | Return the species interaction matrix. |
| maturity | Return the maturity ogive by species and size. |
| max_intake_rate | Return maximum intake rate by species and size. |
| mean_max_weight | Return the mean maximum weight in the initial state. |
| mean_weight | Return the mean community weight in the initial state. |
| metabolic_rate | Return metabolic rate by species and size. |
| metadata | Return model metadata as nested Python structures. |
| pred_kernel | Return the predation kernel by predator species, predator size, and prey size. |
| pred_mort | Return predation mortality in the initial state. |
| pred_rate | Return predation rate by predator species and prey size. |
| project | Run mizer::project() and return a wrapped simulation result. |
| project_to_steady | Run mizer::projectToSteady(). |
| proportion_of_large_fish | Return the proportion of large fish in the initial state. |
| rate_functions | Return the registered R rate-function names from params@rates_funcs. |
| save | Save the params object using saveParams(). |
| save_rds | Serialise the wrapped params object as a generic .rds file. |
| search_volume | Return search volume by species and size. |
| set_fishing | Call setFishing() and wrap the returned params object. |
| set_initial_values | Return a new params object with initial values copied from a simulation. |
| set_interaction | Return a new params object with an updated interaction matrix. |
| set_max_intake_rate | Return a new params object with updated maximum intake rate. |
| set_metabolic_rate | Return a new params object with updated metabolic rate. |
| set_metadata | Return a new params object with updated metadata. |
| set_pred_kernel | Return a new params object with an updated predation kernel. |
| set_rate_functions | Return a new params object with selected rates_funcs entries updated. |
| set_reproduction | Return a new params object with updated reproduction settings. |
| set_resource | Return a new params object with updated resource settings. |
| set_search_volume | Return a new params object with updated search volume. |
| ssb | Return spawning stock biomass in the initial state as a pandas Series. |
| steady | Run mizer::steady() and return params or a simulation. |
| steady_single_species | Run mizer::steadySingleSpecies() for selected species. |
| summary | Return the text representation of summary(params). |
| trophic_level | Return trophic level at size in the initial state. |
| trophic_level_by_species | Return the species-level trophic level in the initial state. |
abundance
MizerParams.abundance(min_w=None, max_w=None, min_l=None, max_l=None)Return species abundance in the initial state.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| min_w | float | list[float] | None | Minimum weight filter. | None |
| max_w | float | list[float] | None | Maximum weight filter. | None |
| min_l | float | list[float] | None | Minimum length filter. | None |
| max_l | float | list[float] | None | Maximum length filter. | None |
Returns
| Name | Type | Description |
|---|---|---|
| pd.Series | A pandas.Series indexed by species name. |
biomass
MizerParams.biomass(
use_cutoff=False,
min_w=None,
max_w=None,
min_l=None,
max_l=None,
)Return species biomass in the initial state.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| use_cutoff | bool | Use the biomass_cutoff species parameter when available. |
False |
| min_w | float | list[float] | None | Minimum weight filter. | None |
| max_w | float | list[float] | None | Maximum weight filter. | None |
| min_l | float | list[float] | None | Minimum length filter. | None |
| max_l | float | list[float] | None | Maximum length filter. | None |
Returns
| Name | Type | Description |
|---|---|---|
| pd.Series | A pandas.Series indexed by species name. |
Examples
biomass = params.biomass(min_w=10, max_w=1000)community_slope
MizerParams.community_slope(
species=None,
biomass=True,
min_w=None,
max_w=None,
min_l=None,
max_l=None,
)Return the fitted community size-spectrum slope in the initial state.
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | A one-row pandas.DataFrame with slope, intercept, and |
|
| pd.DataFrame | r2 columns. |
copy
MizerParams.copy()Return another wrapper for the same underlying object.
diet
MizerParams.diet(proportion=True, as_xarray=True)Return diet composition in the initial state.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| proportion | bool | If True, normalise prey contributions to proportions. |
True |
| as_xarray | bool | When True, return an xarray.DataArray with dimensions ("predator", "w", "prey"). |
True |
feeding_level
MizerParams.feeding_level(as_xarray=True)Return feeding level in the initial state.
growth_curves
MizerParams.growth_curves(species=None, max_age=20, percentage=False)Return species growth curves as a pandas DataFrame.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| species | str | list[str] | tuple[str, …] | None | Optional species subset. | None |
| max_age | float | Maximum age to evaluate. | 20 |
| percentage | bool | Return size as a percentage of w_max. |
False |
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | A pandas.DataFrame indexed by species with age values as |
|
| pd.DataFrame | columns. |
initial_n
MizerParams.initial_n(as_xarray=True)Return the initial fish abundance density spectrum.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| as_xarray | bool | When True, return an xarray.DataArray with dimensions ("sp", "w"). Otherwise return a NumPy array. |
True |
Examples
initial_n = params.initial_n()
cod = initial_n.sel(sp="Cod")initial_n_resource
MizerParams.initial_n_resource()Return the initial resource spectrum.
Returns
| Name | Type | Description |
|---|---|---|
| pd.Series | A pandas.Series indexed by resource size. |
interaction_matrix
MizerParams.interaction_matrix()Return the species interaction matrix.
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | A pandas.DataFrame indexed by predator species with prey species |
|
| pd.DataFrame | as columns. |
maturity
MizerParams.maturity(as_xarray=True)Return the maturity ogive by species and size.
max_intake_rate
MizerParams.max_intake_rate(as_xarray=True)Return maximum intake rate by species and size.
mean_max_weight
MizerParams.mean_max_weight(
measure='both',
*,
species=None,
min_w=None,
max_w=None,
min_l=None,
max_l=None,
)Return the mean maximum weight in the initial state.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| measure | str | One of "both", "numbers", or "biomass". |
'both' |
| species | str | list[str] | tuple[str, …] | None | Optional species subset. | None |
| min_w | float | list[float] | None | Minimum weight filter. | None |
| max_w | float | list[float] | None | Maximum weight filter. | None |
| min_l | float | list[float] | None | Minimum length filter. | None |
| max_l | float | list[float] | None | Maximum length filter. | None |
mean_weight
MizerParams.mean_weight(
species=None,
min_w=None,
max_w=None,
min_l=None,
max_l=None,
)Return the mean community weight in the initial state.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| species | str | list[str] | tuple[str, …] | None | Optional species subset. | None |
| min_w | float | list[float] | None | Minimum weight filter. | None |
| max_w | float | list[float] | None | Maximum weight filter. | None |
| min_l | float | list[float] | None | Minimum length filter. | None |
| max_l | float | list[float] | None | Maximum length filter. | None |
metabolic_rate
MizerParams.metabolic_rate(as_xarray=True)Return metabolic rate by species and size.
metadata
MizerParams.metadata()Return model metadata as nested Python structures.
Returns
| Name | Type | Description |
|---|---|---|
| dict[str, Any] | A Python dict containing metadata fields such as title, |
|
| dict[str, Any] | description, timestamps, and mizer version information. |
pred_kernel
MizerParams.pred_kernel(as_xarray=True)Return the predation kernel by predator species, predator size, and prey size.
pred_mort
MizerParams.pred_mort(as_xarray=True)Return predation mortality in the initial state.
pred_rate
MizerParams.pred_rate(as_xarray=True, t=0)Return predation rate by predator species and prey size.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| as_xarray | bool | When True, return an xarray.DataArray with dimensions ("sp", "w_prey"). |
True |
| t | float | Time passed through to mizer::getPredRate(). |
0 |
project
MizerParams.project(
effort=None,
*,
t_max=100,
dt=0.1,
t_save=1,
t_start=0,
progress_bar=False,
**kwargs,
)Run mizer::project() and return a wrapped simulation result.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| effort | float | dict[str, float] | Any | None | Fishing effort passed through to mizer. A Python dict is converted to a named R numeric vector. |
None |
| t_max | float | Projection length in years. | 100 |
| dt | float | Internal integration time step. | 0.1 |
| t_save | float | Interval between saved output times. | 1 |
| t_start | float | Starting time recorded on the simulation output. | 0 |
| progress_bar | bool | Whether mizer should show an R-side progress bar. |
False |
| **kwargs | Any | Additional arguments forwarded to mizer::project(). |
{} |
Returns
| Name | Type | Description |
|---|---|---|
| A | 'MizerSim' | class:MizerSim wrapper around the R simulation object. |
Examples
import pymizer as mz
params = mz.new_community_params(no_w=20)
sim = params.project(t_max=5, dt=0.1, t_save=1, progress_bar=False)project_to_steady
MizerParams.project_to_steady(
effort=None,
*,
t_per=1.5,
t_max=100,
dt=0.1,
tol=None,
return_sim=False,
progress_bar=False,
info_level=3,
)Run mizer::projectToSteady().
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| effort | float | dict[str, float] | Any | None | Optional fishing effort used throughout the search. | None |
| t_per | float | Time between convergence checks. | 1.5 |
| t_max | float | Maximum search duration. | 100 |
| dt | float | Integration time step. | 0.1 |
| tol | float | None | Convergence tolerance. Defaults to 0.1 * t_per. |
None |
| return_sim | bool | Return a MizerSim with saved intermediate states. |
False |
| progress_bar | bool | Show an R-side progress bar. | False |
| info_level | int | Verbosity of R-side messages. | 3 |
Returns
| Name | Type | Description |
|---|---|---|
| 'MizerParams | MizerSim' | Either a :class:MizerParams or :class:MizerSim, depending on |
|
| 'MizerParams | MizerSim' | return_sim. |
Examples
steady_params = params.project_to_steady(
t_per=1.0,
t_max=5.0,
dt=0.1,
progress_bar=False,
info_level=0,
)proportion_of_large_fish
MizerParams.proportion_of_large_fish(
species=None,
threshold_w=100,
threshold_l=None,
biomass_proportion=True,
min_w=None,
max_w=None,
min_l=None,
max_l=None,
)Return the proportion of large fish in the initial state.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| species | str | list[str] | tuple[str, …] | None | Optional species subset. | None |
| threshold_w | float | Weight threshold separating small and large fish. | 100 |
| threshold_l | float | None | Length threshold separating small and large fish. | None |
| biomass_proportion | bool | Use biomass rather than numbers. | True |
| min_w | float | list[float] | None | Minimum weight filter. | None |
| max_w | float | list[float] | None | Maximum weight filter. | None |
| min_l | float | list[float] | None | Minimum length filter. | None |
| max_l | float | list[float] | None | Maximum length filter. | None |
rate_functions
MizerParams.rate_functions()Return the registered R rate-function names from params@rates_funcs.
save
MizerParams.save(path)Save the params object using saveParams().
save_rds
MizerParams.save_rds(path)Serialise the wrapped params object as a generic .rds file.
search_volume
MizerParams.search_volume(as_xarray=True)Return search volume by species and size.
set_fishing
MizerParams.set_fishing(**kwargs)Call setFishing() and wrap the returned params object.
set_initial_values
MizerParams.set_initial_values(sim, *, time_range=None, geometric_mean=False)Return a new params object with initial values copied from a simulation.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| sim | 'MizerSim' | Simulation providing the source state. | required |
| time_range | Any | None | Optional time range over which to average. | None |
| geometric_mean | bool | Use a geometric rather than arithmetic mean for abundance spectra. | False |
Examples
sim = params.project(t_max=5, dt=0.1, t_save=1, progress_bar=False)
updated = params.set_initial_values(sim)set_interaction
MizerParams.set_interaction(interaction)Return a new params object with an updated interaction matrix.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| interaction | Any | Species interaction matrix as a pandas DataFrame, NumPy array, or other matrix-like object. | required |
set_max_intake_rate
MizerParams.set_max_intake_rate(intake_max=None, *, reset=False)Return a new params object with updated maximum intake rate.
set_metabolic_rate
MizerParams.set_metabolic_rate(metab=None, *, p=None, reset=False)Return a new params object with updated metabolic rate.
set_metadata
MizerParams.set_metadata(
title=None,
description=None,
authors=None,
url=None,
doi=None,
**extra_fields,
)Return a new params object with updated metadata.
Examples
updated = params.set_metadata(
title="North Sea example",
description="Python wrapper demo",
)set_pred_kernel
MizerParams.set_pred_kernel(pred_kernel=None, *, reset=False)Return a new params object with an updated predation kernel.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| pred_kernel | Any | None | Predator x predator-size x prey-size array. | None |
| reset | bool | Recompute from species parameters instead of using a custom kernel. | False |
set_rate_functions
MizerParams.set_rate_functions(**rate_functions)Return a new params object with selected rates_funcs entries updated.
Each keyword must match an existing name in params@rates_funcs and each value must be the name of an R function visible in the current R session. This gives advanced users controlled access to existing extension hooks without supporting Python callbacks.
set_reproduction
MizerParams.set_reproduction(
maturity=None,
repro_prop=None,
reset=False,
rdd=None,
)Return a new params object with updated reproduction settings.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| maturity | Any | None | Species-by-size maturity array. | None |
| repro_prop | Any | None | Species-by-size reproductive proportion array. | None |
| reset | bool | Recompute from species parameters. | False |
| rdd | str | None | Name of the R density-dependence function to use. | None |
set_resource
MizerParams.set_resource(
resource_rate=None,
resource_capacity=None,
resource_level=None,
resource_dynamics=None,
lambda_=None,
n=None,
w_pp_cutoff=None,
balance=None,
)Return a new params object with updated resource settings.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| resource_rate | Any | None | Resource growth-rate parameter or vector. | None |
| resource_capacity | Any | None | Resource carrying capacity parameter or vector. | None |
| resource_level | Any | None | Ratio of current resource to carrying capacity. | None |
| resource_dynamics | str | None | Name of the resource dynamics function. | None |
| lambda_ | float | None | Resource capacity power-law exponent. | None |
| n | float | None | Resource rate power-law exponent. | None |
| w_pp_cutoff | float | None | Upper cutoff size for the resource power law. | None |
| balance | bool | None | Whether to rebalance the resource to the current state. | None |
Examples
updated = params.set_resource(
resource_dynamics="resource_constant",
balance=False,
)set_search_volume
MizerParams.set_search_volume(search_vol=None, *, reset=False)Return a new params object with updated search volume.
ssb
MizerParams.ssb()Return spawning stock biomass in the initial state as a pandas Series.
steady
MizerParams.steady(
t_per=1.5,
t_max=100,
dt=0.1,
tol=None,
return_sim=False,
preserve='reproduction_level',
progress_bar=False,
info_level=3,
)Run mizer::steady() and return params or a simulation.
This uses the higher-level mizer steady-state workflow that holds reproduction and resource dynamics constant during the search.
steady_single_species
MizerParams.steady_single_species(species=None, *, keep='egg')Run mizer::steadySingleSpecies() for selected species.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| species | str | list[str] | tuple[str, …] | None | Optional species subset. | None |
| keep | str | Quantity to preserve. One of "egg", "biomass", or "number". |
'egg' |
summary
MizerParams.summary()Return the text representation of summary(params).
trophic_level
MizerParams.trophic_level(as_xarray=True)Return trophic level at size in the initial state.
trophic_level_by_species
MizerParams.trophic_level_by_species()Return the species-level trophic level in the initial state.