mobidicpy 0.2.0__tar.gz → 0.2.1__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 (59) hide show
  1. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/CITATION.cff +1 -1
  2. {mobidicpy-0.2.0/mobidicpy.egg-info → mobidicpy-0.2.1}/PKG-INFO +2 -2
  3. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/__init__.py +1 -1
  4. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/routing.py +14 -10
  5. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/grid_operations.py +55 -38
  6. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/hillslope_reach_mapping.py +2 -1
  7. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/io.py +1 -1
  8. {mobidicpy-0.2.0 → mobidicpy-0.2.1/mobidicpy.egg-info}/PKG-INFO +2 -2
  9. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidicpy.egg-info/requires.txt +1 -1
  10. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/pyproject.toml +3 -3
  11. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/LICENSE +0 -0
  12. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/MANIFEST.in +0 -0
  13. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/README.md +0 -0
  14. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/__init__.py +0 -0
  15. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/config.py +0 -0
  16. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/forward_model.py +0 -0
  17. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/instruction.py +0 -0
  18. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/metrics.py +0 -0
  19. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/observation.py +0 -0
  20. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/parameter_mapping.py +0 -0
  21. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/pest_setup.py +0 -0
  22. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/results.py +0 -0
  23. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/calibration/template.py +0 -0
  24. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/config/__init__.py +0 -0
  25. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/config/parser.py +0 -0
  26. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/config/schema.py +0 -0
  27. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/__init__.py +0 -0
  28. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/constants.py +0 -0
  29. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/crop_coefficients.py +0 -0
  30. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/energy_balance.py +0 -0
  31. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/groundwater.py +0 -0
  32. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/interpolation.py +0 -0
  33. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/pet.py +0 -0
  34. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/reservoir.py +0 -0
  35. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/simulation.py +0 -0
  36. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/core/soil_water_balance.py +0 -0
  37. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/data/__init__.py +0 -0
  38. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/data/kc_clc_mapping.csv +0 -0
  39. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/io/__init__.py +0 -0
  40. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/io/meteo.py +0 -0
  41. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/io/report.py +0 -0
  42. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/io/state.py +0 -0
  43. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/__init__.py +0 -0
  44. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/gis_reader.py +0 -0
  45. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/hyetograph.py +0 -0
  46. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/meteo_preprocessing.py +0 -0
  47. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/meteo_raster.py +0 -0
  48. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/preprocessor.py +0 -0
  49. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/reservoirs.py +0 -0
  50. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/preprocessing/river_network.py +0 -0
  51. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/py.typed +0 -0
  52. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/utils/__init__.py +0 -0
  53. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/utils/crs.py +0 -0
  54. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidic/utils/logging.py +0 -0
  55. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidicpy.egg-info/SOURCES.txt +0 -0
  56. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidicpy.egg-info/dependency_links.txt +0 -0
  57. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/mobidicpy.egg-info/top_level.txt +0 -0
  58. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/setup.cfg +0 -0
  59. {mobidicpy-0.2.0 → mobidicpy-0.2.1}/tests/test_package.py +0 -0
@@ -9,7 +9,7 @@ authors:
9
9
  - family-names: Castelli
10
10
  given-names: Fabio
11
11
  orcid: "https://orcid.org/0000-0003-0304-0289"
12
- version: "0.2.0"
12
+ version: "0.2.1"
13
13
  repository-code: "https://github.com/mobidichydro/mobidicpy"
14
14
  keywords:
15
15
  - "Hydrology"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mobidicpy
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: MOBIDICpy - Distributed and continuous hydrological balance model
5
5
  Author-email: Matteo Masi <matteo.masi@unifi.it>, Fabio Castelli <fabio.castelli@unifi.it>
6
6
  License-Expression: Apache-2.0
@@ -38,7 +38,7 @@ Requires-Dist: pytest>=7.0; extra == "dev"
38
38
  Requires-Dist: pytest-cov>=4.0; extra == "dev"
39
39
  Requires-Dist: coverage>=7.0; extra == "dev"
40
40
  Requires-Dist: genbadge[coverage]>=1.1.3; extra == "dev"
41
- Requires-Dist: ruff>=0.2.0; extra == "dev"
41
+ Requires-Dist: ruff>=0.2.1; extra == "dev"
42
42
  Requires-Dist: bump-my-version>=1.0; extra == "dev"
43
43
  Provides-Extra: calibration
44
44
  Requires-Dist: pyemu>=1.4.0; extra == "calibration"
@@ -1,6 +1,6 @@
1
1
  """MOBIDIC - Distributed and continuous hydrological balance model."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.2.1"
4
4
 
5
5
  from mobidic.config import MOBIDICConfig
6
6
  from mobidic.config import load_config
@@ -98,16 +98,20 @@ def hillslope_routing(
98
98
  Each cell contains ONLY flow from immediate upstream neighbors (NOT its own flow).
99
99
 
100
100
  Notes:
101
- Flow direction coding (D8) - MOBIDIC convention from MATLAB stack8point.m:
102
- MOBIDIC notation (1-8):
103
- 7 6 5
104
- 8 · 4
105
- 1 2 3
106
-
107
- Direction number -> (row_offset, col_offset) in matrix coordinates:
108
- 1: (-1, -1) northwest, 2: (-1, 0) north, 3: (-1, 1) northeast,
109
- 4: (0, 1) east, 5: (1, 1) southeast, 6: (1, 0) south,
110
- 7: (1, -1) southwest, 8: (0, -1) west
101
+ Flow direction coding (D8) - MOBIDIC convention from MATLAB stack8point.m.
102
+ Rasters are loaded with `np.flipud` (in `grid_to_matrix`) so that increasing
103
+ row index corresponds to moving NORTH; the codes/offsets below assume that
104
+ orientation.
105
+
106
+ MOBIDIC notation (1-8, CCW from SW; north up):
107
+ 7 6 5 (NW N NE)
108
+ 8 · 4 (W E)
109
+ 1 2 3 (SW S SE)
110
+
111
+ Direction number -> compass direction -> (row_offset, col_offset):
112
+ 1: SW (-1, -1), 2: S (-1, 0), 3: SE (-1, +1),
113
+ 4: E ( 0, +1), 5: NE (+1, +1), 6: N (+1, 0),
114
+ 7: NW (+1, -1), 8: W ( 0, -1)
111
115
 
112
116
  Special values:
113
117
  0: Outlet cell (no downstream neighbor)
@@ -107,11 +107,12 @@ def decimate_flow_direction(
107
107
  Flow accumulation is normalized by factor **2 to account for cell size change.
108
108
 
109
109
  Notes:
110
- This function assumes flow_dir uses Grass 1-8 notation:
110
+ This function operates on flow_dir BEFORE conversion to MOBIDIC notation,
111
+ so input is expected in standard GRASS r.watershed 1-8 notation:
111
112
  1=NE, 2=N, 3=NW, 4=W, 5=SW, 6=S, 7=SE, 8=E
112
113
 
113
114
  Examples:
114
- >>> flow_dir = np.array([[2, 2], [2, 2]]) # All cells flow north
115
+ >>> flow_dir = np.array([[2, 2], [2, 2]]) # All cells flow north (Grass code 2)
115
116
  >>> flow_acc = np.array([[1, 1], [3, 4]]) # Different accumulation
116
117
  >>> dec_dir, dec_acc = decimate_flow_direction(flow_dir, flow_acc, factor=2)
117
118
  """
@@ -137,10 +138,11 @@ def decimate_flow_direction(
137
138
  flow_dir_decimated = np.full((nrv, ncv), np.nan, dtype=float)
138
139
  flow_acc_decimated = np.full((nrv, ncv), np.nan, dtype=float)
139
140
 
140
- # Direction offsets for Grass 1-8 notation to MOBIDIC notation
141
- # 1=NE, 2=N, 3=NW, 4=W, 5=SW, 6=S, 7=SE, 8=E
141
+ # Direction offsets indexed by code-1, in standard GRASS r.watershed notation
142
+ # (1=NE, 2=N, 3=NW, 4=W, 5=SW, 6=S, 7=SE, 8=E). Offsets are matrix-coord
143
+ # (row, col) where row+1 = down (image orientation, before any flipud).
142
144
  di = np.array([-1, -1, -1, 0, 1, 1, 1, 0]) # row offset
143
- dj = np.array([-1, 0, 1, 1, 1, 0, -1, -1]) # column offset
145
+ dj = np.array([1, 0, -1, -1, -1, 0, 1, 1]) # column offset
144
146
 
145
147
  # Minimum number of valid cells required
146
148
  min_valid_cells = int(factor * factor * min_valid_fraction)
@@ -204,17 +206,17 @@ def decimate_flow_direction(
204
206
  flow_dir_decimated[i, j] = -999
205
207
  continue
206
208
 
207
- # Map coarse cell offset to direction (1-8)
208
- # coarse_di, coarse_dj -> direction
209
+ # Map coarse cell offset to direction (1-8) in standard GRASS r.watershed
210
+ # convention (image orientation, row+1 = down).
209
211
  offset_to_dir = {
210
- (-1, -1): 1, # NE (IP=-1, JP=-1 -> -11 -> case 1)
211
- (-1, 0): 2, # N (IP=-1, JP=0 -> -10 -> case 2)
212
- (-1, 1): 3, # NW (IP=-1, JP=1 -> -9 -> case 3)
213
- (0, 1): 4, # W (IP=0, JP=1 -> 1 -> case 4)
214
- (1, 1): 5, # SW (IP=1, JP=1 -> 11 -> case 5)
215
- (1, 0): 6, # S (IP=1, JP=0 -> 10 -> case 6)
216
- (1, -1): 7, # SE (IP=1, JP=-1 -> 9 -> case 7)
217
- (0, -1): 8, # E (IP=0, JP=-1 -> -1 -> case 8)
212
+ (-1, 1): 1, # NE
213
+ (-1, 0): 2, # N
214
+ (-1, -1): 3, # NW
215
+ (0, -1): 4, # W
216
+ (1, -1): 5, # SW
217
+ (1, 0): 6, # S
218
+ (1, 1): 7, # SE
219
+ (0, 1): 8, # E
218
220
  }
219
221
 
220
222
  flow_dir_decimated[i, j] = offset_to_dir.get((coarse_di, coarse_dj), -999)
@@ -253,9 +255,13 @@ def convert_to_mobidic_notation(
253
255
  ) -> np.ndarray:
254
256
  """Convert flow direction from Grass or Arc notation to MOBIDIC notation.
255
257
 
256
- MOBIDIC uses a transformed version of the Grass notation with a 180-degree rotation.
257
- This transformation is applied in MATLAB's buildgis_mysql_include.m:
258
- AI=[1 2 3 4 5 6 7 8]; MD=[5 6 7 8 1 2 3 4];
258
+ Translates standard GRASS r.watershed (1-8) or ESRI ArcGIS (powers of 2) flow
259
+ direction codes to MOBIDIC's internal D8 encoding. The renumbering is
260
+ direction-preserving (each input code maps to the MOBIDIC code with the same
261
+ physical compass direction). The mapping matches MATLAB's
262
+ buildgis_mysql_include.m:
263
+ GRASS: AI=[1 2 3 4 5 6 7 8]; MD=[5 6 7 8 1 2 3 4];
264
+ ArcGIS: AI=[1 2 4 8 16 32 64 128]; MD=[4 3 2 1 8 7 6 5];
259
265
 
260
266
  Args:
261
267
  flow_dir: 2D numpy array with flow directions (NaN for nodata).
@@ -265,25 +271,36 @@ def convert_to_mobidic_notation(
265
271
  Flow direction array converted to MOBIDIC notation (1-8).
266
272
 
267
273
  Notes:
268
- Transformation mappings:
269
- - GRASS -> MOBIDIC: 1->5, 2->6, 3->7, 4->8, 5->1, 6->2, 7->3, 8->4
270
- - Arc values are first converted to Grass, then to MOBIDIC
271
-
272
- Notation comparison:
273
- GRASS: MOBIDIC:
274
- 7 6 5 3 2 1
275
- 8 4 4 8
276
- 1 2 3 5 6 7
277
-
278
- MOBIDIC directions:
279
- 1: up-right (row -1, col +1)
280
- 2: up (row -1, col 0)
281
- 3: up-left (row -1, col -1)
282
- 4: left (row 0, col -1)
283
- 5: down-left (row +1, col -1)
284
- 6: down (row +1, col 0)
285
- 7: down-right (row +1, col +1)
286
- 8: right (row 0, col +1)
274
+ Standard GRASS r.watershed convention (1-8, CCW from NE; north up):
275
+
276
+ 3 2 1 1 = NE 5 = SW
277
+ 4 . 8 2 = N 6 = S
278
+ 5 6 7 3 = NW 7 = SE
279
+ 4 = W 8 = E
280
+
281
+ Standard ESRI ArcGIS convention (powers of 2, CW from E; north up):
282
+
283
+ 32 64 128 1 = E 16 = W
284
+ 16 . 1 2 = SE 32 = NW
285
+ 8 4 2 4 = S 64 = N
286
+ 8 = SW 128 = NE
287
+
288
+ MOBIDIC convention (1-8, CCW from SW; north up):
289
+
290
+ 7 6 5 1 = SW 5 = NE
291
+ 8 . 4 2 = S 6 = N
292
+ 1 2 3 3 = SE 7 = NW
293
+ 4 = E 8 = W
294
+
295
+ Direction-preserving mapping:
296
+ GRASS -> MOBIDIC: 1->5, 2->6, 3->7, 4->8, 5->1, 6->2, 7->3, 8->4
297
+ ArcGIS -> MOBIDIC: 1->4, 2->3, 4->2, 8->1, 16->8, 32->7, 64->6, 128->5
298
+
299
+ Array orientation: rasters are loaded by `grid_to_matrix()` with `np.flipud`
300
+ so that increasing row index corresponds to moving NORTH. With that
301
+ orientation, MOBIDIC code k drains to the neighbor at offset
302
+ (di, dj) where di = `[-1,-1,-1,0,1,1,1,0][k-1]` and
303
+ dj = `[-1,0,1,1,1,0,-1,-1][k-1]`. For example, code 5 (NE) -> (+1, +1).
287
304
 
288
305
  Examples:
289
306
  >>> flow_dir_grass = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 1]])
@@ -298,7 +315,7 @@ def convert_to_mobidic_notation(
298
315
  grass_to_mobidic = {1: 5, 2: 6, 3: 7, 4: 8, 5: 1, 6: 2, 7: 3, 8: 4}
299
316
 
300
317
  # Arc to GRASS mapping
301
- arc_to_grass = {1: 8, 2: 1, 4: 2, 8: 3, 16: 4, 32: 5, 64: 6, 128: 7}
318
+ arc_to_grass = {1: 8, 2: 7, 4: 6, 8: 5, 16: 4, 32: 3, 64: 2, 128: 1}
302
319
 
303
320
  # Create output array
304
321
  converted = flow_dir.copy()
@@ -229,7 +229,8 @@ def map_hillslope_to_reach(
229
229
 
230
230
  logger.debug(f"Lookup table built: {len(cell_to_reach)} reach cells")
231
231
 
232
- # Direction offsets for MOBIDIC notation (1-8)
232
+ # Direction offsets for MOBIDIC notation (1-8, CCW from SW; north up).
233
+ # Code k (1..8) -> (di[k-1], dj[k-1]); e.g. 1=SW -> (-1,-1), 5=NE -> (+1,+1).
233
234
  di = np.array([-1, -1, -1, 0, 1, 1, 1, 0]) # row offset (matches i8)
234
235
  dj = np.array([-1, 0, 1, 1, 1, 0, -1, -1]) # column offset (matches j8)
235
236
 
@@ -114,7 +114,7 @@ def save_gisdata(gisdata: "GISData", output_path: str | Path) -> None:
114
114
  "long_name": "Flow Direction",
115
115
  "units": "1",
116
116
  "description": "Flow direction in MOBIDIC notation (1-8)",
117
- "notation": "MOBIDIC: 1=NE, 2=N, 3=NW, 4=W, 5=SW, 6=S, 7=SE, 8=E",
117
+ "notation": "MOBIDIC: 1=SW, 2=S, 3=SE, 4=E, 5=NE, 6=N, 7=NW, 8=W (north up; row+1=N)",
118
118
  "grid_mapping": "crs",
119
119
  }
120
120
  ds["flow_acc"].attrs = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mobidicpy
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: MOBIDICpy - Distributed and continuous hydrological balance model
5
5
  Author-email: Matteo Masi <matteo.masi@unifi.it>, Fabio Castelli <fabio.castelli@unifi.it>
6
6
  License-Expression: Apache-2.0
@@ -38,7 +38,7 @@ Requires-Dist: pytest>=7.0; extra == "dev"
38
38
  Requires-Dist: pytest-cov>=4.0; extra == "dev"
39
39
  Requires-Dist: coverage>=7.0; extra == "dev"
40
40
  Requires-Dist: genbadge[coverage]>=1.1.3; extra == "dev"
41
- Requires-Dist: ruff>=0.2.0; extra == "dev"
41
+ Requires-Dist: ruff>=0.2.1; extra == "dev"
42
42
  Requires-Dist: bump-my-version>=1.0; extra == "dev"
43
43
  Provides-Extra: calibration
44
44
  Requires-Dist: pyemu>=1.4.0; extra == "calibration"
@@ -21,7 +21,7 @@ pytest>=7.0
21
21
  pytest-cov>=4.0
22
22
  coverage>=7.0
23
23
  genbadge[coverage]>=1.1.3
24
- ruff>=0.2.0
24
+ ruff>=0.2.1
25
25
  bump-my-version>=1.0
26
26
 
27
27
  [doc]
@@ -40,7 +40,7 @@ license = "Apache-2.0"
40
40
  name = "mobidicpy"
41
41
  readme = {file = "README.md", content-type = "text/markdown"}
42
42
  requires-python = ">=3.11"
43
- version = "0.2.0"
43
+ version = "0.2.1"
44
44
 
45
45
 
46
46
  [project.optional-dependencies]
@@ -49,7 +49,7 @@ dev = [
49
49
  "pytest-cov>=4.0",
50
50
  "coverage>=7.0",
51
51
  "genbadge[coverage]>=1.1.3",
52
- "ruff>=0.2.0",
52
+ "ruff>=0.2.1",
53
53
  "bump-my-version>=1.0",
54
54
  ]
55
55
  calibration = [
@@ -136,7 +136,7 @@ force-single-line = true
136
136
  no-lines-before = ["future","standard-library","third-party","first-party","local-folder"]
137
137
 
138
138
  [tool.bumpversion]
139
- current_version = "0.2.0"
139
+ current_version = "0.2.1"
140
140
 
141
141
  [[tool.bumpversion.files]]
142
142
  filename = "mobidic/__init__.py"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes