Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coyote
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nils
coyote
Commits
cec42cf2
Commit
cec42cf2
authored
2 months ago
by
Nils-Arne Dreier
Browse files
Options
Downloads
Patches
Plain Diff
switch to json metadata format and add a test
parent
3072f8c5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!42
feat: copy metadata from yac source
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/hiopy/worker.py
+20
-12
20 additions, 12 deletions
apps/hiopy/worker.py
tests/simple_source.c
+48
-2
48 additions, 2 deletions
tests/simple_source.c
with
68 additions
and
14 deletions
apps/hiopy/worker.py
+
20
−
12
View file @
cec42cf2
#!/usr/bin/env python3
import
json
import
logging
from
argparse
import
ArgumentParser
from
itertools
import
chain
,
groupby
import
numpy
as
np
import
yaml
import
zarr
from
coyote
import
(
Coyote
,
...
...
@@ -149,7 +149,7 @@ def main():
time_methods2yac
=
{
"
point
"
:
0
,
"
sum
"
:
1
,
"
mean
"
:
2
,
"
min
"
:
3
,
"
max
"
:
4
}
collection_size
=
v
.
shape
[
1
]
if
len
(
v
.
shape
)
==
3
else
1
src_name
=
v
.
attrs
.
get
(
"
hiopy::src_name
"
,
default
=
v
.
name
.
split
(
"
/
"
)[
-
1
]
)
src_name
=
v
.
attrs
.
get
(
"
hiopy::src_name
"
,
default
=
v
.
base
name
)
if
"
hiopy::yac_source
"
in
v
.
attrs
:
src_comp
,
src_grid
=
v
.
attrs
[
"
hiopy::yac_source
"
]
else
:
...
...
@@ -159,7 +159,7 @@ def main():
for
gid
,
vg
,
_
,
gvars
in
chain
(
*
distributed_data_vars
)
for
groupvar
in
gvars
if
groupvar
.
name
.
split
(
"
/
"
)[
-
2
]
==
v
.
group
.
attrs
[
"
hiopy::parent
"
]
and
groupvar
.
name
.
split
(
"
/
"
)[
-
1
]
==
src_
name
and
groupvar
.
name
.
split
(
"
/
"
)[
-
1
]
==
v
.
base
name
][
0
]
src_comp
=
src_grid
=
f
"
{
args
.
process_group
}
_
{
gid
}
_
{
src_vgroup
}
"
time_method
=
v
.
attrs
.
get
(
"
hiopy::time_method
"
,
"
point
"
)
...
...
@@ -196,23 +196,31 @@ def main():
frac_mask
=
frac_mask
,
)
def
get_source_triple
(
v
):
if
"
hiopy::parent
"
in
v
.
attrs
:
return
get_source_triple
(
v
.
group
.
parent
[
v
.
attrs
[
"
hiopy::parent
"
]][
v
.
basename
])
else
:
def
get_source_triple
(
v
,
group
):
if
"
hiopy::parent
"
in
group
.
attrs
:
parent_field
=
group
.
parent
[
group
.
attrs
[
"
hiopy::parent
"
]][
v
.
basename
]
pgroup
=
group
.
parent
[
group
.
attrs
[
"
hiopy::parent
"
]]
pgroup
.
parent
=
group
.
parent
return
get_source_triple
(
parent_field
,
pgroup
)
elif
"
hiopy::yac_source
"
in
v
.
attrs
:
src_comp
,
src_grid
=
v
.
attrs
[
"
hiopy::yac_source
"
]
src_field
=
v
.
attrs
[
"
hiopy::src_name
"
]
if
"
src_name
"
else
v
.
basename
src_field
=
v
.
attrs
.
get
(
"
hiopy::src_name
"
,
v
.
basename
)
return
src_comp
,
src_grid
,
src_field
else
:
raise
RuntimeError
(
"
Invalid attributes:
"
+
str
(
dict
(
v
.
attrs
)))
ensure_enddef
()
if
group_comm_rank
()
==
0
:
for
v
in
all_data_vars
:
if
"
hiopy::copy_metadata
"
in
v
.
attrs
:
comp
,
grid
,
field
=
get_source_triple
(
v
)
metadata
=
yaml
.
safe_load
(
get_field_metadata
(
comp
,
grid
,
field
))
for
key
,
value
in
metadata
[
"
cf
"
]:
comp
,
grid
,
field
=
get_source_triple
(
v
,
v
.
group
)
md_str
=
get_field_metadata
(
comp
,
grid
,
field
)
print
(
md_str
)
metadata
=
json
.
loads
(
md_str
)
print
(
metadata
)
for
key
,
value
in
metadata
[
"
cf
"
].
items
():
v
.
attrs
[
key
]
=
value
del
v
.
attrs
[
"
hiopy::copy_metadata
"
]
# copy only once
del
v
.
attrs
[
"
hiopy::copy_metadata
"
]
# copy only once
run
()
...
...
This diff is collapsed.
Click to expand it.
tests/simple_source.c
+
48
−
2
View file @
cec42cf2
...
...
@@ -45,7 +45,8 @@ int main(int argc, char** argv) {
yac_cdef_datetime
(
"2000-01-01T00:00:00.00Z"
,
enddate
);
printf
(
"enddate: %s
\n
"
,
enddate
);
int
comp_id
,
grid_id
,
point_id
;
yac_cdef_comp
(
"simple_source"
,
&
comp_id
);
const
char
*
comp_name
=
"simple_source"
;
yac_cdef_comp
(
comp_name
,
&
comp_id
);
int
nbr_points
[]
=
{
2
*
resolution
,
resolution
};
int
cyclic
[]
=
{
1
,
0
};
double
lon
[
nbr_points
[
0
]];
...
...
@@ -56,7 +57,8 @@ int main(int argc, char** argv) {
for
(
size_t
i
=
0
;
i
<
nbr_points
[
1
];
++
i
)
{
lat
[
i
]
=
-
M_PI_2
+
(
i
+
0
.
5
)
*
M_PI
/
nbr_points
[
1
];
}
yac_cdef_grid_reg2d
(
"simple_grid"
,
nbr_points
,
cyclic
,
lon
,
lat
,
&
grid_id
);
const
char
*
grid_name
=
"simple_grid"
;
yac_cdef_grid_reg2d
(
grid_name
,
nbr_points
,
cyclic
,
lon
,
lat
,
&
grid_id
);
int
glb_idx
[
nbr_points
[
0
]
*
nbr_points
[
1
]];
for
(
int
i
=
0
;
i
<
nbr_points
[
0
]
*
nbr_points
[
1
];
++
i
)
glb_idx
[
i
]
=
i
;
...
...
@@ -65,13 +67,57 @@ int main(int argc, char** argv) {
int
x_field_id
=
-
1
;
yac_cdef_field
(
"x"
,
comp_id
,
&
point_id
,
1
,
1
,
"PT1S"
,
YAC_TIME_UNIT_ISO_FORMAT
,
&
x_field_id
);
yac_cdef_field_metadata
(
comp_name
,
grid_name
,
"x"
,
"{
\n
"
"
\"
cf
\"
: {
\n
"
"
\"
standard_name
\"
:
\"
x
\"
,
\n
"
"
\"
long_name
\"
:
\"
this is a very long x
\"
,
\n
"
"
\"
units
\"
:
\"
1
\"\n
"
" }
\n
"
"}"
);
int
y_field_id
=
-
1
;
yac_cdef_field
(
"y"
,
comp_id
,
&
point_id
,
1
,
1
,
"PT1S"
,
YAC_TIME_UNIT_ISO_FORMAT
,
&
y_field_id
);
yac_cdef_field_metadata
(
comp_name
,
grid_name
,
"y"
,
"{
\n
"
"
\"
cf
\"
: {
\n
"
"
\"
standard_name
\"
:
\"
y
\"
,
\n
"
"
\"
long_name
\"
:
\"
this is a very long y
\"
,
\n
"
"
\"
units
\"
:
\"
1
\"\n
"
" }
\n
"
"}"
);
int
z_field_id
=
-
1
;
yac_cdef_field
(
"z"
,
comp_id
,
&
point_id
,
1
,
1
,
"PT1S"
,
YAC_TIME_UNIT_ISO_FORMAT
,
&
z_field_id
);
yac_cdef_field_metadata
(
comp_name
,
grid_name
,
"z"
,
"{
\n
"
"
\"
cf
\"
: {
\n
"
"
\"
standard_name
\"
:
\"
z
\"
,
\n
"
"
\"
long_name
\"
:
\"
this is a very long z
\"
,
\n
"
"
\"
units
\"
:
\"
1
\"\n
"
" }
\n
"
"}"
);
int
clock_field_id
=
-
1
;
yac_cdef_field
(
"clock"
,
comp_id
,
&
point_id
,
1
,
1
,
"PT1S"
,
YAC_TIME_UNIT_ISO_FORMAT
,
&
clock_field_id
);
yac_cdef_field_metadata
(
comp_name
,
grid_name
,
"clock"
,
"{
\n
"
"
\"
cf
\"
: {
\n
"
"
\"
standard_name
\"
:
\"
t
\"
,
\n
"
"
\"
long_name
\"
:
\"
time
\"
,
\n
"
"
\"
units
\"
:
\"
s
\"\n
"
" }
\n
"
"}"
);
yac_cenddef
();
...
...
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