MizerSim

MizerSim(_r_obj, _env)

Python wrapper around an R MizerSim object.

MizerSim stores time-resolved output from a projection. The wrapper exposes common summaries as labelled pandas and xarray objects.

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)
biomass = sim.biomass()

Attributes

Name Description
r Access the underlying R object.

Methods

Name Description
abundance Return total abundance through time as a pandas DataFrame.
biomass Return biomass through time as a pandas DataFrame.
biomass_tidy Return biomass through time in tidy long-form pandas format.
community_slope Return the fitted community size-spectrum slope through time.
diet Return diet composition at the final simulated state.
f_mort Return fishing mortality through time.
f_mort_gear Return gear-resolved fishing mortality through time.
feeding_level Return feeding levels through time.
growth_curves Return growth curves evaluated from the final simulation state.
initial_n Return the initial fish abundance density spectrum used by the simulation.
initial_n_resource Return the initial resource spectrum used by the simulation.
mean_max_weight Return the mean maximum weight through time.
mean_weight Return mean community weight through time.
n Return the species abundance array.
n_resource Return the resource abundance array.
params Return the MizerParams used to create the simulation.
plot_biomass Plot biomass through time with matplotlib and return the axes.
pred_mort Return predation mortality through time.
pred_rate Return predation rate at the final simulated state.
proportion_of_large_fish Return the proportion of large fish through time.
save_rds Serialise the wrapped simulation object as a generic .rds file.
ssb Return spawning stock biomass through time as a pandas DataFrame.
times Return saved times as a NumPy array.
trophic_level Return trophic level at size at the final simulated state.
trophic_level_by_species Return the species-level trophic level at the final simulated state.
yield_ Return fisheries yield through time as a pandas DataFrame.
yield_gear Return gear-resolved fisheries yield through time.

abundance

MizerSim.abundance(min_w=None, max_w=None, min_l=None, max_l=None)

Return total abundance through time as a pandas DataFrame.

biomass

MizerSim.biomass(
    use_cutoff=False,
    min_w=None,
    max_w=None,
    min_l=None,
    max_l=None,
)

Return biomass through time as a pandas DataFrame.

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

biomass_tidy

MizerSim.biomass_tidy(
    species=None,
    use_cutoff=False,
    min_w=None,
    max_w=None,
    min_l=None,
    max_l=None,
)

Return biomass through time in tidy long-form pandas format.

The returned DataFrame has time, species, and biomass columns, which makes it easy to use with seaborn-style APIs or custom notebook analysis pipelines.

community_slope

MizerSim.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 through time.

diet

MizerSim.diet(proportion=True, as_xarray=True)

Return diet composition at the final simulated state.

This method evaluates diet on a params object rebuilt from the final simulated state.

f_mort

MizerSim.f_mort(as_xarray=True)

Return fishing mortality through time.

f_mort_gear

MizerSim.f_mort_gear(as_xarray=True)

Return gear-resolved fishing mortality through time.

feeding_level

MizerSim.feeding_level(as_xarray=True)

Return feeding levels through time.

growth_curves

MizerSim.growth_curves(species=None, max_age=20, percentage=False)

Return growth curves evaluated from the final simulation state.

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

initial_n

MizerSim.initial_n(as_xarray=True)

Return the initial fish abundance density spectrum used by the simulation.

initial_n_resource

MizerSim.initial_n_resource()

Return the initial resource spectrum used by the simulation.

mean_max_weight

MizerSim.mean_max_weight(
    measure='both',
    *,
    species=None,
    min_w=None,
    max_w=None,
    min_l=None,
    max_l=None,
)

Return the mean maximum weight through time.

mean_weight

MizerSim.mean_weight(
    species=None,
    min_w=None,
    max_w=None,
    min_l=None,
    max_l=None,
)

Return mean community weight through time.

n

MizerSim.n(as_xarray=True)

Return the species abundance array.

Parameters

Name Type Description Default
as_xarray bool When True, return an xarray.DataArray with dimensions ("time", "sp", "w"). True

n_resource

MizerSim.n_resource(as_xarray=True)

Return the resource abundance array.

Parameters

Name Type Description Default
as_xarray bool When True, return an xarray.DataArray with dimensions ("time", "w"). True

params

MizerSim.params()

Return the MizerParams used to create the simulation.

plot_biomass

MizerSim.plot_biomass(
    species=None,
    use_cutoff=False,
    min_w=None,
    max_w=None,
    min_l=None,
    max_l=None,
    ax=None,
    **kwargs,
)

Plot biomass through time with matplotlib and return the axes.

This is an opinionated convenience wrapper around sim.biomass() for quick notebook exploration. For more control, call biomass() or biomass_tidy() directly and build the plot yourself.

pred_mort

MizerSim.pred_mort(as_xarray=True)

Return predation mortality through time.

pred_rate

MizerSim.pred_rate(as_xarray=True)

Return predation rate at the final simulated state.

This uses setInitialValues(getParams(sim), sim) under the hood so that the predation rate is evaluated on the final simulated state.

proportion_of_large_fish

MizerSim.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 through time.

save_rds

MizerSim.save_rds(path)

Serialise the wrapped simulation object as a generic .rds file.

ssb

MizerSim.ssb()

Return spawning stock biomass through time as a pandas DataFrame.

times

MizerSim.times()

Return saved times as a NumPy array.

trophic_level

MizerSim.trophic_level(as_xarray=True)

Return trophic level at size at the final simulated state.

trophic_level_by_species

MizerSim.trophic_level_by_species()

Return the species-level trophic level at the final simulated state.

yield_

MizerSim.yield_()

Return fisheries yield through time as a pandas DataFrame.

yield_gear

MizerSim.yield_gear(as_xarray=True)

Return gear-resolved fisheries yield through time.