foxes 1.2.5__py3-none-any.whl → 1.4__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 (201) hide show
  1. docs/source/conf.py +3 -3
  2. examples/abl_states/run.py +2 -2
  3. examples/compare_rotors_pwakes/run.py +1 -1
  4. examples/compare_wakes/run.py +1 -2
  5. examples/dyn_wakes/run.py +29 -6
  6. examples/induction/run.py +3 -3
  7. examples/multi_height/run.py +1 -1
  8. examples/power_mask/run.py +2 -2
  9. examples/quickstart/run.py +16 -0
  10. examples/random_timeseries/run.py +3 -4
  11. examples/scan_row/run.py +3 -3
  12. examples/sequential/run.py +33 -10
  13. examples/single_state/run.py +3 -4
  14. examples/states_lookup_table/run.py +3 -3
  15. examples/streamline_wakes/run.py +27 -4
  16. examples/tab_file/run.py +3 -3
  17. examples/timelines/run.py +29 -5
  18. examples/timeseries/run.py +3 -3
  19. examples/timeseries_slurm/run.py +3 -3
  20. examples/wind_rose/run.py +3 -3
  21. examples/yawed_wake/run.py +16 -8
  22. foxes/__init__.py +22 -18
  23. foxes/algorithms/__init__.py +6 -6
  24. foxes/algorithms/downwind/__init__.py +2 -2
  25. foxes/algorithms/downwind/downwind.py +53 -27
  26. foxes/algorithms/downwind/models/__init__.py +6 -6
  27. foxes/algorithms/downwind/models/farm_wakes_calc.py +22 -14
  28. foxes/algorithms/downwind/models/init_farm_data.py +4 -5
  29. foxes/algorithms/downwind/models/point_wakes_calc.py +7 -13
  30. foxes/algorithms/downwind/models/reorder_farm_output.py +5 -1
  31. foxes/algorithms/downwind/models/set_amb_point_results.py +7 -7
  32. foxes/algorithms/iterative/__init__.py +7 -3
  33. foxes/algorithms/iterative/iterative.py +1 -2
  34. foxes/algorithms/iterative/models/__init__.py +7 -3
  35. foxes/algorithms/iterative/models/farm_wakes_calc.py +15 -8
  36. foxes/algorithms/sequential/__init__.py +3 -3
  37. foxes/algorithms/sequential/models/__init__.py +2 -2
  38. foxes/algorithms/sequential/models/seq_state.py +0 -18
  39. foxes/algorithms/sequential/sequential.py +8 -22
  40. foxes/config/__init__.py +5 -1
  41. foxes/constants.py +22 -0
  42. foxes/core/__init__.py +45 -22
  43. foxes/core/algorithm.py +0 -1
  44. foxes/core/data.py +56 -29
  45. foxes/core/engine.py +28 -14
  46. foxes/core/farm_controller.py +2 -2
  47. foxes/core/farm_data_model.py +1 -0
  48. foxes/core/ground_model.py +4 -13
  49. foxes/core/model.py +5 -5
  50. foxes/core/partial_wakes_model.py +147 -10
  51. foxes/core/point_data_model.py +2 -3
  52. foxes/core/rotor_model.py +42 -38
  53. foxes/core/states.py +4 -50
  54. foxes/core/turbine.py +2 -1
  55. foxes/core/wake_deflection.py +130 -0
  56. foxes/core/wake_model.py +222 -9
  57. foxes/core/wake_superposition.py +122 -4
  58. foxes/core/wind_farm.py +6 -6
  59. foxes/data/__init__.py +7 -2
  60. foxes/data/states/weibull_sectors_12.csv +13 -0
  61. foxes/data/states/weibull_sectors_12.nc +0 -0
  62. foxes/engines/__init__.py +14 -15
  63. foxes/engines/dask.py +39 -14
  64. foxes/engines/numpy.py +0 -3
  65. foxes/input/__init__.py +3 -3
  66. foxes/input/farm_layout/__init__.py +8 -8
  67. foxes/input/farm_layout/from_csv.py +1 -1
  68. foxes/input/farm_layout/ring.py +0 -1
  69. foxes/input/states/__init__.py +22 -11
  70. foxes/input/states/create/__init__.py +3 -2
  71. foxes/input/states/field_data_nc.py +48 -84
  72. foxes/input/states/multi_height.py +40 -60
  73. foxes/input/states/one_point_flow.py +22 -25
  74. foxes/input/states/scan.py +6 -19
  75. foxes/input/states/single.py +6 -18
  76. foxes/input/states/states_table.py +25 -44
  77. foxes/input/states/weibull_sectors.py +225 -0
  78. foxes/input/states/wrg_states.py +151 -37
  79. foxes/input/yaml/__init__.py +9 -3
  80. foxes/input/yaml/dict.py +19 -19
  81. foxes/input/yaml/windio/__init__.py +10 -5
  82. foxes/input/yaml/windio/read_attributes.py +2 -2
  83. foxes/input/yaml/windio/read_farm.py +5 -5
  84. foxes/input/yaml/windio/read_fields.py +4 -2
  85. foxes/input/yaml/windio/read_site.py +52 -0
  86. foxes/input/yaml/windio/windio.py +1 -1
  87. foxes/models/__init__.py +15 -14
  88. foxes/models/axial_induction/__init__.py +2 -2
  89. foxes/models/farm_controllers/__init__.py +1 -1
  90. foxes/models/farm_models/__init__.py +1 -1
  91. foxes/models/ground_models/__init__.py +3 -2
  92. foxes/models/ground_models/wake_mirror.py +3 -3
  93. foxes/models/model_book.py +175 -49
  94. foxes/models/partial_wakes/__init__.py +6 -6
  95. foxes/models/partial_wakes/axiwake.py +30 -5
  96. foxes/models/partial_wakes/centre.py +47 -0
  97. foxes/models/partial_wakes/rotor_points.py +45 -9
  98. foxes/models/partial_wakes/segregated.py +2 -20
  99. foxes/models/partial_wakes/top_hat.py +27 -2
  100. foxes/models/point_models/__init__.py +4 -4
  101. foxes/models/rotor_models/__init__.py +3 -3
  102. foxes/models/rotor_models/centre.py +6 -4
  103. foxes/models/turbine_models/__init__.py +11 -11
  104. foxes/models/turbine_models/set_farm_vars.py +0 -1
  105. foxes/models/turbine_types/PCt_file.py +0 -2
  106. foxes/models/turbine_types/PCt_from_two.py +0 -2
  107. foxes/models/turbine_types/__init__.py +9 -9
  108. foxes/models/vertical_profiles/__init__.py +7 -7
  109. foxes/models/wake_deflections/__init__.py +3 -0
  110. foxes/models/{wake_frames/yawed_wakes.py → wake_deflections/bastankhah2016.py} +32 -111
  111. foxes/models/wake_deflections/jimenez.py +277 -0
  112. foxes/models/wake_deflections/no_deflection.py +94 -0
  113. foxes/models/wake_frames/__init__.py +6 -7
  114. foxes/models/wake_frames/dynamic_wakes.py +12 -3
  115. foxes/models/wake_frames/rotor_wd.py +3 -1
  116. foxes/models/wake_frames/seq_dynamic_wakes.py +45 -8
  117. foxes/models/wake_frames/streamlines.py +8 -6
  118. foxes/models/wake_frames/timelines.py +19 -3
  119. foxes/models/wake_models/__init__.py +7 -7
  120. foxes/models/wake_models/dist_sliced.py +50 -84
  121. foxes/models/wake_models/gaussian.py +20 -0
  122. foxes/models/wake_models/induction/__init__.py +5 -5
  123. foxes/models/wake_models/induction/rankine_half_body.py +30 -71
  124. foxes/models/wake_models/induction/rathmann.py +65 -64
  125. foxes/models/wake_models/induction/self_similar.py +65 -68
  126. foxes/models/wake_models/induction/self_similar2020.py +0 -3
  127. foxes/models/wake_models/induction/vortex_sheet.py +71 -75
  128. foxes/models/wake_models/ti/__init__.py +2 -2
  129. foxes/models/wake_models/ti/crespo_hernandez.py +5 -3
  130. foxes/models/wake_models/ti/iec_ti.py +6 -4
  131. foxes/models/wake_models/top_hat.py +58 -7
  132. foxes/models/wake_models/wind/__init__.py +6 -4
  133. foxes/models/wake_models/wind/bastankhah14.py +25 -7
  134. foxes/models/wake_models/wind/bastankhah16.py +35 -3
  135. foxes/models/wake_models/wind/jensen.py +15 -2
  136. foxes/models/wake_models/wind/turbopark.py +28 -2
  137. foxes/models/wake_superpositions/__init__.py +18 -9
  138. foxes/models/wake_superpositions/ti_linear.py +4 -4
  139. foxes/models/wake_superpositions/ti_max.py +4 -4
  140. foxes/models/wake_superpositions/ti_pow.py +4 -4
  141. foxes/models/wake_superpositions/ti_quadratic.py +4 -4
  142. foxes/models/wake_superpositions/wind_vector.py +257 -0
  143. foxes/models/wake_superpositions/ws_linear.py +9 -10
  144. foxes/models/wake_superpositions/ws_max.py +8 -8
  145. foxes/models/wake_superpositions/ws_pow.py +8 -8
  146. foxes/models/wake_superpositions/ws_product.py +4 -4
  147. foxes/models/wake_superpositions/ws_quadratic.py +8 -8
  148. foxes/output/__init__.py +21 -19
  149. foxes/output/farm_layout.py +14 -6
  150. foxes/output/farm_results_eval.py +51 -27
  151. foxes/output/flow_plots_2d/__init__.py +2 -2
  152. foxes/output/flow_plots_2d/get_fig.py +4 -2
  153. foxes/output/rose_plot.py +23 -5
  154. foxes/output/seq_plugins/__init__.py +2 -2
  155. foxes/output/seq_plugins/seq_flow_ani_plugin.py +0 -3
  156. foxes/output/seq_plugins/seq_wake_debug_plugin.py +0 -1
  157. foxes/output/slice_data.py +16 -19
  158. foxes/output/turbine_type_curves.py +7 -8
  159. foxes/utils/__init__.py +37 -19
  160. foxes/utils/abl/__init__.py +4 -4
  161. foxes/utils/cubic_roots.py +1 -1
  162. foxes/utils/data_book.py +4 -3
  163. foxes/utils/dict.py +3 -3
  164. foxes/utils/exec_python.py +5 -5
  165. foxes/utils/factory.py +1 -3
  166. foxes/utils/geom2d/__init__.py +7 -5
  167. foxes/utils/geopandas_utils.py +2 -2
  168. foxes/utils/pandas_utils.py +4 -3
  169. foxes/utils/tab_files.py +0 -1
  170. foxes/utils/weibull.py +28 -0
  171. foxes/utils/wrg_utils.py +3 -1
  172. foxes/utils/xarray_utils.py +9 -2
  173. foxes/variables.py +67 -9
  174. {foxes-1.2.5.dist-info → foxes-1.4.dist-info}/METADATA +14 -21
  175. foxes-1.4.dist-info/RECORD +320 -0
  176. {foxes-1.2.5.dist-info → foxes-1.4.dist-info}/WHEEL +1 -1
  177. tests/0_consistency/iterative/test_iterative.py +2 -3
  178. tests/0_consistency/partial_wakes/test_partial_wakes.py +2 -2
  179. tests/1_verification/flappy_0_6/PCt_files/flappy/run.py +2 -3
  180. tests/1_verification/flappy_0_6/PCt_files/test_PCt_files.py +48 -56
  181. tests/1_verification/flappy_0_6/abl_states/flappy/run.py +0 -1
  182. tests/1_verification/flappy_0_6/abl_states/test_abl_states.py +33 -36
  183. tests/1_verification/flappy_0_6/partial_top_hat/flappy/run.py +0 -1
  184. tests/1_verification/flappy_0_6/partial_top_hat/test_partial_top_hat.py +0 -2
  185. tests/1_verification/flappy_0_6/row_Jensen_linear_centre/test_row_Jensen_linear_centre.py +3 -3
  186. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat/test_row_Jensen_linear_tophat.py +3 -4
  187. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2005/test_row_Jensen_linear_tophat_IECTI_2005.py +3 -4
  188. tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2019/test_row_Jensen_linear_tophat_IECTI_2019.py +3 -4
  189. tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/test_row_Jensen_quadratic_centre.py +3 -4
  190. tests/1_verification/flappy_0_6_2/grid_rotors/flappy/run.py +0 -2
  191. tests/1_verification/flappy_0_6_2/grid_rotors/test_grid_rotors.py +3 -3
  192. tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/test_row_Bastankhah_Crespo.py +3 -3
  193. tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/flappy/run.py +0 -1
  194. tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/test_row_Bastankhah_linear_centre.py +3 -4
  195. tests/3_examples/test_examples.py +3 -2
  196. foxes/output/round.py +0 -10
  197. foxes/utils/pandas_helpers.py +0 -178
  198. foxes-1.2.5.dist-info/RECORD +0 -312
  199. {foxes-1.2.5.dist-info → foxes-1.4.dist-info}/entry_points.txt +0 -0
  200. {foxes-1.2.5.dist-info → foxes-1.4.dist-info/licenses}/LICENSE +0 -0
  201. {foxes-1.2.5.dist-info → foxes-1.4.dist-info}/top_level.txt +0 -0
@@ -6,10 +6,11 @@ import inspect
6
6
  import foxes
7
7
  import foxes.variables as FV
8
8
 
9
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
10
-
11
9
 
12
10
  def test():
11
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
12
+ print("TESTDIR:", thisdir)
13
+
13
14
  n_s = 800
14
15
  n_t = 76
15
16
  p0 = np.array([0.0, 0.0])
@@ -43,7 +44,6 @@ def test():
43
44
  )
44
45
 
45
46
  with foxes.Engine.new("threads", chunk_size_states=1000):
46
-
47
47
  algo = foxes.algorithms.Downwind(
48
48
  farm,
49
49
  states,
@@ -5,12 +5,12 @@ import inspect
5
5
 
6
6
  import foxes
7
7
  import foxes.variables as FV
8
- from foxes.config import config
9
-
10
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
8
 
12
9
 
13
10
  def test():
11
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
12
+ print("TESTDIR:", thisdir)
13
+
14
14
  n_s = 1000
15
15
  n_t = 55
16
16
  c = 1000
@@ -45,7 +45,6 @@ def test():
45
45
  )
46
46
 
47
47
  with foxes.Engine.new("threads", chunk_size_states=c):
48
-
49
48
  algo = foxes.algorithms.Downwind(
50
49
  farm,
51
50
  states,
@@ -5,12 +5,12 @@ import inspect
5
5
 
6
6
  import foxes
7
7
  import foxes.variables as FV
8
- from foxes.config import config
9
-
10
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
8
 
12
9
 
13
10
  def test():
11
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
12
+ print("TESTDIR:", thisdir)
13
+
14
14
  n_s = 30
15
15
  n_t = 52
16
16
  wd = 270.0
@@ -48,7 +48,6 @@ def test():
48
48
  )
49
49
 
50
50
  with foxes.Engine.new("threads", chunk_size_states=c):
51
-
52
51
  algo = foxes.algorithms.Downwind(
53
52
  farm,
54
53
  states,
@@ -5,12 +5,12 @@ import inspect
5
5
 
6
6
  import foxes
7
7
  import foxes.variables as FV
8
- from foxes.config import config
9
-
10
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
8
 
12
9
 
13
10
  def test():
11
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
12
+ print("TESTDIR:", thisdir)
13
+
14
14
  n_s = 30
15
15
  n_t = 52
16
16
  wd = 270.0
@@ -48,7 +48,6 @@ def test():
48
48
  )
49
49
 
50
50
  with foxes.Engine.new("threads", chunk_size_states=c):
51
-
52
51
  algo = foxes.algorithms.Downwind(
53
52
  farm,
54
53
  states,
@@ -5,12 +5,12 @@ import inspect
5
5
 
6
6
  import foxes
7
7
  import foxes.variables as FV
8
- from foxes.config import config
9
-
10
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
8
 
12
9
 
13
10
  def test():
11
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
12
+ print("TESTDIR:", thisdir)
13
+
14
14
  n_s = 800
15
15
  n_t = 76
16
16
  c = 1000
@@ -45,7 +45,6 @@ def test():
45
45
  )
46
46
 
47
47
  with foxes.Engine.new("threads", chunk_size_states=c):
48
-
49
48
  algo = foxes.algorithms.Downwind(
50
49
  farm,
51
50
  states,
@@ -1,6 +1,4 @@
1
1
  import numpy as np
2
- import pandas as pd
3
- import time
4
2
  import argparse
5
3
  from pathlib import Path
6
4
 
@@ -4,12 +4,12 @@ import inspect
4
4
 
5
5
  import foxes
6
6
  import foxes.variables as FV
7
- from foxes.config import config
8
-
9
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
10
7
 
11
8
 
12
9
  def test():
10
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
11
+ print("TESTDIR:", thisdir)
12
+
13
13
  c = 500
14
14
  cpath = thisdir / "flappy"
15
15
  tfile = thisdir / "NREL-5MW-D126-H90.csv"
@@ -6,10 +6,11 @@ import inspect
6
6
  import foxes
7
7
  import foxes.variables as FV
8
8
 
9
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
10
-
11
9
 
12
10
  def test():
11
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
12
+ print("TESTDIR:", thisdir)
13
+
13
14
  n_s = 30
14
15
  n_t = 52
15
16
  wd = 270.0
@@ -54,7 +55,6 @@ def test():
54
55
  )
55
56
 
56
57
  with foxes.Engine.new("threads", chunk_size_states=c):
57
-
58
58
  algo = foxes.algorithms.Downwind(
59
59
  farm,
60
60
  states,
@@ -1,5 +1,4 @@
1
1
  import numpy as np
2
- import pandas as pd
3
2
  import time
4
3
  import argparse
5
4
  from pathlib import Path
@@ -5,12 +5,12 @@ import inspect
5
5
 
6
6
  import foxes
7
7
  import foxes.variables as FV
8
- from foxes.config import config
9
-
10
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
11
8
 
12
9
 
13
10
  def test():
11
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
12
+ print("TESTDIR:", thisdir)
13
+
14
14
  n_s = 99
15
15
  n_t = 84
16
16
  wd = 88.1
@@ -52,7 +52,6 @@ def test():
52
52
  )
53
53
 
54
54
  with foxes.Engine.new("threads", chunk_size_states=c):
55
-
56
55
  algo = foxes.algorithms.Downwind(
57
56
  farm,
58
57
  states,
@@ -5,10 +5,11 @@ import os
5
5
 
6
6
  from foxes.utils import load_module
7
7
 
8
- thisdir = Path(inspect.getfile(inspect.currentframe())).parent
9
-
10
8
 
11
9
  def test():
10
+ thisdir = Path(inspect.getabsfile(inspect.currentframe())).parent
11
+ print("TESTDIR:", thisdir)
12
+
12
13
  rdir = thisdir.parent.parent / "examples"
13
14
  rpath = rdir / "run_all.py"
14
15
  print(rpath)
foxes/output/round.py DELETED
@@ -1,10 +0,0 @@
1
- import foxes.variables as FV
2
- import foxes.constants as FC
3
-
4
- round_defaults = {v: 4 for v in FV.__dict__.keys() if isinstance(v, str)}
5
- round_defaults[FV.WD] = 3
6
- round_defaults[FV.YAW] = 3
7
- round_defaults[FV.TI] = 6
8
- round_defaults[FV.RHO] = 6
9
- round_defaults[FC.XYH] = 3
10
- round_defaults.update({FV.var2amb[v]: round_defaults[v] for v in FV.var2amb.keys()})
@@ -1,178 +0,0 @@
1
- import pandas as pd
2
- import xarray
3
- from copy import deepcopy
4
-
5
- import foxes.variables as FV
6
-
7
-
8
- class PandasFileHelper:
9
- """
10
- This class helps reading and writing data
11
- to files via pandas.
12
-
13
- Attributes
14
- ----------
15
- DEFAULT_READING_PARAMETERS: dict
16
- Default parameters for file reading
17
- for the supported file formats
18
- DEFAULT_WRITING_PARAMETERS: dict
19
- Default parameters for file writing
20
- for the supported file formats
21
- DATA_FILE_FORMAT: list:str
22
- The supported file formats for data export
23
- DEFAULT_FORMAT_DICT: dict
24
- Default column formatting
25
-
26
- :group: utils
27
-
28
- """
29
-
30
- DEFAULT_READING_PARAMETERS = {
31
- "csv": {},
32
- "csv.gz": {},
33
- "csv.bz2": {},
34
- "csv.zip": {},
35
- "h5": {},
36
- "nc": {},
37
- }
38
-
39
- DEFAULT_WRITING_PARAMETERS = {
40
- "csv": {},
41
- "csv.gz": {},
42
- "csv.bz2": {},
43
- "csv.zip": {},
44
- "h5": {"key": "foxes", "mode": "w"},
45
- "nc": {},
46
- }
47
-
48
- DEFAULT_FORMAT_DICT = {
49
- FV.WD: "{:.3f}",
50
- FV.AMB_WD: "{:.3f}",
51
- FV.WS: "{:.4f}",
52
- FV.AMB_WS: "{:.4f}",
53
- FV.REWS: "{:.4f}",
54
- FV.AMB_REWS: "{:.4f}",
55
- FV.REWS2: "{:.4f}",
56
- FV.AMB_REWS2: "{:.4f}",
57
- FV.REWS3: "{:.4f}",
58
- FV.AMB_REWS3: "{:.4f}",
59
- FV.TI: "{:.6f}",
60
- FV.AMB_TI: "{:.6f}",
61
- FV.RHO: "{:.5f}",
62
- FV.AMB_RHO: "{:.5f}",
63
- FV.P: "{:.3f}",
64
- FV.AMB_P: "{:.3f}",
65
- FV.CT: "{:.6f}",
66
- FV.AMB_CT: "{:.6f}",
67
- FV.T: "{:.3f}",
68
- FV.AMB_T: "{:.3f}",
69
- FV.YLD: "{:.3f}",
70
- FV.AMB_YLD: "{:.3f}",
71
- FV.CAP: "{:.5f}",
72
- FV.AMB_CAP: "{:.5f}",
73
- FV.EFF: "{:.5f}",
74
- }
75
-
76
- DATA_FILE_FORMATS = list(DEFAULT_READING_PARAMETERS.keys())
77
-
78
- @classmethod
79
- def read_file(cls, file_path, **kwargs):
80
- """
81
- Helper for reading data according to file ending.
82
-
83
- Parameters
84
- ----------
85
- file_path: str
86
- The path to the file
87
- **kwargs: dict, optional
88
- Parameters forwarded to the pandas reading method.
89
-
90
- Returns
91
- -------
92
- pandas.DataFrame :
93
- The data
94
-
95
- """
96
- fname = str(file_path)
97
- L = len(fname)
98
- f = None
99
- for fmt in cls.DATA_FILE_FORMATS:
100
- l = len(fmt)
101
- if fname[L - l :] == fmt:
102
- if fmt[:3] == "csv":
103
- f = pd.read_csv
104
-
105
- elif fmt == "h5":
106
- f = pd.read_hdf
107
-
108
- elif fmt == "nc":
109
- f = lambda fname, **pars: xarray.open_dataset(
110
- fname, **pars
111
- ).to_dataframe()
112
-
113
- if f is not None:
114
- pars = deepcopy(cls.DEFAULT_READING_PARAMETERS[fmt])
115
- pars.update(kwargs)
116
- return f(file_path, **pars)
117
-
118
- raise KeyError(
119
- f"Unknown file format '{fname}'. Supported formats: {cls.DATA_FILE_FORMATS}"
120
- )
121
-
122
- @classmethod
123
- def write_file(cls, data, file_path, format_dict={}, **kwargs):
124
- """
125
- Helper for writing data according to file ending.
126
-
127
- Parameters
128
- ----------
129
- data: pandas.DataFrame
130
- The data
131
- file_path: str
132
- The path to the file
133
- format_dict: dict
134
- Dictionary with format entries for
135
- columns, e.g. '{:.4f}'
136
- **kwargs: dict, optional
137
- Parameters forwarded to the pandas writing method.
138
-
139
- """
140
-
141
- digits = {c: FV.get_default_digits(c) for c in data.columns}
142
- fdict = {c: "{:." + str(d) + "f}" for c, d in digits.items() if d is not None}
143
- fdict.update(format_dict)
144
-
145
- out = pd.DataFrame(index=data.index)
146
- for c in data.columns:
147
- if c in fdict.keys():
148
- out[c] = data[c].map(
149
- lambda x: fdict[c].format(x) if not pd.isna(x) else x
150
- )
151
- else:
152
- out[c] = data[c]
153
-
154
- L = len(file_path)
155
- f = None
156
- for fmt in cls.DATA_FILE_FORMATS:
157
- l = len(fmt)
158
- if file_path[L - l :] == fmt:
159
- if fmt[:3] == "csv":
160
- f = out.to_csv
161
-
162
- elif fmt == "h5":
163
- f = out.to_hdf
164
-
165
- elif fmt == "nc":
166
- f = out.to_netcdf
167
-
168
- if f is not None:
169
- pars = cls.DEFAULT_WRITING_PARAMETERS[fmt]
170
- pars.update(kwargs)
171
-
172
- f(file_path, **pars)
173
-
174
- return
175
-
176
- raise KeyError(
177
- f"Unknown file format '{file_path}'. Supported formats: {cls.DATA_FILE_FORMATS}"
178
- )