Code Monkey home page Code Monkey logo

metacast's Introduction

MetaCast

A package for broadCASTing epidemiological and ecological models over META-populations.

DOI DOI

Summary

MetaCast is a python package for broadcasting epidemiological and ecological ODE based models over metapopulations (structured populations). Users first define a function describing the subpopulation model. MetaCast's users then define the dimensions of metapopulations that this subpopulation is broadcast over. These dimensions can be flexibly defined allowing for multiple dimensions and migration (flows) of populations between subpopulations. In addition to the metapopulation suite MetaCast has several features. A multinomial seeder allows users to randomly select infected stages to place an infected population in based on the occupancy time of infected states. MetaCast's event queue suite can handle discrete events within simulations, such as movement of populations between compartments and changes in parameter values. Sensitivity analysis can be done in MetaCast using parallelisable Latin Hypercube Sampling and Partial Rank Correlation Coefficient functions. All of this makes MetaCast an ideal package not only for modelling metapopulations but for wider scenario analysis.

Installation

Requirements

Python 3.10 and pip. Package requirements:

  • numpy >= 1.26.3
  • pandas >= 2.1.4
  • scipy >= 1.11.4
  • pingouin >= 0.5.4
  • tqdm >= 4.66.1
  • dask >= 2024.2.1
  • distributed >= 2024.2.1

For running demonstration jupyter notebooks

  • bokeh >= 3.3.4
  • seaborn >= 0.13.2
  • jupyter >= 1.0.0

Installing via pip

Note this should also install required packages.

pip install metacast

Usage

See jupyter notebooks in demonstration directory of the projects GitGub repository: https://github.com/m-d-grunnill/MetaCast/tree/main/demonstrations

Documentation

https://metacast.readthedocs.io/en/latest/index.html

Citation & Paper

Grunnill et al., (2024). MetaCast: A package for broadCASTing epidemiological and ecological models over META-populations.. Journal of Open Source Software, 9(99), 6851, https://doi.org/10.21105/joss.06851

Contributing

If you wish to contribute to this project please see the CONTRIBUTING.md file.

metacast's People

Contributors

m-d-grunnill avatar mstimberg avatar robmoss avatar

Stargazers

Sandalots avatar Tobias Augspurger avatar Venkata Duvvuri avatar

Watchers

 avatar Julien Arino avatar

Forkers

robmoss mstimberg

metacast's Issues

Possible typos in example notebook and MetaCast package

Hi @m-d-grunnill, I noticed the following potential typos in the example notebook and the MetaCast package:

  • The MultnomialSeeder class is missing the "i" in "Multi"?
  • The metacast.event_handling module provides an EventQueue class, but "queue" is spelt "que" in several places, such as:
    • The metacast.event_handling.event_que module (unlikely to be an issue, since the EventQueue class is typically imported from metacast.event_handling)
    • Throughout the demonstration notebook
  • "Compliance" is spelt "complaince" in several times in the demonstration notebook.

The last two should be simple to address, while correcting the first one would introduce a breaking change unless the class is exported under both the original and corrected names.

None of these are critical, and they do not detract from the value of the package, the examples presented in the notebook, or the JOSS paper. So please resolve these typos as you see fit, or not at all.

Cannot run test cases: ModuleNotFoundError

Hi @m-d-grunnill

I cannot run the test cases because they contain import statements that refer to src.metacast, and while src/ is a directory it isn't a valid Python module:

$ python3 tests/test_event_que.py 
Traceback (most recent call last):
  File "/home/.../MetaCast/tests/test_event_que.py", line 9, in <module>
    from src.metacast import MetaCaster
ModuleNotFoundError: No module named 'src'

If I replace src.metacast with metacast, I can run all of the test cases in a virtual environment where I have installed MetaCast, and they all succeed.

Creating a virtual environment (e.g., in ./venv) and installing MetaCast is relatively straightforward, and the following could be saved as a shell script (e.g., run_tests.sh):

$ python3 -m venv ./venv
$ . venv/bin/activate
$ pip install .
$ for test_file in tests/test_*.py; do python3 "${test_file}"; done
....
----------------------------------------------------------------------
Ran 4 tests in 0.553s

OK
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
                                                                                              .
----------------------------------------------------------------------                         
Ran 1 test in 0.960s

OK
........
----------------------------------------------------------------------
Ran 8 tests in 0.259s

OK

NOTE: In the rest of this comment, I provide a suggestion about how to automate the test cases. I do not expect you to implement this kind of automation as a necessary step in the JOSS review process. This is just a suggestion for your consideration, entirely independent of my comments for the JOSS review.

Alternatively, you could consider using an automation tool. For example, I use nox for running test cases, building and publishing online documentation, running code checks, etc. To run the MetaCast test cases with nox, you can create a file called noxfile.py with the following content:

import nox
import pathlib

@nox.session(reuse_venv=True)
def tests(session):
    """Run test cases."""
    session.install('.')
    test_dir = pathlib.Path('tests')
    for test_file in test_dir.glob('test_*.py'):
        session.run('python3', test_file)

If you install nox, you can then run it from the root of the repository to run the test cases:

$ nox
nox > Running session tests
nox > Creating virtual environment (virtualenv) using python3 in .nox/tests
nox > python -m pip install .
nox > python3 tests/test_event_que.py
....
----------------------------------------------------------------------
Ran 4 tests in 0.610s

OK
nox > python3 tests/test_metacaster.py
........
----------------------------------------------------------------------
Ran 8 tests in 0.263s

OK
nox > python3 tests/test_lhs_and_prcc.py
                                                                                              .
----------------------------------------------------------------------                         
Ran 1 test in 1.014s

OK
nox > python3 tests/test_infection_seeding.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
nox > Session tests was successful.

You could then add a GitHub workflow that installs Python, then installs and runs nox.

JOSS Review - Recommended Edits for Paper.md

Hi @m-d-grunnill,

Overall, this paper looks good, but I noticed some grammatical and structural issues:

  • Under Summary, on line 18, the comma after "models" should be moved to after "flexibly." Also, the acronym "ODE" should be defined before using it.
  • Under Statement of need:
    • The third word in the title of this section should be capitalized to match the capitalization pattern shown in the other sections' titles.
    • On line 33: The word "to" should be added between "order" and "expedite."
    • On line 37: The phrase that starts with "The dimensions (groupings)..." is a fragment and should be merged with one of the sentences around it.
    • On line 37: The word "cluster" should be "clusters."
    • On lines 38-40: The sentence that starts with "MetaCast builds..." could be rewritten for greater clarity.
    • On lines 42-43: I'd suggest rewriting the phrase "makes MetaCast an ideal package" in the last sentence of this paragraph, as this phrase was already used in the last sentence of the paragraph right above it (under Summary).
  • Under State of Field:
    • On line 46: A comma should be added after "knowledge."
    • On lines 49 and 58: To stay consistent with previous descriptions of the package in the paper, the phrase "for Epidemiology" should be expanded to "for Epidemiology and Ecology."
    • On line 60: Covasim should have the same formatting as Epipack and the other package names.
    • On line 61: The word "a" should be removed.
    • On line 67: The comma at the end of the line should be a colon.
  • Under Acknowledgements and Funding, the bullet points are not rendering correctly in the PDF.

Question

Hi Martin,

I have some questions about your code, just for educating. Are you coming to the lab next Wednesday?

Latin Hypercube sampling only supports uniform distributions

Hi @m-d-grunnill I noticed the following comment in §5.2 of the demonstration notebook:

"Note currently metacast only support latin hypercube sampling with uniform distributions."

I feel that this is a relatively important limitation, and it should probably be mentioned elsewhere (e.g., README.md).

End users can circumvent this limitation by sampling from the unit interval, and using inverse-CDF functions to then sample from their desired distributions (e.g., using the ppf() method of scipy.stats distributions). So while this is a limitation of the MetaCast package, it still allows users to sample from arbitrary distributions. You could highlight this in §5.2 of the notebook (and maybe in README.md).

Would it be relatively simple to allow users to provide ppf() methods for each parameter? (I'm asking out of interest, not in th expectation that you'll do this as part of the JOSS review).

Aside: I maintain a Latin hypercube sampling package (imaginatively named lhs) that supports sampling from arbitrary distributions, and defining "dependent distributions" whose shape parameters can be functions of the samples drawn for other parameters. Distributions can be defined in a number of ways.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.