Coverage for C:\src\imod-python\imod\msw\landuse.py: 98%

1 from imod.msw.fixed_format import VariableMetaData

2 from imod.msw.pkgbase import MetaSwapPackage

3

4

5 class LanduseOptions(MetaSwapPackage):

6 """

7 Land use options. This object is responsible for luse_svat.inp

8

9 Parameters

10 ----------

11 landuse_name: array of strings (xr.DataArray)

12 Names of land use

13 vegetation_index: array of integers (xr.DataArray)

14 Vegetation indices

15 jarvis_o2_stress: array of floats (xr.DataArray)

16 Jarvis parameter for oxygen stress

17 jarvis_drought_stress: array of floats (xr.DataArray)

18 Jarvis parameter for drought stress

19 feddes_p1: array of floats (xr.DataArray)

20 p1 (m) in Feddes function for transpiration reduction

21 feddes_p2: array of floats (xr.DataArray)

22 p2 (m) in Feddes function for transpiration reduction

23 feddes_p3h: array of floats (xr.DataArray)

24 p3h (m) in Feddes function for transpiration reduction

25 feddes_p3l: array of floats (xr.DataArray)

26 p3l (m) in Feddes function for transpiration reduction

27 feddes_p4: array of floats (xr.DataArray)

28 p4 (m) in Feddes function for transpiration reduction

29 feddes_t3h: array of floats (xr.DataArray)

30 t3h (mm/d) in Feddes function for transpiration reduction

31 feddes_t3l: array of floats (xr.DataArray)

32 t3l (mm/d) in Feddes function for transpiration reduction

33 threshold_sprinkling: array of floats (xr.DataArray)

34 If <0, pressure head (m) at which sprinkling begins. If >0 drought

35 stress at which sprinkling begins.

36 fraction_evaporated_sprinkling: array of floats (xr.DataArray)

37 Fraction evaporated sprinkling water

38 gift: array of floats (xr.DataArray)

39 Gift (mm) during rotational period

40 gift_duration: array of floats (xr.DataArray)

41 Gift duration (d)

42 rotational_period: array of floats (xr.DataArray)

43 Rotational period (d)

44 start_sprinkling_season: array of floats (xr.DataArray)

45 Day of year at which sprinkling season starts (d)

46 end_sprinkling_season: array of floats (xr.DataArray)

47 Day of year at which sprinkling season ends (d)

48 interception_option: array of integers (xr.DataAray)

49 Choose interception model. 0=Rutter, 1=Von Hoyningen. NOTE: option

50 2=GASH, but this is not supported by MetaSWAP v8.1.0.3 and lower

51 interception_capacity_per_LAI: array of floats (xr.DataArray)

52 Interception capacity (mm/LAI) will be set for both Rutter and Von

53 Hoyningen.

54 interception_intercept: array of floats (xr.DataArray)

55 Intercept of the interception evaporation curve. Pun unintended.

56

57 Notes

58 -----

59 No Penman-Monteith is supported in iMOD Python, so albedo, rsc, rsw, rsoil,

60 kdif, and kdir cannot be specified. (We might create a seperate object for

61 this if there is a demand for it.)

62

63 The GASH model (interception_option = 2) and salt stress parameters Maas &

64 Hoffman are not supported by MetaSWAP at the time of writing this class. So

65 these are not supported.

66 """

67

68 _metadata_dict = {

69 "landuse_index": VariableMetaData(6, 1, 999, int),

70 "landuse_name": VariableMetaData(20, None, None, str),

71 "vegetation_index": VariableMetaData(6, 0.0, 1e6, int),

72 # Jarvis stress

73 # Columns 33-35 and 36-38, but both F6?

74 "jarvis_o2_stress": VariableMetaData(3, 0.0, 1e6, float),

75 "jarvis_drought_stress": VariableMetaData(3, 0.0, 1e6, float),

76 # Feddes transpiration function

77 "feddes_p1": VariableMetaData(8, -160.0, 100.0, float),

78 "feddes_p2": VariableMetaData(8, -160.0, 100.0, float),

79 "feddes_p3h": VariableMetaData(8, -160.0, 0.0, float),

80 "feddes_p3l": VariableMetaData(8, -160.0, 0.0, float),

81 "feddes_p4": VariableMetaData(8, -160.0, 0.0, float),

82 "feddes_t3h": VariableMetaData(8, 0.1, 10.0, float),

83 "feddes_t3l": VariableMetaData(8, 0.1, 10.0, float),

84 # Sprinkling

85 "threshold_sprinkling": VariableMetaData(8, -160.0, 1.0, float),

86 "fraction_evaporated_sprinkling": VariableMetaData(8, 0.0, 1.0, float),

87 "gift": VariableMetaData(8, 1.0, 1000.0, float),

88 "gift_duration": VariableMetaData(8, 0.01, 1000.0, float),

89 "rotational_period": VariableMetaData(6, 1.0, 366.0, float),

90 "start_sprinkling_season": VariableMetaData(6, 0.0, 366.0, float),

91 "end_sprinkling_season": VariableMetaData(6, 0.0, 366.0, float),

92 # Penman-Monteith: not supported

93 "albedo": VariableMetaData(8, None, None, str),

94 "rsc": VariableMetaData(8, None, None, str),

95 "rsw": VariableMetaData(8, None, None, str),

96 "rsoil": VariableMetaData(8, None, None, str),

97 "kdif": VariableMetaData(8, None, None, str),

98 "kdir": VariableMetaData(8, None, None, str),

99 # Interception

100 "interception_option": VariableMetaData(6, 0, 2, int),

101 "interception_capacity_per_LAI_Rutter": VariableMetaData(8, 0.0, 10.0, float),

102 "interception_intercept": VariableMetaData(8, 0.0, 1.0, float),

103 "interception_capacity_per_LAI_VonHoyningen": VariableMetaData(

104 8, 0.0, 10.0, float

105 ),

106 # Gash interception: not supported

107 "pfree": VariableMetaData(8, None, None, str),

108 "pstem": VariableMetaData(8, None, None, str),

109 "scanopy": VariableMetaData(8, None, None, str),

110 "avprec": VariableMetaData(8, None, None, str),

111 "avevap": VariableMetaData(8, None, None, str),

112 # Maas-Hoffman: not supported

113 "saltmax": VariableMetaData(8, None, None, str),

114 "saltslope": VariableMetaData(8, None, None, str),

115 }

116

117 _file_name = "luse_svat.inp"

118

119 def __init__(

120 self,

121 landuse_name,

122 vegetation_index,

123 jarvis_o2_stress,

124 jarvis_drought_stress,

125 feddes_p1,

126 feddes_p2,

127 feddes_p3h,

128 feddes_p3l,

129 feddes_p4,

130 feddes_t3h,

131 feddes_t3l,

132 threshold_sprinkling,

133 fraction_evaporated_sprinkling,

134 gift,

135 gift_duration,

136 rotational_period,

137 start_sprinkling_season,

138 end_sprinkling_season,

139 interception_option,

140 interception_capacity_per_LAI,

141 interception_intercept,

142 ):

143 super().__init__()

144 self.dataset["landuse_name"] = landuse_name

145 self.dataset["vegetation_index"] = vegetation_index

146 self.dataset["jarvis_o2_stress"] = jarvis_o2_stress

147 self.dataset["jarvis_drought_stress"] = jarvis_drought_stress

148 self.dataset["feddes_p1"] = feddes_p1

149 self.dataset["feddes_p2"] = feddes_p2

150 self.dataset["feddes_p3h"] = feddes_p3h

151 self.dataset["feddes_p3l"] = feddes_p3l

152 self.dataset["feddes_p4"] = feddes_p4

153 self.dataset["feddes_t3h"] = feddes_t3h

154 self.dataset["feddes_t3l"] = feddes_t3l

155 self.dataset["threshold_sprinkling"] = threshold_sprinkling

156 self.dataset["fraction_evaporated_sprinkling"] = fraction_evaporated_sprinkling

157 self.dataset["gift"] = gift

158 self.dataset["gift_duration"] = gift_duration

159 self.dataset["rotational_period"] = rotational_period

160 self.dataset["start_sprinkling_season"] = start_sprinkling_season

161 self.dataset["end_sprinkling_season"] = end_sprinkling_season

162 self.dataset["interception_option"] = interception_option

163 self.dataset["interception_capacity_per_LAI_Rutter"] = (

164 interception_capacity_per_LAI

165 )

166 self.dataset["interception_capacity_per_LAI_VonHoyningen"] = (

167 interception_capacity_per_LAI

168 )

169 self.dataset["interception_intercept"] = interception_intercept

170

171 self._pkgcheck()

172

173 def _render(self, file, *args):

174 dataframe = self.dataset.to_dataframe(

175 dim_order=("landuse_index",)

176 ).reset_index()

177

178 self._check_range(dataframe)

179

180 # Find missing columns

181 missing_keys = set(self._metadata_dict.keys()) ^ set(dataframe.columns)

182

183 # Add missing columns

184 for key in missing_keys:

185 dataframe[key] = ""

186

187 # Reorder columns to _metadata_dict order

188 dataframe = dataframe[list(self._metadata_dict.keys())]

189

190 return self.write_dataframe_fixed_width(file, dataframe)

191

192 def _pkgcheck(self):

193 dims = self.dataset.dims

194 dims_expected = ("landuse_index",)

195 if len(set(dims) - set(dims_expected)) > 0:

196 raise ValueError(

197 f"Please provide DataArrays with dimensions {dims_expected}"

198 )