Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
9562b752
Commit
9562b752
authored
4 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
corrected helper behaviour if single station is given
parent
e709bc82
No related branches found
No related tags found
5 merge requests
!192
include Develop
,
!191
Resolve "release v1.1.0"
,
!168
Lukas issue193 bug index error
,
!167
Resolve "bug: too many indices in PlotClimatologicalSkillScore"
,
!139
Draft: Resolve "KZ filter"
Pipeline
#48711
passed
4 years ago
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mlair/helpers/helpers.py
+15
-10
15 additions, 10 deletions
mlair/helpers/helpers.py
test/test_helpers/test_helpers.py
+11
-3
11 additions, 3 deletions
test/test_helpers/test_helpers.py
with
26 additions
and
13 deletions
mlair/helpers/helpers.py
+
15
−
10
View file @
9562b752
...
...
@@ -32,16 +32,21 @@ def dict_to_xarray(d: Dict, coordinate_name: str) -> xr.DataArray:
:return: combined xarray
"""
xarray
=
None
for
k
,
v
in
d
.
items
():
if
xarray
is
None
:
xarray
=
v
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
if
len
(
d
.
keys
())
==
1
:
k
=
list
(
d
.
keys
())
xarray
:
xr
.
DataArray
=
d
[
k
[
0
]]
return
xarray
.
expand_dims
(
dim
=
{
coordinate_name
:
k
},
axis
=
0
)
else
:
xarray
=
None
for
k
,
v
in
d
.
items
():
if
xarray
is
None
:
xarray
=
v
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
:
...
...
This diff is collapsed.
Click to expand it.
test/test_helpers/test_helpers.py
+
11
−
3
View file @
9562b752
...
...
@@ -124,14 +124,22 @@ class TestPytestRegex:
class
TestDictToXarray
:
def
test_dict_to_xarray
(
self
):
array1
=
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
]})
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
],
'
y
'
:
[
0
,
10
,
20
]})
d
=
{
"
number1
"
:
array1
,
"
number2
"
:
array2
}
res
=
dict_to_xarray
(
d
,
"
merge_dim
"
)
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
)
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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment