foxes 1.1.0.2__py3-none-any.whl → 1.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.

Files changed (131) hide show
  1. docs/source/conf.py +3 -2
  2. examples/dyn_wakes/run.py +2 -2
  3. examples/timelines/run.py +1 -1
  4. foxes/__init__.py +13 -2
  5. foxes/algorithms/downwind/downwind.py +6 -1
  6. foxes/algorithms/downwind/models/init_farm_data.py +5 -2
  7. foxes/algorithms/downwind/models/point_wakes_calc.py +0 -1
  8. foxes/algorithms/iterative/iterative.py +1 -1
  9. foxes/algorithms/sequential/sequential.py +4 -3
  10. foxes/config/__init__.py +1 -0
  11. foxes/config/config.py +134 -0
  12. foxes/constants.py +15 -6
  13. foxes/core/algorithm.py +22 -10
  14. foxes/core/data.py +2 -1
  15. foxes/core/engine.py +40 -34
  16. foxes/core/farm_controller.py +4 -3
  17. foxes/core/farm_data_model.py +6 -2
  18. foxes/core/model.py +2 -1
  19. foxes/core/point_data_model.py +4 -2
  20. foxes/core/rotor_model.py +8 -4
  21. foxes/core/turbine_type.py +1 -1
  22. foxes/core/wake_frame.py +7 -5
  23. foxes/core/wake_model.py +6 -1
  24. foxes/data/__init__.py +1 -1
  25. foxes/data/static_data.py +0 -7
  26. foxes/engines/dask.py +4 -3
  27. foxes/engines/single.py +1 -1
  28. foxes/input/__init__.py +1 -1
  29. foxes/input/farm_layout/from_csv.py +3 -1
  30. foxes/input/farm_layout/from_file.py +10 -10
  31. foxes/input/farm_layout/from_json.py +4 -3
  32. foxes/input/farm_layout/grid.py +3 -3
  33. foxes/input/states/create/random_abl_states.py +5 -3
  34. foxes/input/states/field_data_nc.py +22 -14
  35. foxes/input/states/multi_height.py +26 -15
  36. foxes/input/states/one_point_flow.py +6 -5
  37. foxes/input/states/scan_ws.py +4 -1
  38. foxes/input/states/single.py +15 -6
  39. foxes/input/states/slice_data_nc.py +18 -12
  40. foxes/input/states/states_table.py +17 -10
  41. foxes/input/yaml/__init__.py +3 -0
  42. foxes/input/yaml/dict.py +210 -0
  43. foxes/input/yaml/windio/__init__.py +4 -0
  44. foxes/input/{windio → yaml/windio}/get_states.py +7 -7
  45. foxes/input/{windio → yaml/windio}/read_attributes.py +61 -40
  46. foxes/input/{windio → yaml/windio}/read_farm.py +34 -43
  47. foxes/input/{windio → yaml/windio}/read_fields.py +11 -10
  48. foxes/input/yaml/windio/read_outputs.py +147 -0
  49. foxes/input/yaml/windio/windio.py +269 -0
  50. foxes/input/yaml/yaml.py +103 -0
  51. foxes/models/partial_wakes/axiwake.py +7 -6
  52. foxes/models/partial_wakes/centre.py +3 -2
  53. foxes/models/partial_wakes/segregated.py +5 -2
  54. foxes/models/point_models/set_uniform_data.py +5 -3
  55. foxes/models/rotor_models/centre.py +2 -2
  56. foxes/models/rotor_models/grid.py +5 -5
  57. foxes/models/rotor_models/levels.py +6 -6
  58. foxes/models/turbine_models/kTI_model.py +3 -1
  59. foxes/models/turbine_models/lookup_table.py +7 -4
  60. foxes/models/turbine_models/power_mask.py +14 -8
  61. foxes/models/turbine_models/sector_management.py +4 -2
  62. foxes/models/turbine_models/set_farm_vars.py +53 -23
  63. foxes/models/turbine_models/table_factors.py +8 -7
  64. foxes/models/turbine_models/yaw2yawm.py +0 -1
  65. foxes/models/turbine_models/yawm2yaw.py +0 -1
  66. foxes/models/turbine_types/CpCt_file.py +6 -3
  67. foxes/models/turbine_types/CpCt_from_two.py +6 -3
  68. foxes/models/turbine_types/PCt_file.py +7 -6
  69. foxes/models/turbine_types/PCt_from_two.py +11 -2
  70. foxes/models/turbine_types/TBL_file.py +3 -4
  71. foxes/models/turbine_types/wsrho2PCt_from_two.py +19 -11
  72. foxes/models/turbine_types/wsti2PCt_from_two.py +19 -11
  73. foxes/models/vertical_profiles/abl_log_neutral_ws.py +1 -1
  74. foxes/models/vertical_profiles/abl_log_stable_ws.py +1 -1
  75. foxes/models/vertical_profiles/abl_log_unstable_ws.py +1 -1
  76. foxes/models/vertical_profiles/abl_log_ws.py +1 -1
  77. foxes/models/wake_frames/dynamic_wakes.py +17 -9
  78. foxes/models/wake_frames/farm_order.py +4 -3
  79. foxes/models/wake_frames/rotor_wd.py +3 -1
  80. foxes/models/wake_frames/seq_dynamic_wakes.py +14 -7
  81. foxes/models/wake_frames/streamlines.py +9 -6
  82. foxes/models/wake_frames/timelines.py +21 -14
  83. foxes/models/wake_frames/yawed_wakes.py +3 -1
  84. foxes/models/wake_models/induction/vortex_sheet.py +0 -1
  85. foxes/models/wake_models/ti/crespo_hernandez.py +2 -1
  86. foxes/models/wake_models/wind/bastankhah14.py +3 -2
  87. foxes/models/wake_models/wind/bastankhah16.py +2 -1
  88. foxes/models/wake_models/wind/turbopark.py +9 -7
  89. foxes/models/wake_superpositions/ws_product.py +0 -1
  90. foxes/output/calc_points.py +7 -4
  91. foxes/output/farm_layout.py +30 -18
  92. foxes/output/farm_results_eval.py +4 -3
  93. foxes/output/grids.py +8 -7
  94. foxes/output/output.py +7 -2
  95. foxes/output/results_writer.py +10 -11
  96. foxes/output/rose_plot.py +38 -20
  97. foxes/output/rotor_point_plots.py +7 -3
  98. foxes/output/slice_data.py +1 -1
  99. foxes/output/state_turbine_map.py +5 -1
  100. foxes/output/state_turbine_table.py +7 -3
  101. foxes/output/turbine_type_curves.py +7 -2
  102. foxes/utils/dict.py +107 -3
  103. foxes/utils/geopandas_utils.py +3 -2
  104. {foxes-1.1.0.2.dist-info → foxes-1.2.dist-info}/METADATA +20 -21
  105. {foxes-1.1.0.2.dist-info → foxes-1.2.dist-info}/RECORD +122 -122
  106. {foxes-1.1.0.2.dist-info → foxes-1.2.dist-info}/WHEEL +1 -1
  107. foxes-1.2.dist-info/entry_points.txt +3 -0
  108. tests/0_consistency/iterative/test_iterative.py +65 -67
  109. tests/0_consistency/partial_wakes/test_partial_wakes.py +58 -61
  110. tests/1_verification/flappy_0_6/PCt_files/test_PCt_files.py +56 -53
  111. tests/1_verification/flappy_0_6/abl_states/test_abl_states.py +41 -41
  112. tests/1_verification/flappy_0_6/partial_top_hat/test_partial_top_hat.py +34 -34
  113. tests/1_verification/flappy_0_6/row_Jensen_linear_centre/test_row_Jensen_linear_centre.py +50 -50
  114. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat/test_row_Jensen_linear_tophat.py +51 -52
  115. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2005/test_row_Jensen_linear_tophat_IECTI_2005.py +73 -74
  116. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2019/test_row_Jensen_linear_tophat_IECTI_2019.py +73 -74
  117. tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/test_row_Jensen_quadratic_centre.py +51 -49
  118. tests/1_verification/flappy_0_6_2/grid_rotors/test_grid_rotors.py +101 -103
  119. tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/test_row_Bastankhah_Crespo.py +61 -62
  120. tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/test_row_Bastankhah_linear_centre.py +51 -52
  121. examples/windio/run.py +0 -29
  122. foxes/data/states/windio_timeseries_5000.nc +0 -0
  123. foxes/data/windio/DTU_10MW_turbine.yaml +0 -10
  124. foxes/data/windio/__init__.py +0 -0
  125. foxes/data/windio/windio_5turbines_timeseries.yaml +0 -79
  126. foxes/input/windio/__init__.py +0 -11
  127. foxes/input/windio/read_outputs.py +0 -172
  128. foxes/input/windio/runner.py +0 -183
  129. foxes/input/windio/windio.py +0 -193
  130. {foxes-1.1.0.2.dist-info → foxes-1.2.dist-info}/LICENSE +0 -0
  131. {foxes-1.1.0.2.dist-info → foxes-1.2.dist-info}/top_level.txt +0 -0
foxes/core/rotor_model.py CHANGED
@@ -1,12 +1,14 @@
1
1
  import numpy as np
2
2
  from abc import abstractmethod
3
3
 
4
+ from foxes.config import config
5
+ from foxes.utils import wd2uv, uv2wd, all_subclasses
6
+
4
7
  import foxes.variables as FV
5
8
  import foxes.constants as FC
6
- from .farm_data_model import FarmDataModel
7
- from foxes.utils import wd2uv, uv2wd, all_subclasses
8
9
 
9
10
  from .data import TData
11
+ from .farm_data_model import FarmDataModel
10
12
 
11
13
 
12
14
  class RotorModel(FarmDataModel):
@@ -146,14 +148,16 @@ class RotorModel(FarmDataModel):
146
148
  dpoints = self.design_points()
147
149
  D = fdata[FV.D]
148
150
 
149
- rax = np.zeros((n_states, n_turbines, 3, 3), dtype=FC.DTYPE)
151
+ rax = np.zeros((n_states, n_turbines, 3, 3), dtype=config.dtype_double)
150
152
  n = rax[:, :, 0, 0:2]
151
153
  m = rax[:, :, 1, 0:2]
152
154
  n[:] = wd2uv(fdata[FV.YAW], axis=-1)
153
155
  m[:] = np.stack([-n[:, :, 1], n[:, :, 0]], axis=-1)
154
156
  rax[:, :, 2, 2] = 1
155
157
 
156
- points = np.zeros((n_states, n_turbines, n_points, 3), dtype=FC.DTYPE)
158
+ points = np.zeros(
159
+ (n_states, n_turbines, n_points, 3), dtype=config.dtype_double
160
+ )
157
161
  points[:] = fdata[FV.TXYH][:, :, None, :]
158
162
  points[:] += (
159
163
  0.5 * D[:, :, None, None] * np.einsum("stad,pa->stpd", rax, dpoints)
@@ -1,7 +1,7 @@
1
1
  from abc import abstractmethod
2
2
 
3
- import foxes.constants as FC
4
3
  from foxes.utils import all_subclasses
4
+ import foxes.constants as FC
5
5
 
6
6
  from .turbine_model import TurbineModel
7
7
 
foxes/core/wake_frame.py CHANGED
@@ -3,8 +3,9 @@ import numpy as np
3
3
  from scipy.interpolate import interpn
4
4
 
5
5
  from foxes.utils import all_subclasses
6
- import foxes.constants as FC
6
+ from foxes.config import config
7
7
  import foxes.variables as FV
8
+ import foxes.constants as FC
8
9
 
9
10
  from .data import TData
10
11
  from .model import Model
@@ -243,7 +244,7 @@ class WakeFrame(Model):
243
244
  n_steps += 1
244
245
  n_ix = n_steps + 1
245
246
  xs = np.arange(xmin, xmin + n_ix * dx, dx)
246
- xpts = np.zeros((n_states, n_steps), dtype=FC.DTYPE)
247
+ xpts = np.zeros((n_states, n_steps), dtype=config.dtype_double)
247
248
  xpts[:] = xs[None, 1:]
248
249
  pts = self.get_centreline_points(algo, mdata, fdata, downwind_index, xpts)
249
250
 
@@ -251,7 +252,8 @@ class WakeFrame(Model):
251
252
  tdata = TData.from_points(
252
253
  pts,
253
254
  data={
254
- v: np.full((n_states, n_steps, 1), np.nan, dtype=FC.DTYPE) for v in vrs
255
+ v: np.full((n_states, n_steps, 1), np.nan, dtype=config.dtype_double)
256
+ for v in vrs
255
257
  },
256
258
  dims={v: (FC.STATE, FC.TARGET, FC.TPOINT) for v in vrs},
257
259
  )
@@ -280,13 +282,13 @@ class WakeFrame(Model):
280
282
  del wcalc, res
281
283
 
282
284
  # collect integration results:
283
- iresults = np.zeros((n_states, n_ix, n_vars), dtype=FC.DTYPE)
285
+ iresults = np.zeros((n_states, n_ix, n_vars), dtype=config.dtype_double)
284
286
  for vi, v in enumerate(variables):
285
287
  for i in range(n_steps):
286
288
  iresults[:, i + 1, vi] = iresults[:, i, vi] + tdata[v][:, i, 0] * dx
287
289
 
288
290
  # interpolate to x of interest:
289
- qts = np.zeros((n_states, n_points, 2), dtype=FC.DTYPE)
291
+ qts = np.zeros((n_states, n_points, 2), dtype=config.dtype_double)
290
292
  qts[:, :, 0] = np.arange(n_states)[:, None]
291
293
  qts[:, :, 1] = x
292
294
  qts = qts.reshape(n_states * n_points, 2)
foxes/core/wake_model.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from abc import abstractmethod
2
2
  import numpy as np
3
3
 
4
- from foxes.utils import all_subclasses, Factory
4
+ from foxes.utils import all_subclasses
5
5
  import foxes.variables as FV
6
6
  import foxes.constants as FC
7
7
 
@@ -259,6 +259,11 @@ class WakeK(Model):
259
259
  s = f"k_var={self.k_var}"
260
260
  return s
261
261
 
262
+ @property
263
+ def is_kTI(self):
264
+ """Flag for ka != 0"""
265
+ return self._ka is not None and self._ka != 0
266
+
262
267
  @property
263
268
  def all_none(self):
264
269
  """Flag for k=ka=kb=None"""
foxes/data/__init__.py CHANGED
@@ -3,4 +3,4 @@ Static data collection.
3
3
  """
4
4
 
5
5
  from .parse import parse_Pct_file_name, parse_Pct_two_files
6
- from .static_data import FARM, STATES, PCTCURVE, WINDIO, StaticData
6
+ from .static_data import FARM, STATES, PCTCURVE, StaticData
foxes/data/static_data.py CHANGED
@@ -3,7 +3,6 @@ from foxes.utils import DataBook
3
3
  from . import farms
4
4
  from . import states
5
5
  from . import power_ct_curves
6
- from . import windio
7
6
 
8
7
  FARM = "farm"
9
8
  """ Static wind farm data identifier
@@ -20,11 +19,6 @@ PCTCURVE = "power_ct_curve"
20
19
  :group: data
21
20
  """
22
21
 
23
- WINDIO = "windio"
24
- """ Static windio data identifier
25
- :group: data
26
- """
27
-
28
22
 
29
23
  class StaticData(DataBook):
30
24
  """
@@ -41,4 +35,3 @@ class StaticData(DataBook):
41
35
  self.add_data_package(FARM, farms, ".csv")
42
36
  self.add_data_package(STATES, states, [".csv", ".csv.gz", ".nc", ".tab"])
43
37
  self.add_data_package(PCTCURVE, power_ct_curves, ".csv")
44
- self.add_data_package(WINDIO, windio, ".yaml")
foxes/engines/dask.py CHANGED
@@ -5,6 +5,7 @@ from tqdm import tqdm
5
5
 
6
6
  from foxes.core import Engine, MData, FData, TData
7
7
  from foxes.utils import import_module
8
+ from foxes.config import config
8
9
  import foxes.variables as FV
9
10
  import foxes.constants as FC
10
11
 
@@ -212,7 +213,7 @@ def _run_as_ufunc(
212
213
  odims = {v: tuple(out_coords) for v in out_vars}
213
214
  odata = {
214
215
  v: (
215
- np.full(oshape, np.nan, dtype=FC.DTYPE)
216
+ np.full(oshape, np.nan, dtype=config.dtype_double)
216
217
  if v not in init_vars
217
218
  else prev[init_vars.index(v)].copy()
218
219
  )
@@ -264,7 +265,7 @@ def _run_as_ufunc(
264
265
 
265
266
  # create output:
266
267
  n_vars = len(out_vars)
267
- data = np.zeros(oshape + [n_vars], dtype=FC.DTYPE)
268
+ data = np.zeros(oshape + [n_vars], dtype=config.dtype_double)
268
269
  for v in out_vars:
269
270
  data[..., out_vars.index(v)] = results[v]
270
271
 
@@ -449,7 +450,7 @@ class XArrayEngine(DaskBaseEngine):
449
450
  *ldata,
450
451
  input_core_dims=[[]] + iidims + icdims,
451
452
  output_core_dims=[out_core_vars],
452
- output_dtypes=[FC.DTYPE],
453
+ output_dtypes=[config.dtype_double],
453
454
  dask="parallelized",
454
455
  dask_gufunc_kwargs=dargs,
455
456
  kwargs=wargs,
foxes/engines/single.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from xarray import Dataset
2
2
 
3
- import foxes.constants as FC
4
3
  from foxes.core import Engine
4
+ import foxes.constants as FC
5
5
 
6
6
 
7
7
  class SingleChunkEngine(Engine):
foxes/input/__init__.py CHANGED
@@ -4,4 +4,4 @@ Functions and classes for input data definition.
4
4
 
5
5
  from . import farm_layout
6
6
  from . import states
7
- from . import windio
7
+ from . import yaml
@@ -1,6 +1,7 @@
1
1
  import pandas as pd
2
2
 
3
3
  from foxes.core import Turbine
4
+ from foxes.config import get_path
4
5
 
5
6
 
6
7
  def add_from_csv(
@@ -75,7 +76,8 @@ def add_from_csv(
75
76
  else:
76
77
  if verbosity:
77
78
  print("Reading file", data_source)
78
- data = pd.read_csv(data_source, index_col=col_index)
79
+ pth = get_path(data_source)
80
+ data = pd.read_csv(pth, index_col=col_index)
79
81
 
80
82
  tmodels = turbine_parameters.pop("turbine_models", [])
81
83
  H = turbine_parameters.pop("H", None)
@@ -1,6 +1,6 @@
1
- from pathlib import Path
2
-
3
1
  from foxes.data import FARM, StaticData
2
+ from foxes.config import get_path
3
+
4
4
  from .from_json import add_from_json
5
5
  from .from_csv import add_from_csv
6
6
 
@@ -31,24 +31,24 @@ def add_from_file(farm, file_path, *args, verbosity=1, dbook=None, **kwargs):
31
31
 
32
32
  """
33
33
 
34
- fpath = Path(file_path)
34
+ fpath = get_path(file_path)
35
35
  dbook = StaticData() if dbook is None else dbook
36
36
 
37
37
  if not fpath.is_file():
38
38
  if verbosity:
39
39
  print(f"Reading static data '{fpath.name}' from context '{FARM}'")
40
- fpath = dbook.get_file_path(FARM, fpath.name, check_raw=False)
40
+ file_path = dbook.get_file_path(FARM, fpath.name, check_raw=False)
41
41
 
42
42
  if fpath.suffix == ".json":
43
- add_from_json(farm, fpath, *args, **kwargs)
43
+ add_from_json(farm, file_path, *args, **kwargs)
44
44
  elif (
45
45
  fpath.suffix == ".csv"
46
- or (len(fpath) > 7 and fpath[-7:] == ".csv.gz")
47
- or (len(fpath) > 8 and fpath[-8:] == ".csv.bz2")
48
- or (len(fpath) > 8 and fpath[-8:] == ".csv.zip")
46
+ or (len(file_path) > 7 and file_path[-7:] == ".csv.gz")
47
+ or (len(file_path) > 8 and file_path[-8:] == ".csv.bz2")
48
+ or (len(file_path) > 8 and file_path[-8:] == ".csv.zip")
49
49
  ):
50
- add_from_csv(farm, fpath, *args, verbosity=verbosity, **kwargs)
50
+ add_from_csv(farm, file_path, *args, verbosity=verbosity, **kwargs)
51
51
  else:
52
52
  raise KeyError(
53
- f"Unsupported file suffix: '{fpath}'. Please provide any of: json, csv, csv.gz, csv.bz2, csv.zip"
53
+ f"Unsupported file suffix: '{file_path}'. Please provide any of: json, csv, csv.gz, csv.bz2, csv.zip"
54
54
  )
@@ -3,6 +3,7 @@ import numpy as np
3
3
  from copy import deepcopy
4
4
 
5
5
  from foxes.core import Turbine
6
+ from foxes.config import get_path
6
7
 
7
8
 
8
9
  def add_from_json(
@@ -27,10 +28,10 @@ def add_from_json(
27
28
  :group: input.farm_layout
28
29
 
29
30
  """
30
-
31
+ fpath = get_path(file_path)
31
32
  if verbosity:
32
- print("Reading file", file_path)
33
- with open(file_path) as f:
33
+ print("Reading file", fpath)
34
+ with open(fpath) as f:
34
35
  dict = json.load(f)
35
36
 
36
37
  keys = list(dict.keys())
@@ -1,7 +1,7 @@
1
1
  import numpy as np
2
2
 
3
3
  from foxes.core import Turbine
4
- import foxes.constants as FC
4
+ from foxes.config import config
5
5
 
6
6
 
7
7
  def add_grid(
@@ -44,8 +44,8 @@ def add_grid(
44
44
  inds = list(np.ndindex(*steps))
45
45
  n_turbines = len(inds)
46
46
 
47
- xy_base = np.array(xy_base, dtype=FC.DTYPE)
48
- step_vectors = np.array(step_vectors, dtype=FC.DTYPE)
47
+ xy_base = np.array(xy_base, dtype=config.dtype_double)
48
+ step_vectors = np.array(step_vectors, dtype=config.dtype_double)
49
49
 
50
50
  for i in range(n_turbines):
51
51
  xi, yi = inds[i]
@@ -1,6 +1,7 @@
1
1
  import pandas as pd
2
2
  import numpy as np
3
3
 
4
+ from foxes.config import config, get_path
4
5
  import foxes.variables as FV
5
6
  import foxes.constants as FC
6
7
 
@@ -41,7 +42,7 @@ def create_random_abl_states(
41
42
 
42
43
  for v, mm in cols_minmax.items():
43
44
  data[v] = np.random.uniform(low=mm[0], high=mm[1], size=(n_states,)).astype(
44
- FC.DTYPE
45
+ config.dtype_double
45
46
  )
46
47
 
47
48
  cmol = var2col.get(FV.MOL, FV.MOL)
@@ -98,8 +99,9 @@ def write_random_abl_states(
98
99
 
99
100
  """
100
101
 
102
+ fpath = get_path(file_path)
101
103
  if verbosity:
102
- print("Writing file", file_path)
104
+ print("Writing file", fpath)
103
105
 
104
106
  data = create_random_abl_states(
105
107
  n_states, cols_minmax, var2col, mol_abs_range, normalize
@@ -130,4 +132,4 @@ def write_random_abl_states(
130
132
  if d is not None:
131
133
  data[v] = data[v].round(d)
132
134
 
133
- data.to_csv(file_path, **kwargs)
135
+ data.to_csv(fpath, **kwargs)
@@ -2,13 +2,13 @@ import numpy as np
2
2
  import pandas as pd
3
3
  import xarray as xr
4
4
  from scipy.interpolate import interpn
5
- from pathlib import Path
6
5
 
7
6
  from foxes.core import States
8
7
  from foxes.utils import wd2uv, uv2wd, import_module
9
8
  from foxes.data import STATES, StaticData
10
9
  import foxes.variables as FV
11
10
  import foxes.constants as FC
11
+ from foxes.config import config, get_path
12
12
 
13
13
 
14
14
  class FieldDataNC(States):
@@ -150,9 +150,11 @@ class FieldDataNC(States):
150
150
  if "*" in str(self.data_source):
151
151
  pass
152
152
  else:
153
- self.__data_source = StaticData().get_file_path(
154
- STATES, self.data_source, check_raw=True
155
- )
153
+ self.__data_source = get_path(self.data_source)
154
+ if not self.data_source.is_file():
155
+ self.__data_source = StaticData().get_file_path(
156
+ STATES, self.data_source.name, check_raw=False
157
+ )
156
158
  if verbosity:
157
159
  if pre_load:
158
160
  print(
@@ -164,13 +166,14 @@ class FieldDataNC(States):
164
166
  )
165
167
 
166
168
  def _read_ds():
167
- if Path(self.data_source).is_file():
168
- return xr.open_dataset(self.data_source)
169
+ fpath = get_path(self.data_source)
170
+ if fpath.is_file():
171
+ return xr.open_dataset(fpath)
169
172
  else:
170
173
  # try to read multiple files, needs dask:
171
174
  try:
172
175
  return xr.open_mfdataset(
173
- str(self.data_source),
176
+ str(fpath),
174
177
  parallel=False,
175
178
  concat_dim=self.states_coord,
176
179
  combine="nested",
@@ -182,8 +185,7 @@ class FieldDataNC(States):
182
185
  import_module("dask", hint="pip install dask")
183
186
  raise e
184
187
 
185
- with _read_ds() as ds:
186
- self.__data_source = ds
188
+ self.__data_source = _read_ds()
187
189
 
188
190
  if sel is not None:
189
191
  self.__data_source = self.data_source.sel(self.sel)
@@ -275,7 +277,9 @@ class FieldDataNC(States):
275
277
  f"States '{self.name}': Wrong coordinate order for variable '{ncv}': Found {ds[ncv].dims}, expecting {cor_shxy}, {cor_shyx}, {cor_sh} or {cor_s}"
276
278
  )
277
279
 
278
- data = np.zeros((n_sts, n_h, n_y, n_x, len(self.var2ncvar)), dtype=FC.DTYPE)
280
+ data = np.zeros(
281
+ (n_sts, n_h, n_y, n_x, len(self.var2ncvar)), dtype=config.dtype_double
282
+ )
279
283
  for v in vars_shyx:
280
284
  ncv = self.var2ncvar[v]
281
285
  if ds[ncv].dims == cor_shyx:
@@ -290,7 +294,9 @@ class FieldDataNC(States):
290
294
  data[..., self._dkys[v]] = ds[ncv].to_numpy()[:, None, None, None]
291
295
  if FV.WD in self.fixed_vars:
292
296
  data[..., self._dkys[FV.WD]] = np.full(
293
- (n_sts, n_h, n_y, n_x), self.fixed_vars[FV.WD], dtype=FC.DTYPE
297
+ (n_sts, n_h, n_y, n_x),
298
+ self.fixed_vars[FV.WD],
299
+ dtype=config.dtype_double,
294
300
  )
295
301
 
296
302
  if verbosity > 1:
@@ -365,7 +371,7 @@ class FieldDataNC(States):
365
371
 
366
372
  if self.__weights is None:
367
373
  self.__weights = np.full(
368
- (self._N, algo.n_turbines), 1.0 / self._N, dtype=FC.DTYPE
374
+ (self._N, algo.n_turbines), 1.0 / self._N, dtype=config.dtype_double
369
375
  )
370
376
 
371
377
  idata = super().load_data(algo, verbosity)
@@ -608,7 +614,9 @@ class FieldDataNC(States):
608
614
 
609
615
  # prepare points:
610
616
  sts = np.arange(n_states)
611
- pts = np.append(points, np.zeros((n_states, n_pts, 1), dtype=FC.DTYPE), axis=2)
617
+ pts = np.append(
618
+ points, np.zeros((n_states, n_pts, 1), dtype=config.dtype_double), axis=2
619
+ )
612
620
  pts[:, :, 3] = sts[:, None]
613
621
  pts = pts.reshape(n_states * n_pts, 4)
614
622
  pts = np.flip(pts, axis=1)
@@ -697,7 +705,7 @@ class FieldDataNC(States):
697
705
  out[v] = data[..., self._dkys[v]]
698
706
  else:
699
707
  out[v] = np.full(
700
- (n_states, n_pts), self.fixed_vars[v], dtype=FC.DTYPE
708
+ (n_states, n_pts), self.fixed_vars[v], dtype=config.dtype_double
701
709
  )
702
710
 
703
711
  return {v: d.reshape(n_states, n_targets, n_tpoints) for v, d in out.items()}
@@ -1,15 +1,15 @@
1
1
  import numpy as np
2
2
  import pandas as pd
3
3
  from xarray import Dataset, open_dataset
4
- from pathlib import Path
5
4
  from scipy.interpolate import interp1d
6
5
 
7
6
  from foxes.core import States
8
7
  from foxes.utils import PandasFileHelper
9
8
  from foxes.data import STATES
9
+ from foxes.config import config, get_path
10
+ from foxes.utils import wd2uv, uv2wd
10
11
  import foxes.variables as FV
11
12
  import foxes.constants as FC
12
- from foxes.utils import wd2uv, uv2wd
13
13
 
14
14
 
15
15
  class MultiHeightStates(States):
@@ -92,7 +92,7 @@ class MultiHeightStates(States):
92
92
  super().__init__()
93
93
 
94
94
  self.ovars = output_vars
95
- self.heights = np.array(heights, dtype=FC.DTYPE)
95
+ self.heights = np.array(heights, dtype=config.dtype_double)
96
96
  self.rpars = pd_read_pars
97
97
  self.var2col = var2col
98
98
  self.fixed_vars = fixed_vars
@@ -198,13 +198,14 @@ class MultiHeightStates(States):
198
198
 
199
199
  """
200
200
  if not isinstance(self.data_source, pd.DataFrame):
201
- if not Path(self.data_source).is_file():
201
+ self._data_source = get_path(self.data_source)
202
+ if not self.data_source.is_file():
202
203
  if verbosity:
203
204
  print(
204
205
  f"States '{self.name}': Reading static data '{self.data_source}' from context '{STATES}'"
205
206
  )
206
207
  self._data_source = algo.dbook.get_file_path(
207
- STATES, self.data_source, check_raw=False
208
+ STATES, self.data_source.name, check_raw=False
208
209
  )
209
210
  if verbosity:
210
211
  print(f"Path: {self.data_source}")
@@ -226,7 +227,7 @@ class MultiHeightStates(States):
226
227
  self._inds = data.index.to_numpy()
227
228
 
228
229
  col_w = self.var2col.get(FV.WEIGHT, FV.WEIGHT)
229
- self._weights = np.zeros((self._N, algo.n_turbines), dtype=FC.DTYPE)
230
+ self._weights = np.zeros((self._N, algo.n_turbines), dtype=config.dtype_double)
230
231
  if col_w in data:
231
232
  self._weights[:] = data[col_w].to_numpy()[:, None]
232
233
  elif FV.WEIGHT in self.var2col:
@@ -446,7 +447,7 @@ class MultiHeightStates(States):
446
447
  vrs = list(mdata[self.VARS])
447
448
  n_vars = len(vrs)
448
449
 
449
- coeffs = np.zeros((n_h, n_h), dtype=FC.DTYPE)
450
+ coeffs = np.zeros((n_h, n_h), dtype=config.dtype_double)
450
451
  np.fill_diagonal(coeffs, 1.0)
451
452
  ipars = dict(
452
453
  assume_sorted=True,
@@ -499,10 +500,14 @@ class MultiHeightStates(States):
499
500
  elif has_wd and v == FV.WS:
500
501
  results[v] = np.linalg.norm(uv, axis=-1)
501
502
  elif v in self.fixed_vars:
502
- results[v] = np.zeros((n_states, n_targets, n_tpoints), dtype=FC.DTYPE)
503
+ results[v] = np.zeros(
504
+ (n_states, n_targets, n_tpoints), dtype=config.dtype_double
505
+ )
503
506
  results[v][:] = self.fixed_vars[v]
504
507
  elif v in self._solo:
505
- results[v] = np.zeros((n_states, n_targets, n_tpoints), dtype=FC.DTYPE)
508
+ results[v] = np.zeros(
509
+ (n_states, n_targets, n_tpoints), dtype=config.dtype_double
510
+ )
506
511
  results[v][:] = mdata[self.var(v)][:, None, None]
507
512
  else:
508
513
  results[v] = ires[vrs.index(v)]
@@ -620,13 +625,14 @@ class MultiHeightNCStates(MultiHeightStates):
620
625
 
621
626
  """
622
627
  if not isinstance(self.data_source, Dataset):
623
- if not Path(self.data_source).is_file():
628
+ self._data_source = get_path(self.data_source)
629
+ if not self.data_source.is_file():
624
630
  if verbosity:
625
631
  print(
626
632
  f"States '{self.name}': Reading static data '{self.data_source}' from context '{STATES}'"
627
633
  )
628
634
  self._data_source = algo.dbook.get_file_path(
629
- STATES, self.data_source, check_raw=False
635
+ STATES, self.data_source.name, check_raw=False
630
636
  )
631
637
  if verbosity:
632
638
  print(f"Path: {self.data_source}")
@@ -652,7 +658,7 @@ class MultiHeightNCStates(MultiHeightStates):
652
658
  self._inds = format_times_func(self._inds)
653
659
 
654
660
  w_name = self.var2col.get(FV.WEIGHT, FV.WEIGHT)
655
- self._weights = np.zeros((self._N, algo.n_turbines), dtype=FC.DTYPE)
661
+ self._weights = np.zeros((self._N, algo.n_turbines), dtype=config.dtype_double)
656
662
  if w_name in data.data_vars:
657
663
  if data[w_name].dims != (self.state_coord,):
658
664
  raise ValueError(
@@ -664,7 +670,9 @@ class MultiHeightNCStates(MultiHeightStates):
664
670
  f"Weight variable '{w_name}' defined in var2col, but not found in data_vars {list(data.data_vars.keys())}"
665
671
  )
666
672
  else:
667
- self._weights = np.zeros((self._N, algo.n_turbines), dtype=FC.DTYPE)
673
+ self._weights = np.zeros(
674
+ (self._N, algo.n_turbines), dtype=config.dtype_double
675
+ )
668
676
  self._weights[:] = 1.0 / self._N
669
677
 
670
678
  cols = {}
@@ -707,11 +715,14 @@ class MultiHeightNCStates(MultiHeightStates):
707
715
  dims,
708
716
  np.stack(
709
717
  [data.data_vars[c].to_numpy() for c in cols.values()], axis=1
710
- ).astype(FC.DTYPE),
718
+ ).astype(config.dtype_double),
711
719
  )
712
720
 
713
721
  for v, d in self._solo.items():
714
- idata["data_vars"][self.var(v)] = ((FC.STATE,), d.astype(FC.DTYPE))
722
+ idata["data_vars"][self.var(v)] = (
723
+ (FC.STATE,),
724
+ d.astype(config.dtype_double),
725
+ )
715
726
  self._solo = list(self._solo.keys())
716
727
 
717
728
  return idata
@@ -4,6 +4,7 @@ from scipy.interpolate import interpn
4
4
  from foxes.core import States
5
5
  from foxes.utils import uv2wd
6
6
  from foxes.models.wake_frames.timelines import Timelines
7
+ from foxes.config import config
7
8
  import foxes.variables as FV
8
9
  import foxes.constants as FC
9
10
 
@@ -65,7 +66,7 @@ class OnePointFlowStates(States):
65
66
 
66
67
  """
67
68
  super().__init__()
68
- self.ref_xy = np.array(ref_xy, dtype=FC.DTYPE)
69
+ self.ref_xy = np.array(ref_xy, dtype=config.dtype_double)
69
70
  self.heights = tl_heights
70
71
  self.base_states = base_states
71
72
  self.dt_min = dt_min
@@ -268,9 +269,9 @@ class OnePointFlowStates(States):
268
269
 
269
270
  i0 = mdata.states_i0(counter=True)
270
271
  trace_p = points[:, :, :2] - ref_xy[:, :, :2]
271
- trace_si = np.zeros((n_states, n_points), dtype=FC.ITYPE)
272
+ trace_si = np.zeros((n_states, n_points), dtype=config.dtype_int)
272
273
  trace_si[:] = i0 + np.arange(n_states)[:, None]
273
- coeffs = np.full((n_states, n_points), np.nan, dtype=FC.DTYPE)
274
+ coeffs = np.full((n_states, n_points), np.nan, dtype=config.dtype_double)
274
275
 
275
276
  # flake8: noqa: F821
276
277
  def _eval_trace(sel, hdxy=None, hdxy0=None, trs=None):
@@ -396,7 +397,7 @@ class OnePointFlowStates(States):
396
397
  sts = trace_si[hi]
397
398
  cfs = coeffs[hi]
398
399
  data = self.timelines_data[v].to_numpy()[hi]
399
- out = np.zeros(sts.shape, dtype=FC.DTYPE)
400
+ out = np.zeros(sts.shape, dtype=config.dtype_double)
400
401
 
401
402
  sel_low = sts < 0
402
403
  if np.any(sel_low):
@@ -436,7 +437,7 @@ class OnePointFlowStates(States):
436
437
  vres = list(data.keys())
437
438
  data = np.stack(list(data.values()), axis=-1)
438
439
 
439
- eval = np.zeros((n_states, n_points, 3), dtype=FC.DTYPE)
440
+ eval = np.zeros((n_states, n_points, 3), dtype=config.dtype_double)
440
441
  eval[:, :, 0] = points[:, :, 2]
441
442
  eval[:, :, 1] = ar_states[:, None]
442
443
  eval[:, :, 2] = ar_points[None, :]
@@ -1,6 +1,7 @@
1
1
  import numpy as np
2
2
 
3
3
  from foxes.core import States
4
+ from foxes.config import config
4
5
  import foxes.variables as FV
5
6
  import foxes.constants as FC
6
7
 
@@ -198,7 +199,9 @@ class ScanWS(States):
198
199
  The weights, shape: (n_states, n_turbines)
199
200
 
200
201
  """
201
- return np.full((self.N, algo.n_turbines), 1.0 / self.N, dtype=FC.DTYPE)
202
+ return np.full(
203
+ (self.N, algo.n_turbines), 1.0 / self.N, dtype=config.dtype_double
204
+ )
202
205
 
203
206
  def calculate(self, algo, mdata, fdata, tdata):
204
207
  """