Skip to content

Commit

Permalink
sections.py modified for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
daquinterop committed Aug 17, 2023
2 parents fd6aac6 + 4252538 commit 4198a32
Show file tree
Hide file tree
Showing 19 changed files with 1,277 additions and 1,812 deletions.
57 changes: 44 additions & 13 deletions DSSATTools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
'''
DSSAT library allows the user to create low-code scripts to run simulations with the DSSAT model. The library structure allows to execute the DSSAT model based on four input classes: `Crop`, `SoilProfile`, `WeatherStation` and `Management`.
DSSATTools library allows the user to create low-code scripts to run simulations
using the DSSAT modeling framework. The library structure allows to executes DSSAT
based on four input classes: `Crop`, `SoilProfile`, `Weather` and `Management`.
The simulation environment is managed by the `DSSAT` Class. There are three stages
for the simulation to be performed:
The simulation environment is represented by the `DSSAT` Class. There are three stages for the simulation to be excecuted:
#. Initialize a `DSSAT` instance
#. setup the simulation environment by using the `DSSAT.setup` method
#. run the simulation using the `DSSAT.run` method.
1. Initialize a `DSSAT` instance.
2. setup the simulation environment by using the `DSSAT.setup` method. When that
method is called a new directory is created in the provided location (a tmp
directory is default) and all the files that are necessary to run the model are
copied in that folder.
3. run the simulation calling `DSSAT.run` method. That method needs four
parameters to be pased. Each parameter indicates the crop, soil, weather, and management.
This step can be performed as many times as one wants.
4. close the environment using `DSSAT.close`. This removes the directory and the
files created during the environment setup.
During the environment setup (`DSSAT.setup`) a directory is created and all the static files required to run DSSAT are copied in that directory. This directory will be removed when the `DSSAT.close` method is called. After the environment has been set up, the `DSSAT.run` method can be called as many times as you want.
The next simple example illustrates how to run a simulation using the five
aforementioned classes:
Input clases are defined by sections and tabular subsections within some sections. Each section is an attribute of the input instance and is defined as an independent `RowBasedSection` class. This class inherits from `dict`, so you can modify any parameter in the section the same way that you'd modify a `dict`'s item.
>>> crop = Crop('maize')
>>> weather = Weather(
df, # Weather data with a datetime index
{"tn": "TMIN", "rad": "SRAD", "prec": "RAIN", "rh": "RHUM", "TMAX": "TMAX"},
4.54, -75.1, 1800
)
>>> soil = SoilProfile(default_class='SIL')
>>> man = Management(planting_date=datetime(12, 3, 2020))
>>> dssat = DSSAT()
>>> dssat.setup()
>>> dssat.run(soil, wth, crop, man)
>>> growth = dssat.output["PlantGro"]
>>> dssat.close() # Terminate the simulation environment
All of the parameters and attributes of the four basic clases have the same name you find in the DSSAT files (Take a look at the .CDE files in https://github.com/DSSAT/dssat-csm-os/tree/develop/Data).
The parameters for ecach class are described in their doucmentation. It is very
important to highlight that this library will allow the user to run only one treatment
at a time. If the users are familiar to DSSAT, they must know that DSSAT allows to
define multiple treatments in the same experimental file.
All of the parameters for the four basic clases have the same names you find in
the DSSAT files (Take a look at the .CDE files in
https://github.com/DSSAT/dssat-csm-os/tree/develop/Data).
Up to date next crops and models are included:
Expand All @@ -31,19 +61,20 @@
Potato SUBSTOR
Tomato CROPGRO
Cabbage CROPGRO
Potato SUBSTOR
Sugarcane CANEGRO
================== =====================
'''
VERSION = '048'

from DSSATTools.crop import Crop
from DSSATTools.crop import Crop, available_cultivars
from DSSATTools.soil import SoilProfile, SoilLayer
from DSSATTools.weather import WeatherStation, WeatherData
from DSSATTools.weather import Weather
from DSSATTools.management import Management
from DSSATTools.run import DSSAT
from DSSATTools.base.sections import TabularSubsection

__all__ = [
'Crop', 'SoilProfile', 'SoilLayer', 'WeatherStation', 'WeatherData',
'Management', 'DSSAT', 'TabularSubsection'
'Crop', 'SoilProfile', 'SoilLayer', 'Weather', 'Management', 'DSSAT',
'TabularSubsection', "available_cultivars"
]
Loading

0 comments on commit 4198a32

Please sign in to comment.