Skip to content
Snippets Groups Projects
Commit 9562b752 authored by leufen1's avatar leufen1
Browse files

corrected helper behaviour if single station is given

parent e709bc82
Branches
Tags
5 merge requests!192include Develop,!191Resolve "release v1.1.0",!168Lukas issue193 bug index error,!167Resolve "bug: too many indices in PlotClimatologicalSkillScore",!139Draft: Resolve "KZ filter"
Pipeline #48711 passed
...@@ -32,16 +32,21 @@ def dict_to_xarray(d: Dict, coordinate_name: str) -> xr.DataArray: ...@@ -32,16 +32,21 @@ def dict_to_xarray(d: Dict, coordinate_name: str) -> xr.DataArray:
:return: combined xarray :return: combined xarray
""" """
xarray = None if len(d.keys()) == 1:
for k, v in d.items(): k = list(d.keys())
if xarray is None: xarray: xr.DataArray = d[k[0]]
xarray = v return xarray.expand_dims(dim={coordinate_name: k}, axis=0)
xarray.coords[coordinate_name] = k else:
else: xarray = None
tmp_xarray = v for k, v in d.items():
tmp_xarray.coords[coordinate_name] = k if xarray is None:
xarray = xr.concat([xarray, tmp_xarray], coordinate_name) xarray = v
return xarray xarray.coords[coordinate_name] = k
else:
tmp_xarray = v
tmp_xarray.coords[coordinate_name] = k
xarray = xr.concat([xarray, tmp_xarray], coordinate_name)
return xarray
def float_round(number: float, decimals: int = 0, round_type: Callable = math.ceil) -> float: def float_round(number: float, decimals: int = 0, round_type: Callable = math.ceil) -> float:
......
...@@ -124,14 +124,22 @@ class TestPytestRegex: ...@@ -124,14 +124,22 @@ class TestPytestRegex:
class TestDictToXarray: class TestDictToXarray:
def test_dict_to_xarray(self): def test_dict_to_xarray(self):
array1 = xr.DataArray(np.random.randn(2, 3), dims=('x', 'y'), coords={'x': [10, 20]}) array1 = xr.DataArray(np.random.randn(2, 3), dims=('x', 'y'), coords={'x': [10, 20], 'y': [0, 10, 20]})
array2 = xr.DataArray(np.random.randn(2, 3), dims=('x', 'y'), coords={'x': [10, 20]}) array2 = xr.DataArray(np.random.randn(2, 3), dims=('x', 'y'), coords={'x': [10, 20], 'y': [0, 10, 20]})
d = {"number1": array1, "number2": array2} d = {"number1": array1, "number2": array2}
res = dict_to_xarray(d, "merge_dim") res = dict_to_xarray(d, "merge_dim")
assert type(res) == xr.DataArray assert type(res) == xr.DataArray
assert sorted(list(res.coords)) == ["merge_dim", "x"] assert sorted(list(res.coords)) == ["merge_dim", "x", "y"]
assert res.shape == (2, 2, 3) assert res.shape == (2, 2, 3)
def test_dict_to_xarray_single_entry(self):
array1 = xr.DataArray(np.random.randn(2, 3), dims=('x', 'y'), coords={'x': [10, 20], 'y': [0, 10, 20]})
d = {"number1": array1}
res = dict_to_xarray(d, "merge_dim")
assert type(res) == xr.DataArray
assert sorted(list(res.coords)) == ["merge_dim", "x", "y"]
assert res.shape == (1, 2, 3)
class TestFloatRound: class TestFloatRound:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment