Project to centralize code for analyses of simulations with the MONAN model.
MONAN-analysis/
├── README.md
├── pyproject.toml # makes packages inside src/ installable
├── requirements.txt # lists libraries needed to run repo
├── .gitignore # lists files to be ignored by git
├── src/ # source code (installable packages)
│ └── monan_analysis/ # namespace for monan_analysis package
│ ├── __init__.py # python looks for this file when importing modules
│ ├── config.py # general settings shared across multiple analyses
│ ├── utils.py # reusable general-purpose routines
│ ├── io.py # reusable routines for reading input and saving output
│ ├── plots.py # reusable routines for plotting
│ ├── preprocess.py # reusable routines for data preprocessing
│ └── stats.py # reusable routines for calculating statistics
├── analyses/ # ready-to-use analysis code
│ ├── analysis1/
│ │ ├── analysis1_main.py # exemplary main script for analysis1
│ │ ├── analysis1_aux.py # exemplary auxiliary script for analysis1
│ │ └── analysis1_config.py # exemplary config with settings specific to analysis1
│ └── analysis2/
│ ├── analysis2_main.py.py # exemplary main script for analysis2
│ ├── analysis2_aux.py # exemplary auxiliary script for analysis2
│ └── analysis2_config.py # exemplary config with settings specific to analysis2
├── exploratory/ # exploratory (preliminary) scripts
└── unittests/ # unit tests to ensure code is behaving as expected
└── test_monan_analysis/ # unit tests for monan_analysis package
git clone https://github.com/GAMA-INPE/MONAN-analysis.git
cd MONAN-analysis
2.1) If using an HPC system, load Anaconda (or other conda) module
module load anaconda
2.2) Create conda environment to install project packages
conda create -n gama
2.3) Activate conda environment
conda activate gama
2.4) Install python inside that conda environment
conda install python=3.12
2.5) Make sure python is installed in the conda env
which python
If the above points to your recently created conda environment, proceed to step 3.
All project-specific dependencies (external and internal packages under src/) are listed in requirements.txt. Depending on whether you have the external dependencies already installed, you can follow two options:
a) If you do not yet have the external dependencies, you can install those dependencies plus the internal project packages by running
python -m pip install -r requirements.txt
b) If you already have the needed external dependencies and want to install only the internal project packages under src/, you can do this by running
python -m pip install -e .
inside your conda environment.
After installation by option a) or b), you should be able to import in particular internal modules from the packages under src/ in your analysis scripts. You can test this by running from the project's root
python exploratory/import_test/example_analysis.py
If the internal packages have been correctly installed, this test should return
this is a function imported from the utils.py module.
this is a function imported from the io.py module.
this is a function imported from the plots.py module.
this is a function imported from the stats.py module.
The core idea behind this project is that analysis scripts, although developed for performing a particular type of investigation, involve also many repetitive tasks that can be organized in general routines to be reused in the future.
To account for this, the suggested workflow for performing analyses in this repository is the following:
-
Before starting your analysis, check out the general functions and settings already available in our packages under
src/. They may be useful for your particular purposes. -
In
exploratory/, develop your initial analysis scripts and generate your results without worrying too much about organization. -
As the scripts developed in 2. get more mature, transfer them to
analyses/. Here, the goal is to have well tested and documented analysis pipelines that can be readily understood and employed by other users. For a clean code, try to organize the main analysis script as a wrapper (https://en.wikipedia.org/wiki/Wrapper_function; it could be e.g.analyses/analysis1/amalysis1_main.py) that calls subroutines for each task performed. Subroutines that are specific to that particular analysis can be locally defined underanalyses/(e.g.analyses/analysis1/analysis1_aux.py). Subroutines of a more general nature should be defined undersrc/monan_analysisin one of the available modules depending on its purpose (utils.py,io.py,plots.py,stats.py, etc.). A similar procedure can be employed for analysis settings: in defining the parameters/paths/any user configuration for the analysis, try using separate config files (settings specific to the analysis under e.g.analyses/analysis1/amalysis1_config.py, and general settings undersrc/monan_analysis/config.py). Such files have the advantage that they can be saved together with the analysis results, so that one has easily at hand all user input employed for obtaining them.
The goal of all this is to integrate the created general functions and settings into our src/ packages, which are installable, and will therefore be readily available for any future analysis script.
As explained in 1), during steps 2) and 3) the user can take advantage of the already defined functions and settings in our packages under src/. To call them, one just needs to import the respective package as usually done in python, e.g., to import a plotting function do
from monan_analysis.plots import example_function_plots
For developing the project, the following technical workflow is suggested:
-
Preferably, new ideas for implementations should be added to issues (https://github.com/GAMA-INPE/MONAN-analysis/issues), where they can be discussed with the team.
-
Once you plan to implement one of those ideas, assign the issue to yourself and comment something like "I'm taking up this issue" in the respective issue page to avoid different people working on the same issue.
-
Open new branch (name abbreviation/feature, e.g. gtm/repo-organization) for working on that implementation.
-
Work on the code in that branch.
-
Once the code is ready for merging, open a pull request with a basic description of the implementation (mentioning the issue it addresses, if any), and assign reviewers.
-
After reviewer's approval, and if the unit tests are passing, merge into
mainbranch.