Skip to content

Commit 1cf51cf

Browse files
committed
Cotton crop added. pyproject.toml file added
1 parent a2bc0ba commit 1cf51cf

7 files changed

Lines changed: 141 additions & 82 deletions

File tree

DSSATTools/base/partypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
'Sugarcane': "SCCAN",
5252
"Wheat": "CSCER",
5353
"DryBean": "CRGRO",
54-
"Cassava": "CSYCA"
54+
"Cassava": "CSYCA",
55+
"Cotton": "CRGRO"
5556
}
5657
CODE_VARS = {
5758
"plme": ["B", "C", "H", "I", "N", "P", "R", "S", "T", "V", None],

DSSATTools/crop.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
'Sugarcane': f'SCCAN{VERSION}.SPE',
4242
"Wheat": f"WHCER{VERSION}.SPE",
4343
"DryBean": f"CRGRO{VERSION}.SPE",
44-
"Cassava": f"CSYCA{VERSION}.SPE"
44+
"Cassava": f"CSYCA{VERSION}.SPE",
45+
"Cotton": f"CRGRO{VERSION}.SPE"
4546
}
4647

4748
DSSAT_MODULE_PATH = os.path.dirname(module_path)
@@ -738,6 +739,48 @@ class Cassava(Crop):
738739
'pps3': '>5.2f', 'phtv': '>5.2f', 'phsv': '>5.2f', 'rdgs': '>5.2f',
739740
'rlwr': '>5.0f', 'wfsu': '>5.2f', 'rsuse': '>5.2f', 'hmpc': '>5.0f'
740741
}
742+
def __init__(self, cultivar_code):
743+
super().__init__(cultivar_code)
744+
return
745+
746+
class Cotton(Crop):
747+
code = "CO"
748+
smodel = CROPS_MODULES["Cotton"]
749+
spe_file = f'{code}{smodel[2:]}{VERSION}.SPE'
750+
spe_path = os.path.join(GENOTYPE_PATH, spe_file)
751+
cul_dtypes = {
752+
'vrname': DescriptionType, 'expno': DescriptionType, 'eco#': Record,
753+
'csdl': NumberType, 'ppsen': NumberType, 'em-fl': NumberType,
754+
'fl-sh': NumberType, 'fl-sd': NumberType, 'sd-pm': NumberType,
755+
'fl-lf': NumberType, 'lfmax': NumberType, 'slavr': NumberType,
756+
'sizlf': NumberType, 'xfrt': NumberType, 'wtpsd': NumberType,
757+
'sfdur': NumberType, 'sdpdv': NumberType, 'podur': NumberType,
758+
'thrsh': NumberType, 'sdpro': NumberType, 'sdlip': NumberType
759+
}
760+
cul_pars_fmt = {
761+
'vrname': '.<16', 'expno': '>5', 'eco#': '>6', 'csdl': '>5.2f',
762+
'ppsen': '>5.3f', 'em-fl': '>5.1f', 'fl-sh': '>5.1f', 'fl-sd': '>5.1f',
763+
'sd-pm': '>5.2f', 'fl-lf': '>5.2f', 'lfmax': '>5.3f', 'slavr': '>5.1f',
764+
'sizlf': '>5.1f', 'xfrt': '>5.2f', 'wtpsd': '>5.3f', 'sfdur': '>5.1f',
765+
'sdpdv': '>5.1f', 'podur': '>5.1f', 'thrsh': '>5.2f', 'sdpro': '>5.3f',
766+
'sdlip': '>5.3f'
767+
}
768+
eco_dtypes = {
769+
'econame': DescriptionType, 'mg': DescriptionType, 'tm': DescriptionType,
770+
'thvar': NumberType, 'pl-em': NumberType, 'em-v1': NumberType,
771+
'v1-ju': NumberType, 'ju-r0': NumberType, 'pm06': NumberType,
772+
'pm09': NumberType, 'lngsh': NumberType, 'r7-r8': NumberType,
773+
'fl-vs': NumberType, 'trifl': NumberType, 'rwdth': NumberType,
774+
'rhght': NumberType, 'r1ppo': NumberType, 'optbi': NumberType,
775+
'slobi': NumberType
776+
}
777+
eco_pars_fmt = {
778+
'econame': '.<17', 'mg': '<2', 'tm': '<2', 'thvar': '>5.1f',
779+
'pl-em': '>5.1f', 'em-v1': '>5.1f', 'v1-ju': '>5.1f', 'ju-r0': '>5.1f',
780+
'pm06': '>5.1f', 'pm09': '>5.2f', 'lngsh': '>5.1f', 'r7-r8': '>5.1f',
781+
'fl-vs': '>5.2f', 'trifl': '>5.2f', 'rwdth': '>5.2f', 'rhght': '>5.2f',
782+
'r1ppo': '>5.3f', 'optbi': '>5.1f', 'slobi': '>5.3f'
783+
}
741784
def __init__(self, cultivar_code):
742785
super().__init__(cultivar_code)
743786
return

DSSATTools/filex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
from .crop import (
9595
Maize, Wheat, Sorghum, PearlMillet, Sugarbeet, Rice, Alfalfa, Bermudagrass,
9696
Soybean, Canola, Sunflower, Potato, Tomato, Cabbage, Sugarcane, DryBean,
97-
Cassava, SweetCorn
97+
Cassava, SweetCorn, Cotton
9898
)
9999
from .weather import WeatherStation
100100
from .soil import SoilProfile
@@ -104,7 +104,7 @@
104104
"MZ": Maize, 'WH': Wheat, 'SG': Sorghum, 'ML': PearlMillet, 'BS': Sugarbeet,
105105
'RI': Rice, 'SW': SweetCorn, 'AL': Alfalfa, 'BM': Bermudagrass,
106106
'SB': Soybean, 'CN': Canola, 'SU': Sunflower, 'PT': Potato, 'TM': Tomato,
107-
'CB': Cabbage, 'SC': Sugarcane, 'BN': DryBean, 'CS': Cassava
107+
'CB': Cabbage, 'SC': Sugarcane, 'BN': DryBean, 'CS': Cassava, 'CO': Cotton
108108
}
109109

110110
class Planting(Record):

pyproject.toml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[project]
2+
name = "DSSATTools"
3+
version = "3.0.2"
4+
description = "A DSSAT's Python implementation"
5+
readme = "README.md"
6+
requires-python = ">=3.6"
7+
license = "GPL-3.0-or-later"
8+
authors = [
9+
{email = "daquinterop@gmail.com", name = "Diego Quintero"},
10+
]
11+
classifiers = [
12+
"Programming Language :: Python :: 3",
13+
]
14+
dependencies = [
15+
"attrs",
16+
"certifi",
17+
"chardet",
18+
"charset-normalizer",
19+
"coverage",
20+
"idna",
21+
"iniconfig",
22+
"numpy",
23+
"packaging",
24+
"pandas",
25+
"pluggy",
26+
"py",
27+
"pyparsing",
28+
"pytest",
29+
"pytest-cov",
30+
"python-dateutil",
31+
"pytz",
32+
"requests",
33+
"rosetta-soil",
34+
"six",
35+
"toml",
36+
"tomli",
37+
]
38+
39+
[project.urls]
40+
"Homepage" = "https://github.com/daquinterop/Py_DSSATTools"
41+
"Bug Tracker" = "https://github.com/daquinterop/Py_DSSATTools/issues"
42+
"Documentation" = "https://py-dssattools.readthedocs.io/en/latest/"
43+
"Repository" = "https://github.com/daquinterop/Py_DSSATTools"
44+
45+
[tool.setuptools]
46+
packages = [
47+
'DSSATTools',
48+
'DSSATTools.base',
49+
'DSSATTools.dssat-csm-os.Data',
50+
'DSSATTools.dssat-csm-os.Data.Genotype',
51+
'DSSATTools.dssat-csm-os.Data.Default',
52+
'DSSATTools.dssat-csm-os.Data.Pest',
53+
'DSSATTools.dssat-csm-os.Data.StandardData',
54+
'DSSATTools.bin'
55+
]
56+
57+
[tool.setuptools.package-data]
58+
"DSSATTools.dssat-csm-os.Data.Genotype" = ["*"]
59+
"DSSATTools.bin" = ["dscsm048", "dscsm048.exe"]
60+
"DSSATTools.dssat-csm-os.Data.Default" = ["*"]
61+
"DSSATTools.dssat-csm-os.Data.Pest" = ["*"]
62+
"DSSATTools.dssat-csm-os.Data.StandardData" = ["*"]
63+
"DSSATTools.dssat-csm-os.Data" = ["*"]

requirements.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/test_run.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
| Cabbage | IBMC9601 | 1 |
2626
| Sugarcane | ESAL1401 | 1 |
2727
| Cassava | CCPA7801 | 1 |
28+
| Cotton | GACM0401 | 1 |
2829
"""
2930
import pytest
3031

@@ -709,5 +710,33 @@ def test_freeze_soya():
709710
assert 'Freeze occurred' in dssat.stdout
710711
dssat.close()
711712

713+
def test_cotton():
714+
"""
715+
Experiment GACM0401, Treatment 1
716+
"""
717+
soil = SoilProfile.from_file(
718+
"GAPL850009",
719+
os.path.join(DATA_PATH, 'Soil', 'GA.SOL')
720+
)
721+
weather_station = WeatherStation.from_files([
722+
os.path.join(DATA_PATH, 'Weather', "GACM9824.WTH"),
723+
])
724+
treatments = read_filex(os.path.join(DATA_PATH, 'Cotton', "GACM0401.COX"))
725+
treatment = treatments[1]
726+
treatment["Field"]["wsta"] = weather_station
727+
treatment["Field"]["id_soil"] = soil
728+
729+
dssat = DSSAT(os.path.join(TMP, 'dssat_test'))
730+
results = dssat.run_treatment(
731+
cultivar=treatment['Cultivar'].crop,
732+
field=treatment["Field"],
733+
initial_conditions=treatment['InitialConditions'],
734+
planting=treatment["Planting"],
735+
fertilizer=treatment["Fertilizer"],
736+
simulation_controls=treatment["SimulationControls"]
737+
)
738+
assert np.isclose(4647, results['harwt'], rtol=0.01)
739+
dssat.close()
740+
712741
if __name__ == "__main__":
713-
test_wheat()
742+
test_cotton()

0 commit comments

Comments
 (0)