49def get_mask(level, indexing="ij", selection=False):
51 Get mask for a certain mHM level.
53 @param level (str): Name level ("L0", "L1", "L11", "L2")
54 @param indexing (str, optional): Indexing for the 2D mask,
55 either "xy" or "ij" (yx order), by default "ij"
56 @param selection (bool): A masked value in mHM indicates cells inside the domain.
57 In numpy, masked values are outside the domain. That means, by default False
58 @retval mask (numpy.ndarray): Boolean numpy array holding the mask.
59 @throws ValueError: If the level is not in ["L0", "L1", "L11" or "L2"].
62 shp = getattr(wr.get, level +
"_domain_shape")()
65 getattr(wr.get, level +
"_domain_mask")(m=shp[0], n=shp[1]), dtype=bool
69 return mask.T
if indexing ==
"ij" else mask
74 Get a specific variable from mHM in the current time-step.
76 @param name (str): Name of the variable
77 @param index (int, optional): If the variable has an additional dimension
78 (e.g. the horizon), one needs to specify an index, by default 1
79 @param indexing (str, optional): Indexing for the 2D variable,
80 either "xy" or "ij", by default "ij"
81 @param compressed (bool): Whether the data should be flattened and only contain
82 values for each unmasked domain cell. By default False
83 @retval variable (numpy.ndarray): Numpy array holding the desired variable.
84 @throws ValueError: If the variable name doesn't start with "L0", "L1", "L11" or "L2".
87 grid = name.split(
"_")[0].lower()
88 if grid
not in [
"l0",
"l1",
"l11",
"l2"]:
89 raise ValueError(f
"Unknown variable: {name}")
90 n = getattr(wr.get, grid +
"_domain_size")()
91 var = getattr(wr.get, grid +
"_variable")(name=name, n=n, idx=index)
93 return np.asarray(var, dtype=float)
95 grid_info = getattr(wr.get, grid +
"_domain_info")()
97 sel = get_mask(grid, indexing=
"xy", selection=
True)
98 sel = sel.ravel(order=
"F")
99 output = np.ma.empty_like(sel, dtype=float)
100 output.fill_value = grid_info[-1]
103 output = output.reshape((grid_info[0], grid_info[1]), order=
"C")
104 return output.T
if indexing ==
"xy" else output
124 Set meteo data with a time stamp in mHM.
126 @param time (datetime.datetime): Timestamp
127 @param pre (numpy.ndarray, optional): [mm] Precipitation
128 @param temp (numpy.ndarray, optional): [degC] Air temperature
129 @param pet (numpy.ndarray, optional): [mm TS-1] Potential evapotranspiration
130 @param tmin (numpy.ndarray, optional): [degC] minimum daily air temperature
131 @param tmax (numpy.ndarray, optional): [degC] maximum daily air temperature
132 @param netrad (numpy.ndarray, optional): [W m2] net radiation
133 @param absvappress (numpy.ndarray, optional): [Pa] absolute vapour pressure
134 @param windspeed (numpy.ndarray, optional): [m s-1] windspeed
135 @param ssrd (numpy.ndarray, optional): [W m2] short wave radiation
136 @param strd (numpy.ndarray, optional): [W m2] long wave radiation
137 @param tann (numpy.ndarray, optional): [degC] annual mean air temperature
138 @param compressed (bool): Whether the data is flattened and only contains
139 values for each unmasked domain cell. By default False
140 @param indexing (str, optional): Indexing for 2D arrays if data is not compressed,
141 either "xy" or "ij" (yx order), by default "ij"
143 sel = slice(
None)
if compressed
else get_mask(
"L1", indexing, selection=
True)
145 wr.set.meteo(pre[sel],
"PRE", time.year, time.month, time.day, time.hour)
147 wr.set.meteo(temp[sel],
"TEMP", time.year, time.month, time.day, time.hour)
149 wr.set.meteo(pet[sel],
"PET", time.year, time.month, time.day, time.hour)
151 wr.set.meteo(tmin[sel],
"TMIN", time.year, time.month, time.day, time.hour)
153 wr.set.meteo(tmax[sel],
"TMAX", time.year, time.month, time.day, time.hour)
154 if netrad
is not None:
155 wr.set.meteo(netrad[sel],
"NETRAD", time.year, time.month, time.day, time.hour)
156 if absvappress
is not None:
158 absvappress[sel],
"ABSVAPPRESS", time.year, time.month, time.day, time.hour
160 if windspeed
is not None:
162 windspeed[sel],
"WINDSPEED", time.year, time.month, time.day, time.hour
165 wr.set.meteo(ssrd[sel],
"SSRD", time.year, time.month, time.day, time.hour)
167 wr.set.meteo(strd[sel],
"STRD", time.year, time.month, time.day, time.hour)
169 wr.set.meteo(tann[sel],
"TANN", time.year, time.month, time.day, time.hour)