Skip to main content

Demographic vulnerability metrics for matrix population models under temporally structured perturbations.

Project description

demovuln

demovuln is a Python package for simulating temporally structured demographic perturbations in matrix population models and estimating integrated population vulnerability.

The package is designed for comparative demographic analyses in which perturbations differ in magnitude, duration, and recurrence. It provides tools to simulate individual perturbation trajectories, evaluate full perturbation grids, and compute an integrated vulnerability metric based on population reduction relative to an unperturbed baseline.

Installation

For local development:

git clone https://github.com/agimenezromero/demovuln.git
cd demovuln
python -m pip install -e ".[dev,docs]"

After publication on PyPI, the package will be installable with:

pip install demovuln

Basic usage

import numpy as np
from demovuln import MatrixPopulationModel, simulate_dynamics

A = np.array([
    [0.0, 2.0],
    [0.4, 0.7],
])

model = MatrixPopulationModel(A)

result = simulate_dynamics(
    model,
    target="adult_survival",
    magnitude=0.25,
    duration=1,
    period=3,
    t_max=50,
    recovery_steps=10,
)

print(result.reduction)
print(result.abundance)

Perturbation-grid analysis

import numpy as np
from demovuln import MatrixPopulationModel, PerturbationGrid, run_grid

A = np.array([
    [0.0, 2.0],
    [0.4, 0.7],
])

model = MatrixPopulationModel(A)

grid = PerturbationGrid(
    magnitudes=np.linspace(0, 1, 11),
    durations=[0, 1, 2, 3],
    periods=[1, 2, 3, 5, 10],
)

out = run_grid(
    model,
    target="adult_survival",
    grid=grid,
    t_max=50,
    recovery_steps=10,
)

print(out.vulnerability)
print(out.table.head())

Demographic targets

The package supports perturbations to:

  • adult_survival
  • juvenile_survival
  • fecundity
  • all
  • custom

By default, adult stages are inferred as source-stage columns with at least one fecundity entry, and juvenile stages are inferred as the remaining source-stage columns. These definitions can be specified explicitly:

model = MatrixPopulationModel(
    A,
    adult_stages=[1],
    juvenile_stages=[0],
)

Custom perturbation targets can be defined with Boolean masks:

custom_mask = np.array([
    [False, False],
    [True, False],
])

result = simulate_dynamics(
    model,
    target="custom",
    custom_mask=custom_mask,
    magnitude=0.5,
    duration=1,
    period=3,
    t_max=50,
)

Conceptual summary

For a given perturbation regime, population reduction is computed as:

rho = 100 * (1 - N_perturbed(T) / N_baseline(T))

where N_perturbed(T) is the final population size under perturbed dynamics and N_baseline(T) is the final population size under the unperturbed baseline.

Integrated vulnerability is the mean population reduction across the simulated perturbation space:

Phi = mean(rho)

Development checks

Run:

pytest
python examples/basic_usage.py
ruff check demovuln tests examples
sphinx-build -W -b html docs docs/_build/html

Documentation

Local documentation can be built with:

sphinx-build -b html docs docs/_build/html

Then open:

xdg-open docs/_build/html/index.html

Citation

Citation metadata are provided in CITATION.cff.

License

This package is distributed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

demovuln-0.1.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

demovuln-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file demovuln-0.1.0.tar.gz.

File metadata

  • Download URL: demovuln-0.1.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for demovuln-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2e7adfea008429064c3f859176a16a6b0fd1c7a2579a21d01651a332e41c353c
MD5 46cfc39652eea1e07a646d7ee4c661be
BLAKE2b-256 26267c433be29111f8f68237d7778886e232c933d89ce475194ed33c110bcaaf

See more details on using hashes here.

Provenance

The following attestation bundles were made for demovuln-0.1.0.tar.gz:

Publisher: publish.yml on agimenezromero/demovuln

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file demovuln-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: demovuln-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for demovuln-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ac6f310d41b4982cb720870152f4c72ddf6b45289774a9306a7b342cc908e48
MD5 15bed6fee42739085d6fd6d45dd3cce1
BLAKE2b-256 d38fcae3e6ee84de5ea111d0864d54740128df4b3b3f8c1b8f918b21d6ac8b00

See more details on using hashes here.

Provenance

The following attestation bundles were made for demovuln-0.1.0-py3-none-any.whl:

Publisher: publish.yml on agimenezromero/demovuln

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page