-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new constants class * new class colonization start * new class vegetation * changes to veg_model * created get_hydromorphodynamics and import vegetation model * base_simulation.py - created initiate_hydromorphodynamics delft3d.py - created update_hydromorphodynamics * Addition of vegetation characteristics method, growth and mortality classes. New veg_base_simulation. * Addition of vegetation characteristics method, growth and mortality classes. New veg_base_simulation. * add class Hydro_Morphodynamics, process in veg_base_simulation.py * changes to Hydro_Morphodynamics, process in veg_base_simulation.py * changes to Hydro_Morphodynamics, process in veg_base_simulation.py, progress in the veg bio-processes * changes to Hydro_Morphodynamics, process in veg_base_simulation.py, progress in the veg bio-processes * progress in mortality * output * updates to output * progress in mortality * account for maxAge vegetation in veg_growth * account for maxAge vegetation in veg_growth * updates to output * changes after debugging * simtest * veg_delft3D_simulation file * changes to veg_model * updates veg_model * json file for constants and changes to constants class * changes to Vegetation * updates veg_model growth nogrowth * changes to Vegetation * updates veg_model and new veg_lifestages * updates veg_model and new veg_lifestages * changes to Vegetation * changes to Vegetation * Debugging * Debugging * Debugging * Debugging * Added README for the veg_model * Added README for the veg_model * Added README for the veg_model * delete old readme * Rename veg_model_README.md to README.md * delete entries in the initial life stage after passing it to juvenile * delete entries in the initial life stage after passing it to juvenile * add Puccinellia to species in constants, debugging * debugging * debugging * debugging * debugging * debugging and file to read output * debugging and output * debugging and output * debugging and additions for Salicornia * updates veg_mortality.py * changes in mortality * changes in update lifestages * changes in output * ci(pyproject.toml): Corrected tool typo * added test case * test(test/test_data/): Added missing data * test_acceptance.py * delete sim_test * test(test/test_acceptance.py): Fixed test * test(test/test_acceptance.py): Modified test to run on any machine * test(transect_case): Fixed missing test data for the transect case output * autoformat: isort & black * Documentation * autoformat: isort & black * fix bugs in veg_mortality.py * autoformat: isort & black Co-authored-by: DzimbaS <[email protected]> Co-authored-by: deboradta <[email protected]> Co-authored-by: DzimbaS <[email protected]> Co-authored-by: Carsopre <[email protected]> Co-authored-by: deboradta <[email protected]> Co-authored-by: DzimbaS <[email protected]>
- Loading branch information
1 parent
d18c26b
commit 228ad15
Showing
264 changed files
with
4,494 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,48 @@ | ||
[![ci](https://github.com/Deltares/NBSDynamics/actions/workflows/ci.yml/badge.svg)](https://github.com/Deltares/NBSDynamics/actions/workflows/ci.yml) | ||
[![docs](https://github.com/Deltares/NBSDynamics/actions/workflows/docs.yml/badge.svg)](https://github.com/Deltares/NBSDynamics/actions/workflows/docs.yml) | ||
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Deltares_NBSDynamics&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Deltares_NBSDynamics) | ||
![Sonar Coverage](https://img.shields.io/sonar/coverage/Deltares_NBSDynamics?logo=SonarCloud&server=https%3A%2F%2Fsonarcloud.io&?style=plastic&logo=appveyor) | ||
|
||
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Deltares/NBSDynamics) | ||
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/Deltares/NBSDynamics) | ||
|
||
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | ||
|
||
# Official Documentation. | ||
Check our official GitHub pages documentation at [https://deltares.github.io/NBSDynamics/](https://deltares.github.io/NBSDynamics/). | ||
|
||
# CoralModel | ||
A biophysical model framework written in Python to make simulations | ||
on coral development based on four environmental factors: | ||
(1) light; (2) flow; (3) temperature; and (4) acidity. | ||
For the hydrodynamics, the model can be coupled to Delft3D Flexible Mesh; | ||
a hydrodynamic model developed at Deltares | ||
([more information](https://oss.deltares.nl/web/delft3dfm)). | ||
To enable this online coupling, certain configurations of Python are required | ||
([more details](#python-code)). | ||
|
||
**Note:** This model is still in its beta and further development is still being done. | ||
``coral_model_v0`` is used for the study and is rewritten (``coral_model``) to enhance collaboration. | ||
(The original version has not been written efficiently and is hard to follow for outsiders.) | ||
More information on this version control [here](#version-control). | ||
|
||
## Biophysics <a name="biophsics"></a> | ||
This biophysical model framework is part of the result of a | ||
[master thesis](https://repository.tudelft.nl/islandora/object/uuid%3Ae211380e-3f92-4afe-b371-f1e87b0c3bbd?collection=education) | ||
of which the key findings are published in *Environmental Modelling and Software* | ||
(the paper can be found [here](https://www.sciencedirect.com/science/article/pii/S1364815221001468?via%3Dihub)). | ||
|
||
The biophysical relations used in the biophysical model framework are mainly process-based, | ||
where for the acidity the proxy of the aragonite saturation state is used. | ||
Furthermore, both photo- and thermal-acclimatisation are included, | ||
which result in a dynamic behaviour of the corals to their environment. | ||
Hence, the corals are modelled such that they can adapt to changing environmental conditions over time. | ||
|
||
For more details on the biophysics, reference is made to the | ||
[master thesis](https://repository.tudelft.nl/islandora/object/uuid%3Ae211380e-3f92-4afe-b371-f1e87b0c3bbd?collection=education) | ||
and the [paper](https://www.sciencedirect.com/science/article/pii/S1364815221001468?via%3Dihub) that substitute this | ||
repository. | ||
|
||
## Python code <a name="python-code"></a> | ||
The Python code is written in Python 3 and makes use of various packages. | ||
Not all of these packages are automatically included in the standard library of Python, | ||
such as ``NetCDF4`` ([download](http://www.ldf.uci.edu/~gohlke/pythonlibs/#netcdf4)). | ||
In case the biophysical model framework is to be coupled to Delft3d Flexible Mesh, | ||
the ``bmi.wrapper`` package is also required ([download](https://github.com/openearth/bmi-python)). | ||
|
||
The settings of Python and other packages for the online coupling to work properly are the following: | ||
* Python version 3.6.5 | ||
* NumPy version 1.14.3 | ||
* SciPy version 1.1.0 | ||
* NetCDF4 version 1.4.2 | ||
* Matplotlib version 2.2.2 | ||
* BMI-Python | ||
|
||
**Note:** These requirements are only required in case the biophysical model framework is to be coupled | ||
with Delft3D Flexible Mesh. | ||
|
||
|
||
# Version control <a name="version-control"></a> | ||
There are two versions of the CoralModel: ``coral_model_v0`` and ``coral_model``. | ||
The first (``coral_model_v0``) is the original code as used in the study (i.e. | ||
[master thesis](https://repository.tudelft.nl/islandora/object/uuid%3Ae211380e-3f92-4afe-b371-f1e87b0c3bbd?collection=education) | ||
and [paper](https://www.sciencedirect.com/science/article/pii/S1364815221001468?via%3Dihub)). | ||
The latter (``coral_model``) is an updated version, which is rewritten such that it enhances collaboration. | ||
This collaboration was one of the goals to further develop this model, | ||
and the biophysical modelling of coral development. | ||
|
||
``coral_model_v0`` will be depreciated in the future, when ``coral_model`` is fully operational | ||
and possibly even incorporates more aspects of coral (reef) development. | ||
# How to run a Vegetation simulation in NBSDynamics | ||
|
||
|
||
## Simulation structure. | ||
|
||
The simulation is started using the [simtest_saltmars_test](../../test/test_data/simtest_saltmarsh_test.py) file. | ||
Here the different paths need to be specified. | ||
An object of the class [VegFlowFmSimulation](../../src/core/simulation/veg_delft3d_simulation.py) (which inherits from the BaseSimulation) is created. | ||
Within the object, the vegetation species (in constants and vegetation) are required as an input. | ||
Different species are defined through different constants. | ||
In [Constants](../../src/core/common/constants_veg.py) a json file is called which contains the species specific vegetation parameters. | ||
Additional time related constants (e.g. start time and ecological time steps) are defined in [Constants](../../src/core/common/constants_veg.py) and can be changed manually there. | ||
Further species can be added by defining their specific parameters using [constants_json_create](../../src/core/common/constants_json_create.py). | ||
|
||
With those parameters assigned to the object, the simulation is started by using the following methods (specified in the [BaseSimulation](../../src/core/simulation/veg_base_simulation.py)): | ||
|
||
* initiate | ||
* configures hydrodynamics and output | ||
* validates simulation directories | ||
* initiated vegetation characteristics for all life stages in the class [LifeStages](../../src/core/vegetation/veg_lifestages.py) | ||
* initializes the output ([VegOutputWrapper](../../src/core/output/veg_output_wrapper.py)) | ||
|
||
* run | ||
* when calling the run method (sim_run.run()), the duration of the simulation needs to be specified (in years) (e.g. sim_run.run(5)) | ||
* if duration is not given, the duration specified in the [Constants](../../src/core/common/constants_veg.py) class will be used | ||
* the start date is set to the date specified in [Constants](../../src/core/common/constants_veg.py) | ||
* end date = start date + duration | ||
* a loop is started over the duration of the simulation (years) | ||
* inside of that loop another loop iterates over the number of ecological time steps per year (coupling times per year) specified in [Constants](../../src/core/common/constants_veg.py) | ||
* to get the hydro and morphological variables from Delft-FM, the hydro-morphodynamics are retrieved every day. | ||
* the coupling and retrieving of the values is specified in the class [Delft3D](../../src/core/hydrodynamics/delft3d.py) | ||
* aggregated values are then created in the class [Hydro_Morphodynamics](../../src/core/bio_process/hydromorphodynamics.py) and retrieved via the method 'get_hydromorph_values' | ||
* the vegetation dynamics are initiated: | ||
* [Mortality and Growth](../../src/core/bio_process/veg_mortality.py) | ||
* criteria for mortality and mortality fractions are determined based on the species and the morpho- & hydrodynamics | ||
* vegetation growth is initiated based on the number of growth days within the current ecological time step | ||
* [Colonization](../../src/core/bio_process/veg_colonisation.py) | ||
* method is only called when colonization is possible during the specific period of the ecological time step | ||
* criteria for colonization are determined based on the species and the morpho- & hydrodynamics | ||
* the vegetation characteristics of the initial lifestage are updated based on the possible colonization | ||
* [Update_Lifestages](../../src/core/vegetation/veg_model.py) | ||
* the life stages are updates (initial to juvenile and juvenile to mature) | ||
* initial to juvenile always occurs when new vegetation colonized | ||
* juvenile to mature only occurs when vegetation in the juvenile stage reached the maximum years in that life stage | ||
* if the maximum age of vegetation is reached, the vegetation is removed | ||
* The results are exported using the methods defined in [MapOutput](../../src/core/output/veg_output_model.py) and [HisOutput](../../src/core/output/veg_output_model.py) | ||
|
||
* finalize (Finalize simulation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# How to run a Vegetation simulation in NBSDynamics | ||
|
||
|
||
## Simulation structure. | ||
|
||
The simulation is started using the [simtest_saltmars_test](../../test/test_data/simtest_saltmarsh_test.py) file. | ||
Here the different paths need to be specified. | ||
An object of the class [VegFlowFmSimulation](../../reference/simulation/vegetation_simulation/#src.core.simulation.veg_delft3d_simulation) (which inherits from the BaseSimulation) is created. | ||
Within the object, the vegetation species (in constants and vegetation) are required as an input. | ||
Different species are defined through different constants. | ||
In [Constants](../../reference/common/common/#src.core.common.constants_veg) a json file is called which contains the species specific vegetation parameters. | ||
Additional time related constants (e.g. start time and ecological time steps) are defined in [Constants](../../src/core/common/common/#src.core.common.constants_veg) and can be changed manually there. | ||
Further species can be added by defining their specific parameters using [constants_json_create](../../src/core/common/common/#src.core.common.constants_json_create). | ||
|
||
With those parameters assigned to the object, the simulation is started by using the following methods (specified in the [BaseSimulation](../../reference/simulation/vegetation_simulation/#src.core.simulation.veg_base_simulation)): | ||
|
||
* initiate | ||
* configures hydrodynamics and output | ||
* validates simulation directories | ||
* initiated vegetation characteristics for all life stages in the class [LifeStages](../../reference/vegetation/vegetation_model/#src.core.vegetation.veg_lifestages) | ||
* initializes the output ([VegOutputWrapper](../../reference/output/vegetation_output/#src.core.output.veg_output_wrapper)) | ||
|
||
* run | ||
* when calling the run method (sim_run.run()), the duration of the simulation needs to be specified (in years) (e.g. sim_run.run(5)) | ||
* if duration is not given, the duration specified in the [Constants](../../reference/common/common/#src.core.common.constants_veg) class will be used | ||
* the start date is set to the date specified in [Constants](../../reference/common/common/#src.core.common.constants_veg) | ||
* end date = start date + duration | ||
* a loop is started over the duration of the simulation (years) | ||
* inside of that loop another loop iterates over the number of ecological time steps per year (coupling times per year) specified in [Constants](../../reference/common/common/#src.core.common.constants_veg) | ||
* to get the hydro and morphological variables from Delft-FM, the hydro-morphodynamics are retrieved every day. | ||
* the coupling and retrieving of the values is specified in the class [Delft3D](.../../reference/hydrodynamics/hydromodels/#delft3d) | ||
* aggregated values are then created in the class [Hydro_Morphodynamics](../../reference/bio_process/vegetation_processes/#src.core.bio_process.veg_hydro_morphodynamics) and retrieved via the method 'get_hydromorph_values' | ||
* the vegetation dynamics are initiated: | ||
* [Mortality and Growth](../../reference/bio_process/vegetation_processes/#src.core.bio_process.veg_mortality) | ||
* criteria for mortality and mortality fractions are determined based on the species and the morpho- & hydrodynamics | ||
* vegetation growth is initiated based on the number of growth days within the current ecological time step | ||
* [Colonisation](../../reference/bio_process/vegetation_processes/#src.core.bio_process.veg_colonisation) | ||
* method is only called when colonisation is possible during the specific period of the ecological time step | ||
* criteria for colonisation are determined based on the species and the morpho- & hydrodynamics | ||
* the vegetation characteristics of the initial lifestage are updated based on the possible colonisation | ||
* [Update_Lifestages](../../reference/vegetation/vegetation_model/#src.core.vegetation.veg_model) | ||
* the life stages are updates (initial to juvenile and juvenile to mature) | ||
* initial to juvenile always occurs when new vegetation colonized | ||
* juvenile to mature only occurs when vegetation in the juvenile stage reached the maximum years in that life stage | ||
* if the maximum age of vegetation is reached, the vegetation is removed | ||
* The results are exported using the methods defined in [MapOutput](../../reference/output/vegetation_output/#src.core.output.veg_output_model) and [HisOutput](../../reference/output/vegetation_output/#src.core.output.veg_output_model) | ||
|
||
* finalize (Finalize simulation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Biophysical processes | ||
|
||
### Colonisation | ||
::: src.core.bio_process.veg_colonisation | ||
|
||
### Hydro morphodynamics | ||
::: src.core.bio_process.veg_hydro_morphodynamics | ||
|
||
### Mortality and growth | ||
::: src.core.bio_process.veg_mortality | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Output classes for the NBSDynamics vegetation model. | ||
|
||
### Protocol | ||
::: src.core.output.veg_output_protocol | ||
|
||
### Wrapper | ||
::: src.core.output.veg_output_wrapper | ||
|
||
### Output models | ||
::: src.core.output.veg_output_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Classes representing the available simulation modes. | ||
|
||
### Simulation Protocol | ||
::: src.core.simulation.simulation_protocol | ||
|
||
### Base simulation. | ||
::: src.core.simulation.veg_base_simulation | ||
|
||
### Vegetation Delft3D (FlowFM / DIMR) | ||
::: src.core.simulation.veg_delft3d_simulation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Vegetation Model | ||
|
||
:: src.core.vegetation.veg_model | ||
|
||
## Update lifestages | ||
|
||
:: src.core.vegetation.veg_lifestages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import os | ||
|
||
import matplotlib.pyplot as plt | ||
import netCDF4 | ||
import numpy as np | ||
|
||
# plt.style.use('seaborn-whitegrid') | ||
|
||
|
||
out_dir = os.path.join( | ||
"C:\\", | ||
"Users", | ||
"toledoal", | ||
"NBSDynamics", | ||
"test", | ||
"test_data", | ||
"sm_testcase2", | ||
"input", | ||
"MinFiles", | ||
"fm", | ||
"output", | ||
) | ||
|
||
# read map file and plot | ||
url = os.path.join(out_dir, "VegModel_map.nc") | ||
nc = netCDF4.Dataset(url) | ||
nc.variables.keys() | ||
limdict = { | ||
"cover": [0, 9999], | ||
"height": [300, 304], | ||
"diaveg": [295, 297], | ||
"rnveg": [302, 304], | ||
"veg_frac_j": [0, 9999], | ||
"veg_frac_m": [0, 1.05], | ||
"max_tau": [0, 1.05], | ||
"max_u": [0, 1.05], | ||
"max_wl": [0, 1.05], | ||
"min_wl": [0, 1.05], | ||
"bl": [9999, 9999], | ||
} | ||
|
||
teller = 0 | ||
for vv in nc.variables.keys(): | ||
teller = teller + 1 | ||
if teller > 3: | ||
|
||
VT = nc.variables[vv] | ||
VarT = VT[:] | ||
|
||
fig = plt.figure() | ||
ax = plt.axes() | ||
plt.xlim(0, 100) | ||
ylims = limdict[vv] | ||
if ylims[0] == 9999: | ||
ylims[0] = 0.95 * np.min(VarT) | ||
if ylims[1] == 9999: | ||
ylims[1] = 1.05 * np.max(VarT) | ||
plt.ylim(ylims) | ||
plt.title(VT.long_name) | ||
plt.xlabel("Time (years)") | ||
plt.ylabel(VT.units) | ||
|
||
x = np.linspace(1, 100, 100) | ||
|
||
ax.plot(x, VarT[:, 1], "-g", label="Cell 1") | ||
ax.plot(x, VarT[:, 100], "-r", label="Cell 100") | ||
ax.plot(x, VarT[:, 300], "-c", label="Cell 300") | ||
plt.legend() | ||
|
||
nc.close() | ||
|
||
# read his file and plot | ||
url = os.path.join(out_dir, "VegModel_his.nc") | ||
nc = netCDF4.Dataset(url) | ||
nc.variables.keys() | ||
|
||
teller = 0 | ||
for vv in nc.variables.keys(): | ||
teller = teller + 1 | ||
if teller > 3: | ||
|
||
VT = nc.variables[vv] | ||
VarT = VT[:] | ||
|
||
fig = plt.figure() | ||
ax = plt.axes() | ||
plt.xlim(0, 100) | ||
ylims = limdict[vv] | ||
if ylims[0] == 9999: | ||
ylims[0] = 0.95 * np.min(VarT) | ||
if ylims[1] == 9999: | ||
ylims[1] = 1.05 * np.max(VarT) | ||
plt.title(VT.long_name) | ||
plt.xlabel("Time (years)") | ||
plt.ylabel(VT.units) | ||
|
||
x = np.linspace(0, 100, 36525) | ||
colors = iter(plt.cm.rainbow(np.linspace(0, 1, VarT.shape[1]))) | ||
for i in range(VarT.shape[1]): | ||
ax.plot(x, VarT[:, i], color=next(colors), label=f"Point {i}") | ||
plt.legend() | ||
|
||
nc.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.