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.
- docs/source/conf.py +3 -3
- examples/abl_states/run.py +2 -2
- examples/compare_rotors_pwakes/run.py +1 -1
- examples/compare_wakes/run.py +1 -2
- examples/dyn_wakes/run.py +29 -6
- examples/induction/run.py +3 -3
- examples/multi_height/run.py +1 -1
- examples/power_mask/run.py +2 -2
- examples/quickstart/run.py +16 -0
- examples/random_timeseries/run.py +3 -4
- examples/scan_row/run.py +3 -3
- examples/sequential/run.py +33 -10
- examples/single_state/run.py +3 -4
- examples/states_lookup_table/run.py +3 -3
- examples/streamline_wakes/run.py +27 -4
- examples/tab_file/run.py +3 -3
- examples/timelines/run.py +29 -5
- examples/timeseries/run.py +3 -3
- examples/timeseries_slurm/run.py +3 -3
- examples/wind_rose/run.py +3 -3
- examples/yawed_wake/run.py +16 -8
- foxes/__init__.py +22 -18
- foxes/algorithms/__init__.py +6 -6
- foxes/algorithms/downwind/__init__.py +2 -2
- foxes/algorithms/downwind/downwind.py +53 -27
- foxes/algorithms/downwind/models/__init__.py +6 -6
- foxes/algorithms/downwind/models/farm_wakes_calc.py +22 -14
- foxes/algorithms/downwind/models/init_farm_data.py +4 -5
- foxes/algorithms/downwind/models/point_wakes_calc.py +7 -13
- foxes/algorithms/downwind/models/reorder_farm_output.py +5 -1
- foxes/algorithms/downwind/models/set_amb_point_results.py +7 -7
- foxes/algorithms/iterative/__init__.py +7 -3
- foxes/algorithms/iterative/iterative.py +1 -2
- foxes/algorithms/iterative/models/__init__.py +7 -3
- foxes/algorithms/iterative/models/farm_wakes_calc.py +15 -8
- foxes/algorithms/sequential/__init__.py +3 -3
- foxes/algorithms/sequential/models/__init__.py +2 -2
- foxes/algorithms/sequential/models/seq_state.py +0 -18
- foxes/algorithms/sequential/sequential.py +8 -22
- foxes/config/__init__.py +5 -1
- foxes/constants.py +22 -0
- foxes/core/__init__.py +45 -22
- foxes/core/algorithm.py +0 -1
- foxes/core/data.py +56 -29
- foxes/core/engine.py +28 -14
- foxes/core/farm_controller.py +2 -2
- foxes/core/farm_data_model.py +1 -0
- foxes/core/ground_model.py +4 -13
- foxes/core/model.py +5 -5
- foxes/core/partial_wakes_model.py +147 -10
- foxes/core/point_data_model.py +2 -3
- foxes/core/rotor_model.py +42 -38
- foxes/core/states.py +4 -50
- foxes/core/turbine.py +2 -1
- foxes/core/wake_deflection.py +130 -0
- foxes/core/wake_model.py +222 -9
- foxes/core/wake_superposition.py +122 -4
- foxes/core/wind_farm.py +6 -6
- foxes/data/__init__.py +7 -2
- foxes/data/states/weibull_sectors_12.csv +13 -0
- foxes/data/states/weibull_sectors_12.nc +0 -0
- foxes/engines/__init__.py +14 -15
- foxes/engines/dask.py +39 -14
- foxes/engines/numpy.py +0 -3
- foxes/input/__init__.py +3 -3
- foxes/input/farm_layout/__init__.py +8 -8
- foxes/input/farm_layout/from_csv.py +1 -1
- foxes/input/farm_layout/ring.py +0 -1
- foxes/input/states/__init__.py +22 -11
- foxes/input/states/create/__init__.py +3 -2
- foxes/input/states/field_data_nc.py +48 -84
- foxes/input/states/multi_height.py +40 -60
- foxes/input/states/one_point_flow.py +22 -25
- foxes/input/states/scan.py +6 -19
- foxes/input/states/single.py +6 -18
- foxes/input/states/states_table.py +25 -44
- foxes/input/states/weibull_sectors.py +225 -0
- foxes/input/states/wrg_states.py +151 -37
- foxes/input/yaml/__init__.py +9 -3
- foxes/input/yaml/dict.py +19 -19
- foxes/input/yaml/windio/__init__.py +10 -5
- foxes/input/yaml/windio/read_attributes.py +2 -2
- foxes/input/yaml/windio/read_farm.py +5 -5
- foxes/input/yaml/windio/read_fields.py +4 -2
- foxes/input/yaml/windio/read_site.py +52 -0
- foxes/input/yaml/windio/windio.py +1 -1
- foxes/models/__init__.py +15 -14
- foxes/models/axial_induction/__init__.py +2 -2
- foxes/models/farm_controllers/__init__.py +1 -1
- foxes/models/farm_models/__init__.py +1 -1
- foxes/models/ground_models/__init__.py +3 -2
- foxes/models/ground_models/wake_mirror.py +3 -3
- foxes/models/model_book.py +175 -49
- foxes/models/partial_wakes/__init__.py +6 -6
- foxes/models/partial_wakes/axiwake.py +30 -5
- foxes/models/partial_wakes/centre.py +47 -0
- foxes/models/partial_wakes/rotor_points.py +45 -9
- foxes/models/partial_wakes/segregated.py +2 -20
- foxes/models/partial_wakes/top_hat.py +27 -2
- foxes/models/point_models/__init__.py +4 -4
- foxes/models/rotor_models/__init__.py +3 -3
- foxes/models/rotor_models/centre.py +6 -4
- foxes/models/turbine_models/__init__.py +11 -11
- foxes/models/turbine_models/set_farm_vars.py +0 -1
- foxes/models/turbine_types/PCt_file.py +0 -2
- foxes/models/turbine_types/PCt_from_two.py +0 -2
- foxes/models/turbine_types/__init__.py +9 -9
- foxes/models/vertical_profiles/__init__.py +7 -7
- foxes/models/wake_deflections/__init__.py +3 -0
- foxes/models/{wake_frames/yawed_wakes.py → wake_deflections/bastankhah2016.py} +32 -111
- foxes/models/wake_deflections/jimenez.py +277 -0
- foxes/models/wake_deflections/no_deflection.py +94 -0
- foxes/models/wake_frames/__init__.py +6 -7
- foxes/models/wake_frames/dynamic_wakes.py +12 -3
- foxes/models/wake_frames/rotor_wd.py +3 -1
- foxes/models/wake_frames/seq_dynamic_wakes.py +45 -8
- foxes/models/wake_frames/streamlines.py +8 -6
- foxes/models/wake_frames/timelines.py +19 -3
- foxes/models/wake_models/__init__.py +7 -7
- foxes/models/wake_models/dist_sliced.py +50 -84
- foxes/models/wake_models/gaussian.py +20 -0
- foxes/models/wake_models/induction/__init__.py +5 -5
- foxes/models/wake_models/induction/rankine_half_body.py +30 -71
- foxes/models/wake_models/induction/rathmann.py +65 -64
- foxes/models/wake_models/induction/self_similar.py +65 -68
- foxes/models/wake_models/induction/self_similar2020.py +0 -3
- foxes/models/wake_models/induction/vortex_sheet.py +71 -75
- foxes/models/wake_models/ti/__init__.py +2 -2
- foxes/models/wake_models/ti/crespo_hernandez.py +5 -3
- foxes/models/wake_models/ti/iec_ti.py +6 -4
- foxes/models/wake_models/top_hat.py +58 -7
- foxes/models/wake_models/wind/__init__.py +6 -4
- foxes/models/wake_models/wind/bastankhah14.py +25 -7
- foxes/models/wake_models/wind/bastankhah16.py +35 -3
- foxes/models/wake_models/wind/jensen.py +15 -2
- foxes/models/wake_models/wind/turbopark.py +28 -2
- foxes/models/wake_superpositions/__init__.py +18 -9
- foxes/models/wake_superpositions/ti_linear.py +4 -4
- foxes/models/wake_superpositions/ti_max.py +4 -4
- foxes/models/wake_superpositions/ti_pow.py +4 -4
- foxes/models/wake_superpositions/ti_quadratic.py +4 -4
- foxes/models/wake_superpositions/wind_vector.py +257 -0
- foxes/models/wake_superpositions/ws_linear.py +9 -10
- foxes/models/wake_superpositions/ws_max.py +8 -8
- foxes/models/wake_superpositions/ws_pow.py +8 -8
- foxes/models/wake_superpositions/ws_product.py +4 -4
- foxes/models/wake_superpositions/ws_quadratic.py +8 -8
- foxes/output/__init__.py +21 -19
- foxes/output/farm_layout.py +14 -6
- foxes/output/farm_results_eval.py +51 -27
- foxes/output/flow_plots_2d/__init__.py +2 -2
- foxes/output/flow_plots_2d/get_fig.py +4 -2
- foxes/output/rose_plot.py +23 -5
- foxes/output/seq_plugins/__init__.py +2 -2
- foxes/output/seq_plugins/seq_flow_ani_plugin.py +0 -3
- foxes/output/seq_plugins/seq_wake_debug_plugin.py +0 -1
- foxes/output/slice_data.py +16 -19
- foxes/output/turbine_type_curves.py +7 -8
- foxes/utils/__init__.py +37 -19
- foxes/utils/abl/__init__.py +4 -4
- foxes/utils/cubic_roots.py +1 -1
- foxes/utils/data_book.py +4 -3
- foxes/utils/dict.py +3 -3
- foxes/utils/exec_python.py +5 -5
- foxes/utils/factory.py +1 -3
- foxes/utils/geom2d/__init__.py +7 -5
- foxes/utils/geopandas_utils.py +2 -2
- foxes/utils/pandas_utils.py +4 -3
- foxes/utils/tab_files.py +0 -1
- foxes/utils/weibull.py +28 -0
- foxes/utils/wrg_utils.py +3 -1
- foxes/utils/xarray_utils.py +9 -2
- foxes/variables.py +67 -9
- {foxes-1.2.5.dist-info → foxes-1.4.dist-info}/METADATA +14 -21
- foxes-1.4.dist-info/RECORD +320 -0
- {foxes-1.2.5.dist-info → foxes-1.4.dist-info}/WHEEL +1 -1
- tests/0_consistency/iterative/test_iterative.py +2 -3
- tests/0_consistency/partial_wakes/test_partial_wakes.py +2 -2
- tests/1_verification/flappy_0_6/PCt_files/flappy/run.py +2 -3
- tests/1_verification/flappy_0_6/PCt_files/test_PCt_files.py +48 -56
- tests/1_verification/flappy_0_6/abl_states/flappy/run.py +0 -1
- tests/1_verification/flappy_0_6/abl_states/test_abl_states.py +33 -36
- tests/1_verification/flappy_0_6/partial_top_hat/flappy/run.py +0 -1
- tests/1_verification/flappy_0_6/partial_top_hat/test_partial_top_hat.py +0 -2
- tests/1_verification/flappy_0_6/row_Jensen_linear_centre/test_row_Jensen_linear_centre.py +3 -3
- tests/1_verification/flappy_0_6/row_Jensen_linear_tophat/test_row_Jensen_linear_tophat.py +3 -4
- tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2005/test_row_Jensen_linear_tophat_IECTI_2005.py +3 -4
- tests/1_verification/flappy_0_6/row_Jensen_linear_tophat_IECTI2019/test_row_Jensen_linear_tophat_IECTI_2019.py +3 -4
- tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/test_row_Jensen_quadratic_centre.py +3 -4
- tests/1_verification/flappy_0_6_2/grid_rotors/flappy/run.py +0 -2
- tests/1_verification/flappy_0_6_2/grid_rotors/test_grid_rotors.py +3 -3
- tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/test_row_Bastankhah_Crespo.py +3 -3
- tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/flappy/run.py +0 -1
- tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/test_row_Bastankhah_linear_centre.py +3 -4
- tests/3_examples/test_examples.py +3 -2
- foxes/output/round.py +0 -10
- foxes/utils/pandas_helpers.py +0 -178
- foxes-1.2.5.dist-info/RECORD +0 -312
- {foxes-1.2.5.dist-info → foxes-1.4.dist-info}/entry_points.txt +0 -0
- {foxes-1.2.5.dist-info → foxes-1.4.dist-info/licenses}/LICENSE +0 -0
- {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,
|
tests/1_verification/flappy_0_6/row_Jensen_quadratic_centre/test_row_Jensen_quadratic_centre.py
CHANGED
|
@@ -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,
|
|
@@ -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,
|
tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/test_row_Bastankhah_linear_centre.py
CHANGED
|
@@ -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()})
|
foxes/utils/pandas_helpers.py
DELETED
|
@@ -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
|
-
)
|