Coverage for C:\src\imod-python\imod\msw\ponding.py: 48%

23 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-08 10:26 +0200

1import pandas as pd 

2 

3from imod.msw.fixed_format import VariableMetaData 

4from imod.msw.pkgbase import MetaSwapPackage 

5 

6 

7class Ponding(MetaSwapPackage): 

8 """ 

9 Set ponding related parameters for MetaSWAP. This class is responsible for 

10 the svat2swnr_roff.inp file. Currently, we do not support ponds coupled to 

11 SIMGRO's surface water module. 

12 

13 Parameters 

14 ---------- 

15 ponding_depth: array of floats (xr.DataArray) 

16 Ponding depth of the SVAT units in meters. If set to 0. water can freely 

17 flow over the soil surface. Runoff is disable by setting the ponding 

18 depth to 9999 m. Large values, e.g. 1000 m, should be avoided becauses 

19 this causes excess memory use. This array must have a subunit coordinate 

20 to describe different land uses. 

21 runoff_resistance: array of floats (xr.DataArray) 

22 Runoff resistance of SVAT units in days. This array must have a subunit 

23 coordinate to describe different land uses. 

24 runon_resistance: array of floats (xr.DataArray) 

25 Runon resistance of SVAT units in days. This array must have a subunit 

26 coordinate to describe different land uses. 

27 """ 

28 

29 _file_name = "svat2swnr_roff.inp" 

30 _metadata_dict = { 

31 "svat": VariableMetaData(10, 1, 99999999, int), 

32 "swnr": VariableMetaData(10, 0, 99999999, int), 

33 "ponding_depth": VariableMetaData(8, 0.0, 1e6, float), 

34 "runoff_resistance": VariableMetaData(8, 0.0, 1e6, float), 

35 "runon_resistance": VariableMetaData(8, 0.0, 1e6, float), 

36 } 

37 

38 _with_subunit = ("ponding_depth", "runoff_resistance", "runon_resistance") 

39 _without_subunit = () 

40 _to_fill = () 

41 

42 def __init__(self, ponding_depth, runon_resistance, runoff_resistance) -> None: 

43 super().__init__() 

44 self.dataset["ponding_depth"] = ponding_depth 

45 self.dataset["runon_resistance"] = runon_resistance 

46 self.dataset["runoff_resistance"] = runoff_resistance 

47 

48 self._pkgcheck() 

49 

50 def _render(self, file, index, svat): 

51 data_dict = {"svat": svat.values.ravel()[index]} 

52 

53 for var in self._with_subunit: 

54 data_dict[var] = self._index_da(self.dataset[var], index) 

55 

56 data_dict["swnr"] = 0 

57 

58 dataframe = pd.DataFrame( 

59 data=data_dict, columns=list(self._metadata_dict.keys()) 

60 ) 

61 

62 self._check_range(dataframe) 

63 

64 return self.write_dataframe_fixed_width(file, dataframe)