foxes 0.5.1__py3-none-any.whl → 0.5.2__py3-none-any.whl
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.
Potentially problematic release.
This version of foxes might be problematic. Click here for more details.
- foxes/VERSION +1 -1
- foxes/algorithms/downwind/downwind.py +41 -46
- foxes/algorithms/downwind/models/point_wakes_calc.py +4 -9
- foxes/algorithms/downwind/models/set_amb_point_results.py +5 -22
- foxes/core/algorithm.py +1 -1
- foxes/core/data_calc_model.py +26 -2
- foxes/core/partial_wakes_model.py +1 -1
- foxes/core/rotor_model.py +36 -2
- foxes/core/turbine_model.py +36 -0
- foxes/core/turbine_type.py +35 -1
- foxes/core/wake_frame.py +39 -3
- foxes/core/wake_model.py +36 -0
- foxes/models/model_book.py +132 -85
- foxes/models/turbine_models/rotor_centre_calc.py +1 -2
- foxes/models/turbine_types/CpCt_file.py +13 -3
- foxes/models/turbine_types/CpCt_from_two.py +14 -4
- foxes/models/vertical_profiles/abl_log_neutral_ws.py +32 -5
- foxes/models/vertical_profiles/abl_log_stable_ws.py +32 -4
- foxes/models/vertical_profiles/abl_log_unstable_ws.py +32 -4
- foxes/models/vertical_profiles/abl_log_ws.py +50 -18
- foxes/models/wake_frames/yawed_wakes.py +15 -9
- foxes/models/wake_models/induction/__init__.py +1 -1
- foxes/models/wake_models/induction/rankine_half_body.py +33 -7
- foxes/models/wake_models/ti/crespo_hernandez.py +6 -1
- foxes/models/wake_models/ti/iec_ti.py +5 -3
- foxes/models/wake_models/wind/__init__.py +2 -2
- foxes/models/wake_models/wind/{bastankhah.py → bastankhah14.py} +11 -14
- foxes/models/wake_models/wind/{porte_agel.py → bastankhah16.py} +24 -16
- foxes/models/wake_models/wind/turbopark.py +11 -22
- foxes/models/wake_superpositions/__init__.py +9 -5
- foxes/models/wake_superpositions/ti_linear.py +134 -0
- foxes/models/wake_superpositions/ti_max.py +134 -0
- foxes/models/wake_superpositions/{ti_superp.py → ti_pow.py} +15 -57
- foxes/models/wake_superpositions/ti_quadratic.py +134 -0
- foxes/models/wake_superpositions/ws_linear.py +170 -0
- foxes/models/wake_superpositions/ws_max.py +173 -0
- foxes/models/wake_superpositions/ws_pow.py +175 -0
- foxes/models/wake_superpositions/{product.py → ws_product.py} +43 -22
- foxes/models/wake_superpositions/ws_quadratic.py +170 -0
- foxes/output/__init__.py +4 -0
- foxes/output/calc_points.py +143 -0
- foxes/output/flow_plots_2d/__init__.py +1 -0
- foxes/output/flow_plots_2d/common.py +104 -1
- foxes/output/flow_plots_2d/flow_plots.py +237 -569
- foxes/output/flow_plots_2d/get_fig.py +183 -0
- foxes/output/flow_plots_2d/seq_flow_ani_plugin.py +0 -1
- foxes/output/grids.py +705 -0
- foxes/output/output.py +58 -11
- foxes/output/results_writer.py +101 -17
- foxes/output/round.py +10 -0
- foxes/output/slice_data.py +900 -0
- foxes/utils/__init__.py +5 -3
- foxes/utils/exec_python.py +56 -0
- foxes/utils/geopandas_utils.py +294 -0
- foxes/utils/pandas_utils.py +175 -0
- foxes/utils/plotly_utils.py +19 -0
- foxes/utils/xarray_utils.py +38 -0
- {foxes-0.5.1.dist-info → foxes-0.5.2.dist-info}/METADATA +1 -1
- {foxes-0.5.1.dist-info → foxes-0.5.2.dist-info}/RECORD +63 -49
- foxes/models/wake_superpositions/linear.py +0 -242
- foxes/models/wake_superpositions/max.py +0 -258
- foxes/models/wake_superpositions/quadratic.py +0 -252
- {foxes-0.5.1.dist-info → foxes-0.5.2.dist-info}/LICENSE +0 -0
- {foxes-0.5.1.dist-info → foxes-0.5.2.dist-info}/WHEEL +0 -0
- {foxes-0.5.1.dist-info → foxes-0.5.2.dist-info}/top_level.txt +0 -0
- {foxes-0.5.1.dist-info → foxes-0.5.2.dist-info}/zip-safe +0 -0
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from foxes.output import Output
|
|
4
|
+
from foxes.utils import write_nc
|
|
5
|
+
import foxes.constants as FC
|
|
6
|
+
import foxes.variables as FV
|
|
7
|
+
|
|
8
|
+
from . import grids
|
|
9
|
+
|
|
10
|
+
class SliceData(Output):
|
|
11
|
+
"""
|
|
12
|
+
Create data for horizontal or vertical 2D slices
|
|
13
|
+
|
|
14
|
+
Attributes
|
|
15
|
+
----------
|
|
16
|
+
algo: foxes.Algorithm
|
|
17
|
+
The algorithm for point calculation
|
|
18
|
+
farm_results: xarray.Dataset
|
|
19
|
+
The farm results
|
|
20
|
+
runner: foxes.utils.runners.Runner, optional
|
|
21
|
+
The runner
|
|
22
|
+
|
|
23
|
+
:group: output.flow_plots_2d
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, algo, farm_results, runner=None, **kwargs):
|
|
28
|
+
"""
|
|
29
|
+
Constructor.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
algo: foxes.Algorithm
|
|
34
|
+
The algorithm for point calculation
|
|
35
|
+
farm_results: xarray.Dataset
|
|
36
|
+
The farm results
|
|
37
|
+
runner: foxes.utils.runners.Runner, optional
|
|
38
|
+
The runner
|
|
39
|
+
kwargs: dict, optional
|
|
40
|
+
Additional parameters for the base class
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
super().__init__(**kwargs)
|
|
44
|
+
self.algo = algo
|
|
45
|
+
self.fres = farm_results
|
|
46
|
+
self.runner = runner
|
|
47
|
+
|
|
48
|
+
def _data_mod(self, a_pos, b_pos, c_pos, data,
|
|
49
|
+
normalize_a, normalize_b, normalize_c,
|
|
50
|
+
normalize_v, vmin, vmax):
|
|
51
|
+
""" Helper function for data modification """
|
|
52
|
+
if normalize_a is not None:
|
|
53
|
+
a_pos /= normalize_a
|
|
54
|
+
if normalize_b is not None:
|
|
55
|
+
b_pos /= normalize_b
|
|
56
|
+
if normalize_c is not None:
|
|
57
|
+
c_pos /= normalize_c
|
|
58
|
+
|
|
59
|
+
for v in data:
|
|
60
|
+
if v in normalize_v:
|
|
61
|
+
data[v] /= normalize_v[v]
|
|
62
|
+
if v in vmin:
|
|
63
|
+
data[v] = np.maximum(data[v], vmin[v])
|
|
64
|
+
if v in vmax:
|
|
65
|
+
data[v] = np.minimum(data[v], vmax[v])
|
|
66
|
+
|
|
67
|
+
return a_pos, b_pos, c_pos, data
|
|
68
|
+
|
|
69
|
+
def _write(self, format, data, fname, verbosity, **write_pars):
|
|
70
|
+
""" Helper function for file writing """
|
|
71
|
+
if fname is not None:
|
|
72
|
+
|
|
73
|
+
if format == "numpy":
|
|
74
|
+
fpath = self.get_fpath(fname)
|
|
75
|
+
if verbosity > 0:
|
|
76
|
+
print("Writing file", fpath)
|
|
77
|
+
wpars = dict(format="%.6f")
|
|
78
|
+
wpars.update(write_pars)
|
|
79
|
+
data.tofile(fpath, **wpars)
|
|
80
|
+
|
|
81
|
+
elif format == "pandas":
|
|
82
|
+
if verbosity > 0:
|
|
83
|
+
print("Writing file", fpath)
|
|
84
|
+
self.write(fname, data, **write_pars)
|
|
85
|
+
|
|
86
|
+
elif format == "xarray":
|
|
87
|
+
write_nc(data, self.get_fpath(fname), verbosity=verbosity, **write_pars)
|
|
88
|
+
|
|
89
|
+
else:
|
|
90
|
+
raise ValueError(f"Unknown data format '{format}', choices: numpy, pandas, xarray")
|
|
91
|
+
|
|
92
|
+
def _calc_mean_data(
|
|
93
|
+
self,
|
|
94
|
+
ori,
|
|
95
|
+
data_format,
|
|
96
|
+
variables,
|
|
97
|
+
a_pos,
|
|
98
|
+
b_pos,
|
|
99
|
+
c_pos,
|
|
100
|
+
g_pts,
|
|
101
|
+
normalize_a,
|
|
102
|
+
normalize_b,
|
|
103
|
+
normalize_c,
|
|
104
|
+
normalize_v,
|
|
105
|
+
label_map,
|
|
106
|
+
vmin,
|
|
107
|
+
vmax,
|
|
108
|
+
states_sel,
|
|
109
|
+
states_isel,
|
|
110
|
+
weight_turbine,
|
|
111
|
+
to_file,
|
|
112
|
+
write_pars,
|
|
113
|
+
ret_states,
|
|
114
|
+
verbosity,
|
|
115
|
+
**kwargs,
|
|
116
|
+
):
|
|
117
|
+
""" Helper function for mean data calculation """
|
|
118
|
+
# calculate point results:
|
|
119
|
+
point_results = grids.calc_point_results(
|
|
120
|
+
algo=self.algo,
|
|
121
|
+
farm_results=self.fres,
|
|
122
|
+
g_pts=g_pts,
|
|
123
|
+
sel={FC.STATE: states_sel} if states_sel is not None else None,
|
|
124
|
+
isel={FC.STATE: states_isel} if states_isel is not None else None,
|
|
125
|
+
verbosity=verbosity,
|
|
126
|
+
**kwargs,
|
|
127
|
+
)
|
|
128
|
+
states = point_results[FC.STATE].to_numpy()
|
|
129
|
+
if variables is None:
|
|
130
|
+
variables = list(point_results.data_vars.keys())
|
|
131
|
+
else:
|
|
132
|
+
point_results.drop_vars(variables)
|
|
133
|
+
del g_pts
|
|
134
|
+
|
|
135
|
+
# take mean over states:
|
|
136
|
+
weights = self.fres[FV.WEIGHT][:, weight_turbine].to_numpy()
|
|
137
|
+
data = {v: np.einsum("s,sp->p", weights, point_results[v].to_numpy())
|
|
138
|
+
for v in variables}
|
|
139
|
+
del point_results
|
|
140
|
+
|
|
141
|
+
# apply data modification:
|
|
142
|
+
a_pos, b_pos, c_pos, data = self._data_mod(a_pos, b_pos, c_pos, data,
|
|
143
|
+
normalize_a, normalize_b, normalize_c, normalize_v, vmin, vmax)
|
|
144
|
+
|
|
145
|
+
# translate to selected format:
|
|
146
|
+
if data_format == "numpy":
|
|
147
|
+
data = grids.np2np_p(data, a_pos, b_pos)
|
|
148
|
+
self._write(data_format, data, to_file, verbosity, **write_pars)
|
|
149
|
+
elif data_format == "pandas":
|
|
150
|
+
data = grids.np2pd_p(data, a_pos, b_pos, ori, label_map)
|
|
151
|
+
self._write(data_format, data, to_file, verbosity, **write_pars)
|
|
152
|
+
elif data_format == "xarray":
|
|
153
|
+
data = grids.np2xr_p(data, a_pos, b_pos, c_pos, ori, label_map)
|
|
154
|
+
self._write(data_format, data, to_file, verbosity, **write_pars)
|
|
155
|
+
else:
|
|
156
|
+
raise ValueError(f"Unknown data format '{data_format}', choices: numpy, pandas, xarray")
|
|
157
|
+
|
|
158
|
+
return (data, states) if ret_states else data
|
|
159
|
+
|
|
160
|
+
def get_mean_data_xy(
|
|
161
|
+
self,
|
|
162
|
+
resolution,
|
|
163
|
+
variables=None,
|
|
164
|
+
data_format="xarray",
|
|
165
|
+
xmin=None,
|
|
166
|
+
ymin=None,
|
|
167
|
+
xmax=None,
|
|
168
|
+
ymax=None,
|
|
169
|
+
z=None,
|
|
170
|
+
xspace=500.0,
|
|
171
|
+
yspace=500.0,
|
|
172
|
+
normalize_x=None,
|
|
173
|
+
normalize_y=None,
|
|
174
|
+
normalize_z=None,
|
|
175
|
+
normalize_v={},
|
|
176
|
+
label_map={},
|
|
177
|
+
vmin={},
|
|
178
|
+
vmax={},
|
|
179
|
+
states_sel=None,
|
|
180
|
+
states_isel=None,
|
|
181
|
+
weight_turbine=0,
|
|
182
|
+
to_file=None,
|
|
183
|
+
write_pars={},
|
|
184
|
+
ret_states=False,
|
|
185
|
+
ret_grid=False,
|
|
186
|
+
verbosity=0,
|
|
187
|
+
**kwargs,
|
|
188
|
+
):
|
|
189
|
+
"""
|
|
190
|
+
Creates mean data of 2D farm flow slices in a horizontal xy-plane.
|
|
191
|
+
|
|
192
|
+
Parameters
|
|
193
|
+
----------
|
|
194
|
+
resolution: float
|
|
195
|
+
The resolution in m
|
|
196
|
+
variables: list of str, optional
|
|
197
|
+
The variables, or None for all
|
|
198
|
+
data_format: str
|
|
199
|
+
The output data format: numpy, pandas, xarray
|
|
200
|
+
xmin: float, optional
|
|
201
|
+
The min x coordinate, or None for automatic
|
|
202
|
+
ymin: float, optional
|
|
203
|
+
The min y coordinate, or None for automatic
|
|
204
|
+
xmax: float, optional
|
|
205
|
+
The max x coordinate, or None for automatic
|
|
206
|
+
ymax: float, optional
|
|
207
|
+
The max y coordinate, or None for automatic
|
|
208
|
+
z: float, optional
|
|
209
|
+
The z coordinate of the plane
|
|
210
|
+
xspace: float, optional
|
|
211
|
+
The extra space in x direction, before and after wind farm
|
|
212
|
+
yspace: float, optional
|
|
213
|
+
The extra space in y direction, before and after wind farm
|
|
214
|
+
normalize_x: float, optional
|
|
215
|
+
Divide x by this value
|
|
216
|
+
normalize_y: float, optional
|
|
217
|
+
Divide y by this value
|
|
218
|
+
normalize_z: float, optional
|
|
219
|
+
Divide z by this value
|
|
220
|
+
normalize_v: dict, optional
|
|
221
|
+
Divide the variables by these values
|
|
222
|
+
label_map: dict
|
|
223
|
+
The mapping from original to new field names
|
|
224
|
+
vmin: dict
|
|
225
|
+
Minimal values for variables
|
|
226
|
+
vmax: dict
|
|
227
|
+
Maximal values for variables
|
|
228
|
+
states_sel: list, optional
|
|
229
|
+
Reduce to selected states
|
|
230
|
+
states_isel: list, optional
|
|
231
|
+
Reduce to the selected states indices
|
|
232
|
+
weight_turbine: int, optional
|
|
233
|
+
Index of the turbine from which to take the weight
|
|
234
|
+
to_file: str, optional
|
|
235
|
+
Write data to this file name
|
|
236
|
+
write_pars: dict
|
|
237
|
+
Additional write function parameters
|
|
238
|
+
ret_states: bool
|
|
239
|
+
Flag for returning states indices
|
|
240
|
+
ret_grid: bool
|
|
241
|
+
Flag for returning grid data
|
|
242
|
+
verbosity: int, optional
|
|
243
|
+
The verbosity level, 0 = silent
|
|
244
|
+
kwargs: dict, optional
|
|
245
|
+
Parameters forwarded to the algorithm's calc_points
|
|
246
|
+
function.
|
|
247
|
+
|
|
248
|
+
Returns
|
|
249
|
+
-------
|
|
250
|
+
data: dict or pandas.DataFrame or xarray.Dataset
|
|
251
|
+
The gridded data
|
|
252
|
+
states: numpy.ndarray, optional
|
|
253
|
+
The states indices
|
|
254
|
+
grid_data: tuple, optional
|
|
255
|
+
The grid data (x_pos, y_pos, z_pos, g_pts)
|
|
256
|
+
|
|
257
|
+
"""
|
|
258
|
+
gdata = grids.get_grid_xy(
|
|
259
|
+
self.fres, resolution, xmin, ymin, xmax, ymax, z, xspace, yspace, verbosity
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
data = self._calc_mean_data("xy", data_format, variables, *gdata,
|
|
263
|
+
normalize_x, normalize_y, normalize_z, normalize_v, label_map,
|
|
264
|
+
vmin, vmax, states_sel, states_isel, weight_turbine, to_file,
|
|
265
|
+
write_pars, ret_states, verbosity, **kwargs)
|
|
266
|
+
|
|
267
|
+
if ret_grid:
|
|
268
|
+
out = list(data) if ret_states else [data]
|
|
269
|
+
return tuple(out + [gdata])
|
|
270
|
+
return data
|
|
271
|
+
|
|
272
|
+
def get_mean_data_xz(
|
|
273
|
+
self,
|
|
274
|
+
resolution,
|
|
275
|
+
variables=None,
|
|
276
|
+
data_format="xarray",
|
|
277
|
+
x_direction=270,
|
|
278
|
+
xmin=None,
|
|
279
|
+
zmin=0.,
|
|
280
|
+
xmax=None,
|
|
281
|
+
zmax=None,
|
|
282
|
+
y=None,
|
|
283
|
+
xspace=500.0,
|
|
284
|
+
zspace=500.0,
|
|
285
|
+
normalize_x=None,
|
|
286
|
+
normalize_y=None,
|
|
287
|
+
normalize_z=None,
|
|
288
|
+
normalize_v={},
|
|
289
|
+
label_map={},
|
|
290
|
+
vmin={},
|
|
291
|
+
vmax={},
|
|
292
|
+
states_sel=None,
|
|
293
|
+
states_isel=None,
|
|
294
|
+
weight_turbine=0,
|
|
295
|
+
to_file=None,
|
|
296
|
+
write_pars={},
|
|
297
|
+
ret_states=False,
|
|
298
|
+
ret_grid=False,
|
|
299
|
+
verbosity=0,
|
|
300
|
+
**kwargs,
|
|
301
|
+
):
|
|
302
|
+
"""
|
|
303
|
+
Creates mean data of 2D farm flow slices in an xz-plane.
|
|
304
|
+
|
|
305
|
+
Parameters
|
|
306
|
+
----------
|
|
307
|
+
resolution: float
|
|
308
|
+
The resolution in m
|
|
309
|
+
variables: list of str, optional
|
|
310
|
+
The variables, or None for all
|
|
311
|
+
data_format: str
|
|
312
|
+
The output data format: numpy, pandas, xarray
|
|
313
|
+
x_direction: float, optional
|
|
314
|
+
The direction of the x axis, 0 = north
|
|
315
|
+
xmin: float, optional
|
|
316
|
+
The min x coordinate, or None for automatic
|
|
317
|
+
zmin: float, optional
|
|
318
|
+
The min z coordinate
|
|
319
|
+
xmax: float, optional
|
|
320
|
+
The max x coordinate, or None for automatic
|
|
321
|
+
zmax: float, optional
|
|
322
|
+
The max z coordinate, or None for automatic
|
|
323
|
+
y: float, optional
|
|
324
|
+
The y coordinate of the plane
|
|
325
|
+
xspace: float, optional
|
|
326
|
+
The extra space in x direction, before and after wind farm
|
|
327
|
+
zspace: float, optional
|
|
328
|
+
The extra space in z direction, below and above wind farm
|
|
329
|
+
normalize_x: float, optional
|
|
330
|
+
Divide x by this value
|
|
331
|
+
normalize_y: float, optional
|
|
332
|
+
Divide y by this value
|
|
333
|
+
normalize_z: float, optional
|
|
334
|
+
Divide z by this value
|
|
335
|
+
normalize_v: dict, optional
|
|
336
|
+
Divide the variables by these values
|
|
337
|
+
label_map: dict
|
|
338
|
+
The mapping from original to new field names
|
|
339
|
+
vmin: dict
|
|
340
|
+
Minimal values for variables
|
|
341
|
+
vmax: dict
|
|
342
|
+
Maximal values for variables
|
|
343
|
+
states_sel: list, optional
|
|
344
|
+
Reduce to selected states
|
|
345
|
+
states_isel: list, optional
|
|
346
|
+
Reduce to the selected states indices
|
|
347
|
+
weight_turbine: int, optional
|
|
348
|
+
Index of the turbine from which to take the weight
|
|
349
|
+
to_file: str, optional
|
|
350
|
+
Write data to this file name
|
|
351
|
+
write_pars: dict
|
|
352
|
+
Additional write function parameters
|
|
353
|
+
ret_states: bool
|
|
354
|
+
Flag for returning states indices
|
|
355
|
+
ret_grid: bool
|
|
356
|
+
Flag for returning grid data
|
|
357
|
+
verbosity: int, optional
|
|
358
|
+
The verbosity level, 0 = silent
|
|
359
|
+
kwargs: dict, optional
|
|
360
|
+
Parameters forwarded to the algorithm's calc_points
|
|
361
|
+
function.
|
|
362
|
+
|
|
363
|
+
Returns
|
|
364
|
+
-------
|
|
365
|
+
data: dict or pandas.DataFrame or xarray.Dataset
|
|
366
|
+
The gridded data
|
|
367
|
+
states: numpy.ndarray, optional
|
|
368
|
+
The states indices
|
|
369
|
+
grid_data: tuple, optional
|
|
370
|
+
The grid data (x_pos, y_pos, z_pos, g_pts)
|
|
371
|
+
|
|
372
|
+
"""
|
|
373
|
+
gdata = grids.get_grid_xz(self.fres, resolution,
|
|
374
|
+
x_direction, xmin, zmin, xmax, zmax, y, xspace, zspace, verbosity)
|
|
375
|
+
gdatb = (gdata[0], gdata[2], gdata[1], gdata[3])
|
|
376
|
+
|
|
377
|
+
data = self._calc_mean_data("xz", data_format, variables, *gdatb,
|
|
378
|
+
normalize_x, normalize_z, normalize_y, normalize_v, label_map,
|
|
379
|
+
vmin, vmax, states_sel, states_isel, weight_turbine, to_file,
|
|
380
|
+
write_pars, ret_states, verbosity, **kwargs)
|
|
381
|
+
|
|
382
|
+
if ret_grid:
|
|
383
|
+
out = list(data) if ret_states else [data]
|
|
384
|
+
return tuple(out + [gdata])
|
|
385
|
+
return data
|
|
386
|
+
|
|
387
|
+
def get_mean_data_yz(
|
|
388
|
+
self,
|
|
389
|
+
resolution,
|
|
390
|
+
variables=None,
|
|
391
|
+
data_format="xarray",
|
|
392
|
+
x_direction=270,
|
|
393
|
+
ymin=None,
|
|
394
|
+
zmin=0.,
|
|
395
|
+
ymax=None,
|
|
396
|
+
zmax=None,
|
|
397
|
+
x=None,
|
|
398
|
+
yspace=500.0,
|
|
399
|
+
zspace=500.0,
|
|
400
|
+
normalize_x=None,
|
|
401
|
+
normalize_y=None,
|
|
402
|
+
normalize_z=None,
|
|
403
|
+
normalize_v={},
|
|
404
|
+
label_map={},
|
|
405
|
+
vmin={},
|
|
406
|
+
vmax={},
|
|
407
|
+
states_sel=None,
|
|
408
|
+
states_isel=None,
|
|
409
|
+
weight_turbine=0,
|
|
410
|
+
to_file=None,
|
|
411
|
+
write_pars={},
|
|
412
|
+
ret_states=False,
|
|
413
|
+
ret_grid=False,
|
|
414
|
+
verbosity=0,
|
|
415
|
+
**kwargs,
|
|
416
|
+
):
|
|
417
|
+
"""
|
|
418
|
+
Creates mean data of 2D farm flow slices in a yz-plane.
|
|
419
|
+
|
|
420
|
+
Parameters
|
|
421
|
+
----------
|
|
422
|
+
resolution: float
|
|
423
|
+
The resolution in m
|
|
424
|
+
variables: list of str, optional
|
|
425
|
+
The variables, or None for all
|
|
426
|
+
data_format: str
|
|
427
|
+
The output data format: numpy, pandas, xarray
|
|
428
|
+
x_direction: float, optional
|
|
429
|
+
The direction of the x axis, 0 = north
|
|
430
|
+
ymin: float, optional
|
|
431
|
+
The min y coordinate, or None for automatic
|
|
432
|
+
zmin: float, optional
|
|
433
|
+
The min z coordinate
|
|
434
|
+
ymax: float, optional
|
|
435
|
+
The max y coordinate, or None for automatic
|
|
436
|
+
zmax: float, optional
|
|
437
|
+
The max z coordinate, or None for automatic
|
|
438
|
+
x: float, optional
|
|
439
|
+
The x coordinate of the plane
|
|
440
|
+
yspace: float, optional
|
|
441
|
+
The extra space in y direction, before and after wind farm
|
|
442
|
+
zspace: float, optional
|
|
443
|
+
The extra space in z direction, below and above wind farm
|
|
444
|
+
normalize_x: float, optional
|
|
445
|
+
Divide x by this value
|
|
446
|
+
normalize_y: float, optional
|
|
447
|
+
Divide y by this value
|
|
448
|
+
normalize_z: float, optional
|
|
449
|
+
Divide z by this value
|
|
450
|
+
normalize_v: dict, optional
|
|
451
|
+
Divide the variables by these values
|
|
452
|
+
label_map: dict
|
|
453
|
+
The mapping from original to new field names
|
|
454
|
+
vmin: dict
|
|
455
|
+
Minimal values for variables
|
|
456
|
+
vmax: dict
|
|
457
|
+
Maximal values for variables
|
|
458
|
+
states_sel: list, optional
|
|
459
|
+
Reduce to selected states
|
|
460
|
+
states_isel: list, optional
|
|
461
|
+
Reduce to the selected states indices
|
|
462
|
+
weight_turbine: int, optional
|
|
463
|
+
Index of the turbine from which to take the weight
|
|
464
|
+
to_file: str, optional
|
|
465
|
+
Write data to this file name
|
|
466
|
+
write_pars: dict
|
|
467
|
+
Additional write function parameters
|
|
468
|
+
ret_states: bool
|
|
469
|
+
Flag for returning states indices
|
|
470
|
+
ret_grid: bool
|
|
471
|
+
Flag for returning grid data
|
|
472
|
+
verbosity: int, optional
|
|
473
|
+
The verbosity level, 0 = silent
|
|
474
|
+
kwargs: dict, optional
|
|
475
|
+
Parameters forwarded to the algorithm's calc_points
|
|
476
|
+
function.
|
|
477
|
+
|
|
478
|
+
Returns
|
|
479
|
+
-------
|
|
480
|
+
data: dict or pandas.DataFrame or xarray.Dataset
|
|
481
|
+
The gridded data
|
|
482
|
+
states: numpy.ndarray, optional
|
|
483
|
+
The states indices
|
|
484
|
+
grid_data: tuple, optional
|
|
485
|
+
The grid data (x_pos, y_pos, z_pos, g_pts)
|
|
486
|
+
|
|
487
|
+
"""
|
|
488
|
+
gdata = grids.get_grid_yz(self.fres, resolution,
|
|
489
|
+
x_direction, ymin, zmin, ymax, zmax, x, yspace, zspace, verbosity)
|
|
490
|
+
gdatb = (gdata[1], gdata[2], gdata[0], gdata[3])
|
|
491
|
+
|
|
492
|
+
data = self._calc_mean_data("yz", data_format, variables, *gdatb,
|
|
493
|
+
normalize_y, normalize_z, normalize_x, normalize_v, label_map,
|
|
494
|
+
vmin, vmax, states_sel, states_isel, weight_turbine, to_file,
|
|
495
|
+
write_pars, ret_states, verbosity, **kwargs)
|
|
496
|
+
|
|
497
|
+
if ret_grid:
|
|
498
|
+
out = list(data) if ret_states else [data]
|
|
499
|
+
return tuple(out + [gdata])
|
|
500
|
+
return data
|
|
501
|
+
|
|
502
|
+
def _calc_states_data(
|
|
503
|
+
self,
|
|
504
|
+
ori,
|
|
505
|
+
data_format,
|
|
506
|
+
variables,
|
|
507
|
+
a_pos,
|
|
508
|
+
b_pos,
|
|
509
|
+
c_pos,
|
|
510
|
+
g_pts,
|
|
511
|
+
normalize_a,
|
|
512
|
+
normalize_b,
|
|
513
|
+
normalize_c,
|
|
514
|
+
normalize_v,
|
|
515
|
+
label_map,
|
|
516
|
+
vmin,
|
|
517
|
+
vmax,
|
|
518
|
+
states_sel,
|
|
519
|
+
states_isel,
|
|
520
|
+
to_file,
|
|
521
|
+
write_pars,
|
|
522
|
+
ret_states,
|
|
523
|
+
verbosity,
|
|
524
|
+
**kwargs,
|
|
525
|
+
):
|
|
526
|
+
""" Helper function for states data calculation """
|
|
527
|
+
# calculate point results:
|
|
528
|
+
if states_sel is not None:
|
|
529
|
+
kwargs["sel"] = {FC.STATE: states_sel}
|
|
530
|
+
if states_isel is not None:
|
|
531
|
+
kwargs["isel"] = {FC.STATE: states_isel}
|
|
532
|
+
point_results = grids.calc_point_results(
|
|
533
|
+
algo=self.algo,
|
|
534
|
+
farm_results=self.fres,
|
|
535
|
+
g_pts=g_pts,
|
|
536
|
+
verbosity=verbosity,
|
|
537
|
+
**kwargs,
|
|
538
|
+
)
|
|
539
|
+
states = point_results[FC.STATE].to_numpy()
|
|
540
|
+
if variables is None:
|
|
541
|
+
variables = list(point_results.data_vars.keys())
|
|
542
|
+
else:
|
|
543
|
+
point_results.drop_vars(variables)
|
|
544
|
+
del g_pts
|
|
545
|
+
|
|
546
|
+
# convert to numpy:
|
|
547
|
+
data = {v: point_results[v].to_numpy() for v in variables}
|
|
548
|
+
del point_results
|
|
549
|
+
|
|
550
|
+
# apply data modification:
|
|
551
|
+
a_pos, b_pos, c_pos, data = self._data_mod(a_pos, b_pos, c_pos, data,
|
|
552
|
+
normalize_a, normalize_b, normalize_c, normalize_v, vmin, vmax)
|
|
553
|
+
|
|
554
|
+
# translate to selected format:
|
|
555
|
+
if data_format == "numpy":
|
|
556
|
+
data = grids.np2np_sp(data, states, a_pos, b_pos)
|
|
557
|
+
self._write(data_format, data, to_file, verbosity, **write_pars)
|
|
558
|
+
elif data_format == "pandas":
|
|
559
|
+
data = grids.np2pd_sp(data, states, a_pos, b_pos, ori, label_map)
|
|
560
|
+
self._write(data_format, data, to_file, verbosity, **write_pars)
|
|
561
|
+
elif data_format == "xarray":
|
|
562
|
+
data = grids.np2xr_sp(data, states, a_pos, b_pos, c_pos, ori, label_map)
|
|
563
|
+
self._write(data_format, data, to_file, verbosity, **write_pars)
|
|
564
|
+
else:
|
|
565
|
+
raise ValueError(f"Unknown data format '{data_format}', choices: numpy, pandas, xarray")
|
|
566
|
+
|
|
567
|
+
return (data, states) if ret_states else data
|
|
568
|
+
|
|
569
|
+
def get_states_data_xy(
|
|
570
|
+
self,
|
|
571
|
+
resolution,
|
|
572
|
+
variables=None,
|
|
573
|
+
data_format="xarray",
|
|
574
|
+
xmin=None,
|
|
575
|
+
ymin=None,
|
|
576
|
+
xmax=None,
|
|
577
|
+
ymax=None,
|
|
578
|
+
z=None,
|
|
579
|
+
xspace=500.0,
|
|
580
|
+
yspace=500.0,
|
|
581
|
+
normalize_x=None,
|
|
582
|
+
normalize_y=None,
|
|
583
|
+
normalize_z=None,
|
|
584
|
+
normalize_v={},
|
|
585
|
+
label_map={},
|
|
586
|
+
vmin={},
|
|
587
|
+
vmax={},
|
|
588
|
+
states_sel=None,
|
|
589
|
+
states_isel=None,
|
|
590
|
+
to_file=None,
|
|
591
|
+
write_pars={},
|
|
592
|
+
ret_states=False,
|
|
593
|
+
ret_grid=False,
|
|
594
|
+
verbosity=0,
|
|
595
|
+
**kwargs,
|
|
596
|
+
):
|
|
597
|
+
"""
|
|
598
|
+
Creates states data of 2D farm flow slices in a horizontal xy-plane.
|
|
599
|
+
|
|
600
|
+
Parameters
|
|
601
|
+
----------
|
|
602
|
+
resolution: float
|
|
603
|
+
The resolution in m
|
|
604
|
+
variables: list of str, optional
|
|
605
|
+
The variables, or None for all
|
|
606
|
+
data_format: str
|
|
607
|
+
The output data format: numpy, pandas, xarray
|
|
608
|
+
xmin: float, optional
|
|
609
|
+
The min x coordinate, or None for automatic
|
|
610
|
+
ymin: float, optional
|
|
611
|
+
The min y coordinate, or None for automatic
|
|
612
|
+
xmax: float, optional
|
|
613
|
+
The max x coordinate, or None for automatic
|
|
614
|
+
ymax: float, optional
|
|
615
|
+
The max y coordinate, or None for automatic
|
|
616
|
+
z: float, optional
|
|
617
|
+
The z coordinate of the plane
|
|
618
|
+
xspace: float, optional
|
|
619
|
+
The extra space in x direction, before and after wind farm
|
|
620
|
+
yspace: float, optional
|
|
621
|
+
The extra space in y direction, before and after wind farm
|
|
622
|
+
normalize_x: float, optional
|
|
623
|
+
Divide x by this value
|
|
624
|
+
normalize_y: float, optional
|
|
625
|
+
Divide y by this value
|
|
626
|
+
normalize_z: float, optional
|
|
627
|
+
Divide z by this value
|
|
628
|
+
normalize_v: dict, optional
|
|
629
|
+
Divide the variables by these values
|
|
630
|
+
label_map: dict
|
|
631
|
+
The mapping from original to new field names
|
|
632
|
+
vmin: dict
|
|
633
|
+
Minimal values for variables
|
|
634
|
+
vmax: dict
|
|
635
|
+
Maximal values for variables
|
|
636
|
+
states_sel: list, optional
|
|
637
|
+
Reduce to selected states
|
|
638
|
+
states_isel: list, optional
|
|
639
|
+
Reduce to the selected states indices
|
|
640
|
+
to_file: str, optional
|
|
641
|
+
Write data to this file name
|
|
642
|
+
write_pars: dict
|
|
643
|
+
Additional write function parameters
|
|
644
|
+
ret_states: bool
|
|
645
|
+
Flag for returning states indices
|
|
646
|
+
ret_grid: bool
|
|
647
|
+
Flag for returning grid data
|
|
648
|
+
verbosity: int, optional
|
|
649
|
+
The verbosity level, 0 = silent
|
|
650
|
+
kwargs: dict, optional
|
|
651
|
+
Parameters forwarded to the algorithm's calc_points
|
|
652
|
+
function.
|
|
653
|
+
|
|
654
|
+
Returns
|
|
655
|
+
-------
|
|
656
|
+
data: dict or pandas.DataFrame or xarray.Dataset
|
|
657
|
+
The gridded data
|
|
658
|
+
states: numpy.ndarray, optional
|
|
659
|
+
The states indices
|
|
660
|
+
grid_data: tuple, optional
|
|
661
|
+
The grid data (x_pos, y_pos, z_pos, g_pts)
|
|
662
|
+
|
|
663
|
+
"""
|
|
664
|
+
gdata = grids.get_grid_xy(
|
|
665
|
+
self.fres, resolution, xmin, ymin, xmax, ymax, z, xspace, yspace, verbosity
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
data = self._calc_states_data("xy", data_format, variables, *gdata,
|
|
669
|
+
normalize_x, normalize_y, normalize_z, normalize_v, label_map,
|
|
670
|
+
vmin, vmax, states_sel, states_isel, to_file, write_pars,
|
|
671
|
+
ret_states, verbosity, **kwargs)
|
|
672
|
+
|
|
673
|
+
if ret_grid:
|
|
674
|
+
out = list(data) if ret_states else [data]
|
|
675
|
+
return tuple(out + [gdata])
|
|
676
|
+
return data
|
|
677
|
+
|
|
678
|
+
def get_states_data_xz(
|
|
679
|
+
self,
|
|
680
|
+
resolution,
|
|
681
|
+
variables=None,
|
|
682
|
+
data_format="xarray",
|
|
683
|
+
x_direction=270,
|
|
684
|
+
xmin=None,
|
|
685
|
+
zmin=0.,
|
|
686
|
+
xmax=None,
|
|
687
|
+
zmax=None,
|
|
688
|
+
y=None,
|
|
689
|
+
xspace=500.0,
|
|
690
|
+
zspace=500.0,
|
|
691
|
+
normalize_x=None,
|
|
692
|
+
normalize_y=None,
|
|
693
|
+
normalize_z=None,
|
|
694
|
+
normalize_v={},
|
|
695
|
+
label_map={},
|
|
696
|
+
vmin={},
|
|
697
|
+
vmax={},
|
|
698
|
+
states_sel=None,
|
|
699
|
+
states_isel=None,
|
|
700
|
+
to_file=None,
|
|
701
|
+
write_pars={},
|
|
702
|
+
ret_states=False,
|
|
703
|
+
ret_grid=False,
|
|
704
|
+
verbosity=0,
|
|
705
|
+
**kwargs,
|
|
706
|
+
):
|
|
707
|
+
"""
|
|
708
|
+
Creates states data of 2D farm flow slices in an xz-plane.
|
|
709
|
+
|
|
710
|
+
Parameters
|
|
711
|
+
----------
|
|
712
|
+
resolution: float
|
|
713
|
+
The resolution in m
|
|
714
|
+
variables: list of str, optional
|
|
715
|
+
The variables, or None for all
|
|
716
|
+
data_format: str
|
|
717
|
+
The output data format: numpy, pandas, xarray
|
|
718
|
+
x_direction: float, optional
|
|
719
|
+
The direction of the x axis, 0 = north
|
|
720
|
+
xmin: float, optional
|
|
721
|
+
The min x coordinate, or None for automatic
|
|
722
|
+
zmin: float, optional
|
|
723
|
+
The min z coordinate
|
|
724
|
+
xmax: float, optional
|
|
725
|
+
The max x coordinate, or None for automatic
|
|
726
|
+
zmax: float, optional
|
|
727
|
+
The max z coordinate, or None for automatic
|
|
728
|
+
y: float, optional
|
|
729
|
+
The y coordinate of the plane
|
|
730
|
+
xspace: float, optional
|
|
731
|
+
The extra space in x direction, before and after wind farm
|
|
732
|
+
zspace: float, optional
|
|
733
|
+
The extra space in z direction, below and above wind farm
|
|
734
|
+
normalize_x: float, optional
|
|
735
|
+
Divide x by this value
|
|
736
|
+
normalize_y: float, optional
|
|
737
|
+
Divide y by this value
|
|
738
|
+
normalize_z: float, optional
|
|
739
|
+
Divide z by this value
|
|
740
|
+
normalize_v: dict, optional
|
|
741
|
+
Divide the variables by these values
|
|
742
|
+
label_map: dict
|
|
743
|
+
The mapping from original to new field names
|
|
744
|
+
vmin: dict
|
|
745
|
+
Minimal values for variables
|
|
746
|
+
vmax: dict
|
|
747
|
+
Maximal values for variables
|
|
748
|
+
states_sel: list, optional
|
|
749
|
+
Reduce to selected states
|
|
750
|
+
states_isel: list, optional
|
|
751
|
+
Reduce to the selected states indices
|
|
752
|
+
to_file: str, optional
|
|
753
|
+
Write data to this file name
|
|
754
|
+
write_pars: dict
|
|
755
|
+
Additional write function parameters
|
|
756
|
+
ret_states: bool
|
|
757
|
+
Flag for returning states indices
|
|
758
|
+
ret_grid: bool
|
|
759
|
+
Flag for returning grid data
|
|
760
|
+
verbosity: int, optional
|
|
761
|
+
The verbosity level, 0 = silent
|
|
762
|
+
kwargs: dict, optional
|
|
763
|
+
Parameters forwarded to the algorithm's calc_points
|
|
764
|
+
function.
|
|
765
|
+
|
|
766
|
+
Returns
|
|
767
|
+
-------
|
|
768
|
+
data: dict or pandas.DataFrame or xarray.Dataset
|
|
769
|
+
The gridded data
|
|
770
|
+
states: numpy.ndarray, optional
|
|
771
|
+
The states indices
|
|
772
|
+
grid_data: tuple, optional
|
|
773
|
+
The grid data (x_pos, y_pos, z_pos, g_pts)
|
|
774
|
+
|
|
775
|
+
"""
|
|
776
|
+
gdata = grids.get_grid_xz(self.fres, resolution,
|
|
777
|
+
x_direction, xmin, zmin, xmax, zmax, y, xspace, zspace, verbosity)
|
|
778
|
+
gdatb = (gdata[0], gdata[2], gdata[1], gdata[3])
|
|
779
|
+
|
|
780
|
+
data = self._calc_states_data("xz", data_format, variables, *gdatb,
|
|
781
|
+
normalize_x, normalize_z, normalize_y, normalize_v, label_map,
|
|
782
|
+
vmin, vmax, states_sel, states_isel, to_file, write_pars,
|
|
783
|
+
ret_states, verbosity, **kwargs)
|
|
784
|
+
|
|
785
|
+
if ret_grid:
|
|
786
|
+
out = list(data) if ret_states else [data]
|
|
787
|
+
return tuple(out + [gdata])
|
|
788
|
+
return data
|
|
789
|
+
|
|
790
|
+
def get_states_data_yz(
|
|
791
|
+
self,
|
|
792
|
+
resolution,
|
|
793
|
+
variables=None,
|
|
794
|
+
data_format="xarray",
|
|
795
|
+
x_direction=270,
|
|
796
|
+
ymin=None,
|
|
797
|
+
zmin=0.,
|
|
798
|
+
ymax=None,
|
|
799
|
+
zmax=None,
|
|
800
|
+
x=None,
|
|
801
|
+
yspace=500.0,
|
|
802
|
+
zspace=500.0,
|
|
803
|
+
normalize_x=None,
|
|
804
|
+
normalize_y=None,
|
|
805
|
+
normalize_z=None,
|
|
806
|
+
normalize_v={},
|
|
807
|
+
label_map={},
|
|
808
|
+
vmin={},
|
|
809
|
+
vmax={},
|
|
810
|
+
states_sel=None,
|
|
811
|
+
states_isel=None,
|
|
812
|
+
to_file=None,
|
|
813
|
+
write_pars={},
|
|
814
|
+
ret_states=False,
|
|
815
|
+
ret_grid=False,
|
|
816
|
+
verbosity=0,
|
|
817
|
+
**kwargs,
|
|
818
|
+
):
|
|
819
|
+
"""
|
|
820
|
+
Creates states data of 2D farm flow slices in a yz-plane.
|
|
821
|
+
|
|
822
|
+
Parameters
|
|
823
|
+
----------
|
|
824
|
+
resolution: float
|
|
825
|
+
The resolution in m
|
|
826
|
+
variables: list of str, optional
|
|
827
|
+
The variables, or None for all
|
|
828
|
+
data_format: str
|
|
829
|
+
The output data format: numpy, pandas, xarray
|
|
830
|
+
x_direction: float, optional
|
|
831
|
+
The direction of the x axis, 0 = north
|
|
832
|
+
ymin: float, optional
|
|
833
|
+
The min y coordinate, or None for automatic
|
|
834
|
+
zmin: float, optional
|
|
835
|
+
The min z coordinate
|
|
836
|
+
ymax: float, optional
|
|
837
|
+
The max y coordinate, or None for automatic
|
|
838
|
+
zmax: float, optional
|
|
839
|
+
The max z coordinate, or None for automatic
|
|
840
|
+
x: float, optional
|
|
841
|
+
The x coordinate of the plane
|
|
842
|
+
yspace: float, optional
|
|
843
|
+
The extra space in y direction, before and after wind farm
|
|
844
|
+
zspace: float, optional
|
|
845
|
+
The extra space in z direction, below and above wind farm
|
|
846
|
+
normalize_x: float, optional
|
|
847
|
+
Divide x by this value
|
|
848
|
+
normalize_y: float, optional
|
|
849
|
+
Divide y by this value
|
|
850
|
+
normalize_z: float, optional
|
|
851
|
+
Divide z by this value
|
|
852
|
+
normalize_v: dict, optional
|
|
853
|
+
Divide the variables by these values
|
|
854
|
+
label_map: dict
|
|
855
|
+
The mapping from original to new field names
|
|
856
|
+
vmin: dict
|
|
857
|
+
Minimal values for variables
|
|
858
|
+
vmax: dict
|
|
859
|
+
Maximal values for variables
|
|
860
|
+
states_sel: list, optional
|
|
861
|
+
Reduce to selected states
|
|
862
|
+
states_isel: list, optional
|
|
863
|
+
Reduce to the selected states indices
|
|
864
|
+
to_file: str, optional
|
|
865
|
+
Write data to this file name
|
|
866
|
+
write_pars: dict
|
|
867
|
+
Additional write function parameters
|
|
868
|
+
ret_states: bool
|
|
869
|
+
Flag for returning states indices
|
|
870
|
+
ret_grid: bool
|
|
871
|
+
Flag for returning grid data
|
|
872
|
+
verbosity: int, optional
|
|
873
|
+
The verbosity level, 0 = silent
|
|
874
|
+
kwargs: dict, optional
|
|
875
|
+
Parameters forwarded to the algorithm's calc_points
|
|
876
|
+
function.
|
|
877
|
+
|
|
878
|
+
Returns
|
|
879
|
+
-------
|
|
880
|
+
data: dict or pandas.DataFrame or xarray.Dataset
|
|
881
|
+
The gridded data
|
|
882
|
+
states: numpy.ndarray, optional
|
|
883
|
+
The states indices
|
|
884
|
+
grid_data: tuple, optional
|
|
885
|
+
The grid data (x_pos, y_pos, z_pos, g_pts)
|
|
886
|
+
|
|
887
|
+
"""
|
|
888
|
+
gdata = grids.get_grid_yz(self.fres, resolution,
|
|
889
|
+
x_direction, ymin, zmin, ymax, zmax, x, yspace, zspace, verbosity)
|
|
890
|
+
gdatb = (gdata[1], gdata[2], gdata[0], gdata[3])
|
|
891
|
+
|
|
892
|
+
data = self._calc_states_data("yz", data_format, variables, *gdatb,
|
|
893
|
+
normalize_y, normalize_z, normalize_x, normalize_v, label_map,
|
|
894
|
+
vmin, vmax, states_sel, states_isel, to_file, write_pars,
|
|
895
|
+
ret_states, verbosity, **kwargs)
|
|
896
|
+
|
|
897
|
+
if ret_grid:
|
|
898
|
+
out = list(data) if ret_states else [data]
|
|
899
|
+
return tuple(out + [gdata])
|
|
900
|
+
return data
|