pyswap 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. pyswap-0.1.0/LICENSE +21 -0
  2. pyswap-0.1.0/PKG-INFO +66 -0
  3. pyswap-0.1.0/README.md +46 -0
  4. pyswap-0.1.0/pyproject.toml +26 -0
  5. pyswap-0.1.0/pyswap/__init__.py +3 -0
  6. pyswap-0.1.0/pyswap/atmosphere/__init__.py +13 -0
  7. pyswap-0.1.0/pyswap/atmosphere/meteorology.py +123 -0
  8. pyswap-0.1.0/pyswap/atmosphere/metfile.py +107 -0
  9. pyswap-0.1.0/pyswap/atmosphere/tables.py +34 -0
  10. pyswap-0.1.0/pyswap/boundary/__init__.py +9 -0
  11. pyswap-0.1.0/pyswap/boundary/boundary.py +146 -0
  12. pyswap-0.1.0/pyswap/core/__init__.py +22 -0
  13. pyswap-0.1.0/pyswap/core/basemodel.py +87 -0
  14. pyswap-0.1.0/pyswap/core/database/__init__.py +11 -0
  15. pyswap-0.1.0/pyswap/core/database/connection.py +64 -0
  16. pyswap-0.1.0/pyswap/core/database/events.py +36 -0
  17. pyswap-0.1.0/pyswap/core/database/models.py +83 -0
  18. pyswap-0.1.0/pyswap/core/defaults.py +14 -0
  19. pyswap-0.1.0/pyswap/core/fields.py +56 -0
  20. pyswap-0.1.0/pyswap/core/files.py +46 -0
  21. pyswap-0.1.0/pyswap/core/plot/__init__.py +11 -0
  22. pyswap-0.1.0/pyswap/core/plot/evapotranspiration.py +32 -0
  23. pyswap-0.1.0/pyswap/core/plot/gwl.py +34 -0
  24. pyswap-0.1.0/pyswap/core/plot/watercontent.py +35 -0
  25. pyswap-0.1.0/pyswap/core/serializers.py +85 -0
  26. pyswap-0.1.0/pyswap/core/tablevalidation.py +42 -0
  27. pyswap-0.1.0/pyswap/core/valueranges.py +16 -0
  28. pyswap-0.1.0/pyswap/drainage/__init__.py +12 -0
  29. pyswap-0.1.0/pyswap/drainage/drafile.py +196 -0
  30. pyswap-0.1.0/pyswap/drainage/drainage.py +39 -0
  31. pyswap-0.1.0/pyswap/extras/__init__.py +6 -0
  32. pyswap-0.1.0/pyswap/extras/heatflow.py +73 -0
  33. pyswap-0.1.0/pyswap/extras/solutetransport.py +63 -0
  34. pyswap-0.1.0/pyswap/extras/tables.py +30 -0
  35. pyswap-0.1.0/pyswap/irrigation/__init__.py +13 -0
  36. pyswap-0.1.0/pyswap/irrigation/irgfile.py +48 -0
  37. pyswap-0.1.0/pyswap/irrigation/irrigation.py +160 -0
  38. pyswap-0.1.0/pyswap/irrigation/tables.py +27 -0
  39. pyswap-0.1.0/pyswap/libs/swap420-exe/swap.exe +0 -0
  40. pyswap-0.1.0/pyswap/libs/swap420-linux/swap420 +0 -0
  41. pyswap-0.1.0/pyswap/model/__init__.py +12 -0
  42. pyswap-0.1.0/pyswap/model/model.py +206 -0
  43. pyswap-0.1.0/pyswap/model/result.py +61 -0
  44. pyswap-0.1.0/pyswap/plant/__init__.py +13 -0
  45. pyswap-0.1.0/pyswap/plant/create_crp_tables.py +59 -0
  46. pyswap-0.1.0/pyswap/plant/crop.py +47 -0
  47. pyswap-0.1.0/pyswap/plant/crpfile.py +708 -0
  48. pyswap-0.1.0/pyswap/plant/read_yaml.py +87 -0
  49. pyswap-0.1.0/pyswap/plant/tables.py +103 -0
  50. pyswap-0.1.0/pyswap/simsettings/__init__.py +13 -0
  51. pyswap-0.1.0/pyswap/simsettings/general.py +139 -0
  52. pyswap-0.1.0/pyswap/simsettings/metadata.py +30 -0
  53. pyswap-0.1.0/pyswap/simsettings/richards.py +37 -0
  54. pyswap-0.1.0/pyswap/soilwater/__init__.py +19 -0
  55. pyswap-0.1.0/pyswap/soilwater/evaporation.py +51 -0
  56. pyswap-0.1.0/pyswap/soilwater/snow.py +41 -0
  57. pyswap-0.1.0/pyswap/soilwater/soilmoisture.py +41 -0
  58. pyswap-0.1.0/pyswap/soilwater/soilprofile.py +46 -0
  59. pyswap-0.1.0/pyswap/soilwater/surfaceflow.py +44 -0
  60. pyswap-0.1.0/pyswap/soilwater/tables.py +76 -0
  61. pyswap-0.1.0/pyswap/testcase/__init__.py +2 -0
  62. pyswap-0.1.0/pyswap/testcase/data/1-hupselbrook/283.csv +8870 -0
  63. pyswap-0.1.0/pyswap/testcase/data/1-hupselbrook/grassd.crp +492 -0
  64. pyswap-0.1.0/pyswap/testcase/data/1-hupselbrook/swap.dra +381 -0
  65. pyswap-0.1.0/pyswap/testcase/hupselbrook.py +464 -0
  66. pyswap-0.1.0/pyswap/testcase/load_data.py +26 -0
  67. pyswap-0.1.0/pyswap/testcase/run_testcase.py +11 -0
  68. pyswap-0.1.0/pyswap/tests/test_boundary.py +15 -0
  69. pyswap-0.1.0/pyswap/tests/test_db.py +38 -0
  70. pyswap-0.1.0/pyswap/tests/test_metadata.py +19 -0
pyswap-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 zawadzkim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pyswap-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyswap
3
+ Version: 0.1.0
4
+ Summary: Python wrapper for SWAP hydrological model.
5
+ License: MIT
6
+ Author: Mateusz
7
+ Author-email: zawadzkimat@outlook.com
8
+ Requires-Python: >=3.11,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Requires-Dist: jupyter (>=1.0.0,<2.0.0)
14
+ Requires-Dist: knmi-py (>=0.1.10,<0.2.0)
15
+ Requires-Dist: numpy (>=1.26.4,<2.0.0)
16
+ Requires-Dist: pandas (>=2.2.2,<3.0.0)
17
+ Requires-Dist: pydantic (>=2.7.4,<3.0.0)
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pySWAP - Python wraper for SWAP hydrological model
21
+
22
+ <!-- [![CI](https://img.shields.io/github/actions/workflow/status/pydantic/pydantic/ci.yml?branch=main&logo=github&label=CI)](https://github.com/pydantic/pydantic/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)
23
+ [![Coverage](https://coverage-badge.samuelcolvin.workers.dev/pydantic/pydantic.svg)](https://coverage-badge.samuelcolvin.workers.dev/redirect/pydantic/pydantic)
24
+ [![pypi](https://img.shields.io/pypi/v/pydantic.svg)](https://pypi.python.org/pypi/pydantic)
25
+ [![CondaForge](https://img.shields.io/conda/v/conda-forge/pydantic.svg)](https://anaconda.org/conda-forge/pydantic)
26
+ [![downloads](https://static.pepy.tech/badge/pydantic/month)](https://pepy.tech/project/pydantic)
27
+ [![versions](https://img.shields.io/pypi/pyversions/pydantic.svg)](https://github.com/pydantic/pydantic)
28
+ [![license](https://img.shields.io/github/license/pydantic/pydantic.svg)](https://github.com/pydantic/pydantic/blob/main/LICENSE)
29
+ [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges) -->
30
+
31
+ pySWAP is a Python wrapper (not Python implementation) for the SWAP hydrological model developed at Wageningen University and Research ([link to the model website](https://www.swap.alterra.nl/)). It simplifies the creation of input files, execution of the SWAP model, and analysis and visualization of results. Users can set up and document their models in Jupyter notebooks, enhancing transparency, collaboration, and facilitating community-supported debugging.
32
+
33
+ ## Contributing
34
+
35
+ pySWAP is in the early stages of development so any contributions are highly encouraged. You can open issues, submit pull requests, or initiate discussions on GitHub. For more details on how you can contribute, visit the [CONTRIBUTE](./docs/CONTRIBUTING.md) section and get involved!
36
+
37
+ ## Help
38
+
39
+ Consult pySWAP [documentation](https://docs.pydantic.dev/) page for detailed instructions.
40
+
41
+ ## Installation
42
+
43
+ As this is still a development version, the package is only available through GitHub.
44
+ You can install it by cloning the repository and installing it in your environment using
45
+ pip:
46
+
47
+ ```shell
48
+ git clone --recurse-submodules https://github.com/zawadzkim/pySWAP.git
49
+ ```
50
+
51
+ Then go inside the freshly cloned repo and type:
52
+
53
+ ```Shell
54
+ pip install .
55
+ ```
56
+
57
+ If you would like to adapt the software and share it, install it in interactive mode:
58
+
59
+ ```Shell
60
+ pip install -e .
61
+ ```
62
+
63
+ <!-- ## Reporting a Security Vulnerability
64
+
65
+ See our [security policy](https://github.com/pydantic/pydantic/security/policy). -->
66
+
pyswap-0.1.0/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # pySWAP - Python wraper for SWAP hydrological model
2
+
3
+ <!-- [![CI](https://img.shields.io/github/actions/workflow/status/pydantic/pydantic/ci.yml?branch=main&logo=github&label=CI)](https://github.com/pydantic/pydantic/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)
4
+ [![Coverage](https://coverage-badge.samuelcolvin.workers.dev/pydantic/pydantic.svg)](https://coverage-badge.samuelcolvin.workers.dev/redirect/pydantic/pydantic)
5
+ [![pypi](https://img.shields.io/pypi/v/pydantic.svg)](https://pypi.python.org/pypi/pydantic)
6
+ [![CondaForge](https://img.shields.io/conda/v/conda-forge/pydantic.svg)](https://anaconda.org/conda-forge/pydantic)
7
+ [![downloads](https://static.pepy.tech/badge/pydantic/month)](https://pepy.tech/project/pydantic)
8
+ [![versions](https://img.shields.io/pypi/pyversions/pydantic.svg)](https://github.com/pydantic/pydantic)
9
+ [![license](https://img.shields.io/github/license/pydantic/pydantic.svg)](https://github.com/pydantic/pydantic/blob/main/LICENSE)
10
+ [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges) -->
11
+
12
+ pySWAP is a Python wrapper (not Python implementation) for the SWAP hydrological model developed at Wageningen University and Research ([link to the model website](https://www.swap.alterra.nl/)). It simplifies the creation of input files, execution of the SWAP model, and analysis and visualization of results. Users can set up and document their models in Jupyter notebooks, enhancing transparency, collaboration, and facilitating community-supported debugging.
13
+
14
+ ## Contributing
15
+
16
+ pySWAP is in the early stages of development so any contributions are highly encouraged. You can open issues, submit pull requests, or initiate discussions on GitHub. For more details on how you can contribute, visit the [CONTRIBUTE](./docs/CONTRIBUTING.md) section and get involved!
17
+
18
+ ## Help
19
+
20
+ Consult pySWAP [documentation](https://docs.pydantic.dev/) page for detailed instructions.
21
+
22
+ ## Installation
23
+
24
+ As this is still a development version, the package is only available through GitHub.
25
+ You can install it by cloning the repository and installing it in your environment using
26
+ pip:
27
+
28
+ ```shell
29
+ git clone --recurse-submodules https://github.com/zawadzkim/pySWAP.git
30
+ ```
31
+
32
+ Then go inside the freshly cloned repo and type:
33
+
34
+ ```Shell
35
+ pip install .
36
+ ```
37
+
38
+ If you would like to adapt the software and share it, install it in interactive mode:
39
+
40
+ ```Shell
41
+ pip install -e .
42
+ ```
43
+
44
+ <!-- ## Reporting a Security Vulnerability
45
+
46
+ See our [security policy](https://github.com/pydantic/pydantic/security/policy). -->
@@ -0,0 +1,26 @@
1
+ [tool.poetry]
2
+ name = "pyswap"
3
+ version = "0.1.0"
4
+ description = "Python wrapper for SWAP hydrological model."
5
+ authors = ["Mateusz <zawadzkimat@outlook.com>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.11"
11
+ pandas = "^2.2.2"
12
+ numpy = "^1.26.4"
13
+ pydantic = "^2.7.4"
14
+ knmi-py = "^0.1.10"
15
+ jupyter = "^1.0.0"
16
+
17
+
18
+ [tool.poetry.group.dev.dependencies]
19
+ mkdocs-material = "^9.5.27"
20
+ mkdocs-include-markdown-plugin = "^6.2.0"
21
+ mkdocs-autorefs = "^1.0.1"
22
+ mkdocstrings-python = "^1.10.3"
23
+
24
+ [build-system]
25
+ requires = ["poetry-core"]
26
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,3 @@
1
+ from .simsettings import Metadata, GeneralSettings, RichardsSettings
2
+ from .atmosphere import Meteorology, MetFile
3
+ from .boundary import BottomBoundary
@@ -0,0 +1,13 @@
1
+ """
2
+ # Atmosphere subpackage
3
+
4
+ Meteorological settings and data for SWAP simulations.
5
+
6
+ Modules:
7
+ metfile: meteorological data for SWAP simulations
8
+ meteorology: meteorological settings for SWAP simulations
9
+ ___________________________________________________________________________
10
+ """
11
+
12
+ from .meteorology import *
13
+ from .metfile import *
@@ -0,0 +1,123 @@
1
+ """
2
+ Meteorological settings for SWAP simulations.
3
+
4
+ !!! note
5
+ `Meteorology` object requires the `MetFile` object to be passed upon initialization. When the model is run,
6
+ the `MetFile` object is saved to a .met file.
7
+
8
+ Classes:
9
+ Meteorology: Holds the settings of the meteo section of the .swp file.
10
+ """
11
+
12
+ from ..core.basemodel import PySWAPBaseModel
13
+ from ..core.fields import Table
14
+ from ..core.files import save_file
15
+ from ..core.valueranges import UNITRANGE
16
+ from .metfile import MetFile
17
+ from pydantic import Field, model_validator
18
+ from typing import Optional, Literal
19
+
20
+
21
+ class Meteorology(PySWAPBaseModel):
22
+ """Meteorological settings of the simulation.
23
+
24
+ Attributes:
25
+ lat (float): latitude of the meteo station [degrees].
26
+ swetr (int): Switch type of weather data for potential evapotranspiration:
27
+
28
+ * 0 - Use basic weather data and apply Penman-Monteith equation.
29
+ * 1 - Use reference evapotranspiration data in combination with crop factors.
30
+
31
+ swdivide (int): Switch for distribution of E and T. Defaults to 0:
32
+
33
+ * 0 - Based on crop and soil factors.
34
+ * 1 - Based on direct application of Penman-Monteith.
35
+
36
+ swmetdetail (int): Switch for time interval of evapotranspiration and rainfall weather data:
37
+
38
+ * 0 - Daily data.
39
+ * 1 - Subdaily data.
40
+
41
+ swrain (int): Switch for use of actual rainfall intensity, defaults to 0:
42
+
43
+ * 0 - Use daily rainfall amounts.
44
+ * 1 - Use daily rainfall amounts + mean intensity.
45
+ * 2 - Use daily rainfall amounts + duration.
46
+ * 3 - Use detailed rainfall records (dt < 1 day), as supplied in separate file.
47
+
48
+ swetsine (int): Switch, distribute daily Tp and Ep according to sinus wave, default to 0:
49
+
50
+ * 0 - No distribution.
51
+ * 1 - Distribute Tp and Ep according to sinus wave.
52
+
53
+ metfile (MetFile): MetFile model containing meteorological data to be saved to .met file.
54
+ alt (float): Altitude of the meteo station [m].
55
+ altw (float): Altitude of the wind [m].
56
+ angstroma (float): Fraction of extraterrestrial radiation reaching the earth on overcast days.
57
+ angstromb (float): Additional fraction of extraterrestrial radiation reaching the earth on clear days.
58
+ table_rainflux (Table): rainfall intensity RAINFLUX as function of time TIME.
59
+ rainfil (str): file name of file with detailed rainfall data.
60
+ nmetdetail (int): Number of weather data records each day.
61
+
62
+ Methods:
63
+ write_met: Write the .met file.
64
+ """
65
+
66
+ # metfil: str
67
+ lat: float = Field(ge=-90, le=90)
68
+ swetr: Literal[0, 1]
69
+ swdivide: Literal[0, 1]
70
+ # TODO: SWRAIN should be optional, but Fortran code evaluates its presence anyway
71
+ swrain: Optional[Literal[0, 1, 2, 3]] = 0
72
+ # TODO: SWETSINE should be optional, but Fortran code evaluates its presence anyway
73
+ swetsine: Literal[0, 1] = 0
74
+ metfile: Optional[MetFile] = Field(
75
+ default=None, repr=False)
76
+ alt: float = Field(ge=-400.0, le=3000.0)
77
+ altw: float = Field(default=None, ge=0.0, le=99.0)
78
+ angstroma: float = Field(default=None, **UNITRANGE)
79
+ angstromb: float = Field(default=None, **UNITRANGE)
80
+ swmetdetail: Optional[Literal[0, 1]] = None
81
+ table_rainflux: Optional[Table] = None
82
+ rainfil: Optional[str] = None
83
+ nmetdetail: Optional[int] = Field(default=None, ge=1, le=96)
84
+
85
+ @model_validator(mode='after')
86
+ def _validate_meteo_section(self):
87
+
88
+ if self.swetr == 1: # if PM method is NOT used
89
+ assert self.swetsine is not None, "SWETSINE is required when SWETR is 1"
90
+ assert self.swrain is not None, "SWRAIN is required when SWETR is 1"
91
+ if self.swrain == 1:
92
+ assert self.table_rainflux is not None, "RAINFLUX is required when SWRAIN is 1"
93
+ elif self.swrain == 3:
94
+ assert self.rainfil, "RAINFIL is required when SWRAIN is 3"
95
+
96
+ else:
97
+ assert self.alt is not None, "alt settings are required when SWETR is 0"
98
+ assert self.altw is not None, "altw settings are required when SWETR is 0"
99
+ assert self.angstroma is not None, "angstroma settings are required when SWETR is 0"
100
+ assert self.angstromb is not None, "angstromb settings are required when SWETR is 0"
101
+ assert self.swmetdetail is not None, "SWMETDETAIL is required when SWETR is 0"
102
+ if self.swmetdetail == 1:
103
+ assert self.nmetdetail is not None, "NMETDETAIL is required when SWMETDETAIL is 1"
104
+
105
+ def write_met(self, path: str):
106
+ """Write the .met file.
107
+
108
+ !!! note
109
+
110
+ in this function the extension is not passed because
111
+ swp file requires the metfile parameter to be passed already with
112
+ the extension.
113
+
114
+ Parameters:
115
+ path (str): Path to the file.
116
+ """
117
+ save_file(
118
+ string=self.metfile.content.to_csv(index=False),
119
+ fname=self.metfile.metfil,
120
+ path=path
121
+ )
122
+
123
+ print(f'{self.metfile.metfil} saved.')
@@ -0,0 +1,107 @@
1
+ """
2
+ Getting and formatting meteorological data for SWAP similation.
3
+
4
+ Classes:
5
+ MetFile: meteorological data for the .met file
6
+
7
+ Functions:
8
+ load_from_csv: loading meteorological data from a CSV file
9
+ load_from_knmi: retrieving meteorological data from KNMI API
10
+ """
11
+
12
+ from typing import Optional, Literal
13
+ from pandas import read_csv
14
+ from datetime import datetime as dt
15
+ from knmi import get_day_data_dataframe, get_hour_data_dataframe
16
+ from ..core import PySWAPBaseModel
17
+ from ..core import CSVTable
18
+ from pydantic import Field
19
+
20
+
21
+ class MetFile(PySWAPBaseModel):
22
+ """Meteorological data for the .met file.
23
+
24
+ This object is created by functions fetching or loading meteorological data
25
+ from various sources. The data is stored as a pandas.DataFrame, but is formatted
26
+ with a custom field serializer of the CSVTable field type.
27
+
28
+ Attributes:
29
+ metfil (str): name of the .met file
30
+ content (CSVTable): meteorological data file
31
+ """
32
+
33
+ metfil: str
34
+ content: Optional[CSVTable] = Field(default=None, exclude=True)
35
+
36
+
37
+ def load_from_csv(metfil: str, csv_path: str, **kwargs) -> MetFile:
38
+ """Method for loading meteorological data from a CSV file.
39
+
40
+ Parameters:
41
+ metfil (str): name of the .met file
42
+ csv_path (str): path to the CSV file
43
+ **kwargs (dict): keyword arguments for pandas.read_csv
44
+
45
+ Returns:
46
+ MetFile object.
47
+ """
48
+
49
+ return MetFile(metfil=metfil, content=read_csv(csv_path, **kwargs))
50
+
51
+
52
+ def load_from_knmi(metfil: str,
53
+ stations: str | list,
54
+ variables: str | list = [
55
+ 'TEMP', 'PRCP', 'Q', 'UG', 'FG', 'UX', 'UN'],
56
+ start: str | dt = '20000101',
57
+ end: str | dt = '20200101',
58
+ frequency: Literal['day', 'hour'] = 'day',
59
+ inseason: bool = False) -> MetFile:
60
+ """Retrieves the meteorological data from KNMI API using knmi-py.
61
+
62
+ Parameters:
63
+ metfil (str): name of the .met file
64
+ stations (str | list): station number(s) to retrieve data from
65
+ variables (str | list): variables to retrieve
66
+ start (str | dt): start date of the data
67
+ end (str | dt): end date of the data
68
+ frequency (Literal['day', 'hour']): frequency of the data (day or hour)
69
+ inseason (bool): whether to retrieve in-season data
70
+
71
+ Returns:
72
+ MetFile object.
73
+ """
74
+
75
+ if isinstance(stations, str):
76
+ stations = [stations]
77
+ if isinstance(variables, str):
78
+ variables = [variables]
79
+
80
+ get_func = get_day_data_dataframe if frequency == 'day' else get_hour_data_dataframe
81
+
82
+ df = get_func(stations=stations,
83
+ start=start,
84
+ end=end,
85
+ variables=variables,
86
+ inseason=inseason)
87
+
88
+ # rename some columns
89
+ required_column_names = {'STN': 'Station',
90
+ 'TN': 'Tmin',
91
+ 'TX': 'Tmax',
92
+ 'UG': 'HUM',
93
+ 'DR': 'WET',
94
+ 'FG': 'WIND',
95
+ 'RH': 'RAIN',
96
+ 'EV24': 'ETref',
97
+ 'Q': 'RAD'}
98
+
99
+ df = df.rename(columns=required_column_names)
100
+
101
+ # recalculation of the parameters
102
+ df[['Tmin', 'Tmax', 'ETref', 'RAIN', 'WIND']] = df[['Tmin', 'Tmax', 'ETref', 'RAIN',
103
+ 'WIND']] * 0.1 # the original unit is 0.1 Unit
104
+ df['WET'] = df['WET'] * \
105
+ 0.1 * 24 # the required unit is days
106
+
107
+ return MetFile(metfil=metfil, content=df)
@@ -0,0 +1,34 @@
1
+ from ..core.tablevalidation import BaseModel
2
+ from pandera.typing import Series
3
+ import pandera as pa
4
+
5
+ class DAILYMETEODATA(BaseModel):
6
+ Station: Series[str]
7
+ DD: Series[str]
8
+ MM: Series[str]
9
+ YYYY: Series[str]
10
+ RAD: Series[float]
11
+ Tmin: Series[float]
12
+ Tmax: Series[float]
13
+ HUM: Series[float]
14
+ WIND: Series[float]
15
+ RAIN: Series[float]
16
+ ETref: Series[float]
17
+ WET: Series[float]
18
+
19
+ class SHORTINTERVALMETEODATA(BaseModel):
20
+ Date: Series[pa.DateTime]
21
+ Record: Series[int] = pa.Field(ge=1, le=10)
22
+ Rad: Series[float]
23
+ Temp: Series[float]
24
+ Hum: Series[float]
25
+ Wind: Series[float]
26
+ Rain: Series[float]
27
+
28
+ class DETAILEDRAINFALL(BaseModel):
29
+ Station: Series[str]
30
+ Day: Series[int]
31
+ Month: Series[int]
32
+ Year: Series[int]
33
+ Time: Series[float]
34
+ Amount: Series[float]
@@ -0,0 +1,9 @@
1
+ """
2
+ # Boundary subpackage
3
+
4
+ This subpackage deals with boundary conditions for the SWAP model.
5
+
6
+ Modules:
7
+ bottomboundary: Bottom boundary condition settings for the SWAP model.
8
+ """
9
+ from .boundary import BottomBoundary
@@ -0,0 +1,146 @@
1
+ """
2
+ Bottom boundary condition settings for the SWAP model.
3
+
4
+ Classes:
5
+ BottomBoundary: Holds the settings of the bottom boundary conditions of the .swp file.
6
+ """
7
+
8
+ from typing import Optional, Literal
9
+ from pydantic import model_validator, Field
10
+ from ..core import PySWAPBaseModel
11
+ from ..core import Table
12
+
13
+
14
+ class BottomBoundary(PySWAPBaseModel):
15
+ """
16
+ Bottom boundary settings for SWAP model.
17
+
18
+ Attributes:
19
+ swbbcfile (Literal[0, 1]): Switch for file with bottom boundary data:
20
+
21
+ * 0 - data are specified in current file
22
+ * 1 - data are specified in separate file
23
+
24
+ swbotb (Literal[1, 2, 3, 4, 5, 6, 7, 8]): Switch for type of bottom boundary.
25
+
26
+ * 1 - prescribe groundwater level;
27
+ * 2 - prescribe bottom flux;
28
+ * 3 - calculate bottom flux from hydraulic head of deep aquifer;
29
+ * 4 - calculate bottom flux as function of groundwater level;
30
+ * 5 - prescribe soil water pressure head of bottom compartment;
31
+ * 6 - bottom flux equals zero;
32
+ * 7 - free drainage of soil profile;
33
+ * 8 - free outflow at soil-air interface.
34
+
35
+ sw2 (Optional[Literal[1, 2]]): Specify whether a sinus function or a table are used for the bottom flux.
36
+
37
+ * 1 - sinus function;
38
+ * 2 - table.
39
+
40
+ sw3 (Optional[Literal[1, 2]]): Specify whether a sinus function or a table are used for the hydraulic head in the deep aquifer.
41
+
42
+ * 1 - sinus function;
43
+ * 2 - table.
44
+
45
+ sw4 (Optional[Literal[0, 1]]): An extra groundwater flux can be specified which is added to above specified flux.
46
+
47
+ * 0 - no extra flux;
48
+ * 1 - extra flux.
49
+
50
+ swbotb3resvert (Optional[Literal[0, 1]]): Switch for vertical hydraulic resistance between bottom boundary and groundwater level.
51
+
52
+ * 0 - Include vertical hydraulic resistance
53
+ * 1 - Suppress vertical hydraulic resistance
54
+
55
+ swbotb3impl (Optional[Literal[0, 1]]): Switch for numerical solution of bottom flux.
56
+
57
+ * 0 - Explicit solution (choose always when SHAPE < 1.0);
58
+ * 1 - Implicit solution.
59
+
60
+ swqhbot (Optional[Literal[1, 2]]): Specify whether an exponential relation or a table is used.
61
+
62
+ * 1 - bottom flux is calculated with an exponential relation
63
+ * 2 - bottom flux is derived from a table
64
+
65
+ bbcfile (Optional[str]): Name of file with bottom boundary data (without .BBC extension).
66
+ sinave (Optional[float]): Average value of bottom flux.
67
+ sinamp (Optional[float]): Amplitude of bottom flux sine function.
68
+ sinmax (Optional[float]): Time of the year with maximum bottom flux.
69
+ shape (Optional[float]): Shape factor to derive average groundwater level.
70
+ hdrain (Optional[float]): Mean drain base to correct for average groundwater level.
71
+ rimlay (Optional[float]): Vertical resistance of aquitard.
72
+ aqave (Optional[float]): Average hydraulic head in underlaying aquifer.
73
+ aqamp (Optional[float]): Amplitude hydraulic head sinus wave.
74
+ aqtmax (Optional[float]): First time of the year with maximum hydraulic head.
75
+ aqper (Optional[float]): Period of hydraulic head sinus wave.
76
+ cofqha (Optional[float]): Coefficient A for exponential relation for bottom flux.
77
+ cofqhb (Optional[float]): Coefficient B for exponential relation for bottom flux.
78
+ cofqhc (Optional[float]): Coefficient C for exponential relation for bottom flux.
79
+ gwlevel (Optional[Table]): Table with groundwater level data.
80
+ table_qbot (Optional[Table]): Table with bottom flux data.
81
+ table_haquif (Optional[Table]): Table with average pressure head in underlaying aquifer.
82
+ table_qbot4 (Optional[Table]): Table with bottom flux data.
83
+ table_qtab (Optional[Table]): Table with groundwater level-bottom flux relation
84
+ table_hbot (Optional[Table]): Table with the bottom compartment pressure head.
85
+ """
86
+
87
+ swbbcfile: Literal[0, 1]
88
+ swbotb: Literal[1, 2, 3, 4, 5, 6, 7, 8]
89
+ sw2: Optional[Literal[1, 2]] = None
90
+ sw3: Optional[Literal[1, 2]] = None
91
+ sw4: Optional[Literal[0, 1]] = None
92
+ swbotb3resvert: Optional[Literal[0, 1]] = None
93
+ swbotb3impl: Optional[Literal[0, 1]] = None
94
+ swqhbot: Optional[Literal[1, 2]] = None
95
+ bbcfile: Optional[str] = None
96
+ sinave: Optional[float] = Field(ge=-10.0, le=10.0, default=None)
97
+ sinamp: Optional[float] = Field(ge=-10.0, le=10.0, default=None)
98
+ sinmax: Optional[float] = Field(ge=0.0, le=366.0, default=None)
99
+ shape: Optional[float] = None
100
+ hdrain: Optional[float] = None
101
+ rimlay: Optional[float] = None
102
+ aqave: Optional[float] = None
103
+ aqamp: Optional[float] = None
104
+ aqtmax: Optional[float] = None
105
+ aqper: Optional[float] = None
106
+ cofqha: Optional[float] = None
107
+ cofqhb: Optional[float] = None
108
+ cofqhc: Optional[float] = None
109
+ table_gwlevel: Optional[Table] = None
110
+ table_qbot: Optional[Table] = None
111
+ table_haquif: Optional[Table] = None
112
+ table_qbot4: Optional[Table] = None
113
+ table_qtab: Optional[Table] = None
114
+ table_hbot5: Optional[Table] = None
115
+
116
+ @model_validator(mode='after')
117
+ def _check_swbotb(self):
118
+ if self.swbotb == 1:
119
+ assert self.gwlevel, 'gwlevel must be provided if swbotb is 1'
120
+ elif self.swbotb == 2:
121
+ assert self.sw2, 'sw2 must be provided if swbotb is 2'
122
+ if self.sw2 == 1:
123
+ assert self.sinave, 'sinave must be provided if sw2 is 1'
124
+ assert self.sinamp, 'sinamp must be provided if sw2 is 1'
125
+ assert self.sinmax, 'sinmax must be provided if sw2 is 1'
126
+ elif self.sw2 == 2:
127
+ assert self.table_qbot, 'qbot must be provided if sw2 is 2'
128
+ elif self.swbotb == 3:
129
+ assert self.sw3, 'sw3 must be provided if swbotb is 3'
130
+ if self.sw3 == 1:
131
+ assert self.aqave, 'aqave must be provided if sw3 is 1'
132
+ assert self.aqamp, 'auamp must be provided if sw3 is 1'
133
+ assert self.aqtmax, 'aqtmax must be provided if sw3 is 1'
134
+ assert self.aqper, 'aqper must be provided if sw3 is 1'
135
+ elif self.sw3 == 2:
136
+ assert self.table_haquif, 'haquif must be provided if sw3 is 2'
137
+ elif self.swbotb == 4:
138
+ assert self.swqhbot, 'swqhbot must be provided if swbotb is 4'
139
+ if self.swqhbot == 1:
140
+ assert self.cofqha, 'cofqha must be provided if swqhbot is 1'
141
+ assert self.cofqhb, 'cofqhb must be provided if swqhbot is 1'
142
+ assert self.cofqhc, 'cofqhc must be provided if swqhbot is 1'
143
+ elif self.swqhbot == 2:
144
+ assert self.table_qtab, 'qtab must be provided if swqhbot is 2'
145
+ elif self.swbotb == 5:
146
+ assert self.table_hbot5, 'hbot5 must be provided if swbotb is 5'
@@ -0,0 +1,22 @@
1
+ """
2
+ # Core subpackage
3
+
4
+ Core package containing the main classes and functions for the SWAP model.
5
+
6
+ Modules:
7
+ basemodel: Base model class for pySWAP.
8
+ fields: Field types for pyswap used for serialization.
9
+ files: Functions to interact with file system.
10
+ serializers: Functions to fine tune the serializatino of pySWAP objects.
11
+ valueranges: Objects containing value ranges used is validation of pySWAP objects.
12
+ model: Contains the classes for the model of the simulation.
13
+ result: Contains the classes for the results of the simulation.
14
+ ___________________________________________________________________________
15
+ """
16
+
17
+ from .basemodel import *
18
+ from .fields import *
19
+ from .files import *
20
+ from .serializers import *
21
+ from .valueranges import *
22
+ from .tablevalidation import *