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_survivaljuvenile_survivalfecundityallcustom
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e7adfea008429064c3f859176a16a6b0fd1c7a2579a21d01651a332e41c353c
|
|
| MD5 |
46cfc39652eea1e07a646d7ee4c661be
|
|
| BLAKE2b-256 |
26267c433be29111f8f68237d7778886e232c933d89ce475194ed33c110bcaaf
|
Provenance
The following attestation bundles were made for demovuln-0.1.0.tar.gz:
Publisher:
publish.yml on agimenezromero/demovuln
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demovuln-0.1.0.tar.gz -
Subject digest:
2e7adfea008429064c3f859176a16a6b0fd1c7a2579a21d01651a332e41c353c - Sigstore transparency entry: 1572491265
- Sigstore integration time:
-
Permalink:
agimenezromero/demovuln@8c7f4cd196098c144ac3459ceb09621e3f2c1563 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/agimenezromero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8c7f4cd196098c144ac3459ceb09621e3f2c1563 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ac6f310d41b4982cb720870152f4c72ddf6b45289774a9306a7b342cc908e48
|
|
| MD5 |
15bed6fee42739085d6fd6d45dd3cce1
|
|
| BLAKE2b-256 |
d38fcae3e6ee84de5ea111d0864d54740128df4b3b3f8c1b8f918b21d6ac8b00
|
Provenance
The following attestation bundles were made for demovuln-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on agimenezromero/demovuln
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demovuln-0.1.0-py3-none-any.whl -
Subject digest:
6ac6f310d41b4982cb720870152f4c72ddf6b45289774a9306a7b342cc908e48 - Sigstore transparency entry: 1572491273
- Sigstore integration time:
-
Permalink:
agimenezromero/demovuln@8c7f4cd196098c144ac3459ceb09621e3f2c1563 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/agimenezromero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8c7f4cd196098c144ac3459ceb09621e3f2c1563 -
Trigger Event:
push
-
Statement type: