Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
toargridding
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
toar-public
toargridding
Commits
5011de8c
Commit
5011de8c
authored
1 year ago
by
Simon Grasse
Browse files
Options
Downloads
Patches
Plain Diff
eliminate string constants from processing
parent
54894844
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!11
Creation of first beta release version
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
toargridding/grids.py
+31
-14
31 additions, 14 deletions
toargridding/grids.py
toargridding/metadata.py
+14
-3
14 additions, 3 deletions
toargridding/metadata.py
with
45 additions
and
17 deletions
toargridding/grids.py
+
31
−
14
View file @
5011de8c
...
@@ -14,7 +14,11 @@ from toargridding.toar_rest_client import (
...
@@ -14,7 +14,11 @@ from toargridding.toar_rest_client import (
STATION_LON
,
STATION_LON
,
COORDS
,
COORDS
,
)
)
from
toargridding.metadata
import
GLOBAL
,
LATITUDE
,
LONGITUDE
,
get_variable_attributes
from
toargridding.metadata
import
(
Variables
,
get_variable_attributes
,
get_global_attributes
,
)
GridType
=
Enum
(
"
GridType
"
,
[
"
regular
"
])
GridType
=
Enum
(
"
GridType
"
,
[
"
regular
"
])
...
@@ -108,13 +112,13 @@ class RegularGrid(GridDefinition):
...
@@ -108,13 +112,13 @@ class RegularGrid(GridDefinition):
def
get_cell_statistics
(
self
,
groups
):
def
get_cell_statistics
(
self
,
groups
):
stats
=
{
stats
=
{
"
mean
"
:
groups
.
mean
(),
Variables
.
mean
.
name
:
groups
.
mean
(),
"
std
"
:
groups
.
std
(),
Variables
.
std
.
name
:
groups
.
std
(),
"
n
"
:
groups
.
count
(),
Variables
.
n
.
name
:
groups
.
count
(),
}
}
idx
=
stats
[
"
n
"
]
==
0
idx
=
stats
[
Variables
.
n
.
name
]
==
0
stats
[
"
mean
"
][
idx
]
=
self
.
fill_value
stats
[
Variables
.
mean
.
name
][
idx
]
=
self
.
fill_value
stats
[
"
std
"
][
idx
]
=
self
.
fill_value
stats
[
Variables
.
std
.
name
][
idx
]
=
self
.
fill_value
return
stats
return
stats
...
@@ -123,9 +127,9 @@ class RegularGrid(GridDefinition):
...
@@ -123,9 +127,9 @@ class RegularGrid(GridDefinition):
time
=
pd
.
DatetimeIndex
(
random_df
.
columns
)
time
=
pd
.
DatetimeIndex
(
random_df
.
columns
)
gridded_ds
=
self
.
get_empty_grid
(
time
,
metadata
)
gridded_ds
=
self
.
get_empty_grid
(
time
,
metadata
)
for
cell_statistic
,
group
ed_timeseries
in
cell_statistics
.
items
():
for
cell_statistic
,
aggregat
ed_timeseries
in
cell_statistics
.
items
():
gridded_ds
=
self
.
assign_statistic_to_grid
(
gridded_ds
=
self
.
assign_statistic_to_grid
(
gridded_ds
,
cell_statistic
,
group
ed_timeseries
,
time
gridded_ds
,
cell_statistic
,
aggregat
ed_timeseries
,
time
)
)
return
gridded_ds
return
gridded_ds
...
@@ -137,7 +141,16 @@ class RegularGrid(GridDefinition):
...
@@ -137,7 +141,16 @@ class RegularGrid(GridDefinition):
metadata
=
get_variable_attributes
(
cell_statistic
)
metadata
=
get_variable_attributes
(
cell_statistic
)
gridded_ds
=
gridded_ds
.
assign
(
# maybe better all in one ? (memory)
gridded_ds
=
gridded_ds
.
assign
(
# maybe better all in one ? (memory)
{
cell_statistic
:
([
"
latitude
"
,
"
longitude
"
,
"
time
"
],
values
)}
{
cell_statistic
:
(
[
Variables
.
latitude
.
name
,
Variables
.
longitude
.
name
,
Variables
.
time
.
name
,
],
values
,
)
}
)
)
return
gridded_ds
return
gridded_ds
...
@@ -172,9 +185,13 @@ class RegularGrid(GridDefinition):
...
@@ -172,9 +185,13 @@ class RegularGrid(GridDefinition):
self
,
time
:
pd
.
DatetimeIndex
,
metadata
:
pd
.
DataFrame
self
,
time
:
pd
.
DatetimeIndex
,
metadata
:
pd
.
DataFrame
)
->
xr
.
Dataset
:
# TODO make CF-compliant => docs
)
->
xr
.
Dataset
:
# TODO make CF-compliant => docs
coords
=
{
coords
=
{
"
longitude
"
:
self
.
lon
,
Variables
.
longitude
.
name
:
self
.
lon
,
"
latitude
"
:
self
.
lat
,
Variables
.
latitude
.
name
:
self
.
lat
,
"
time
"
:
time
,
Variables
.
time
.
name
:
time
,
}
}
return
xr
.
Dataset
(
coords
=
coords
,
attrs
=
GLOBAL
)
ds
=
xr
.
Dataset
(
coords
=
coords
,
attrs
=
get_global_attributes
(
metadata
))
ds
.
longitude
.
attrs
=
get_variable_attributes
(
Variables
.
longitude
)
ds
.
latitude
.
attrs
=
get_variable_attributes
(
Variables
.
latitude
)
return
ds
This diff is collapsed.
Click to expand it.
toargridding/metadata.py
+
14
−
3
View file @
5011de8c
from
datetime
import
datetime
from
datetime
import
datetime
from
enum
import
Enum
import
numpy
as
np
import
numpy
as
np
date_created
=
datetime
.
utcnow
().
strftime
(
"
%Y-%m-dT%H:%M:%SZ
"
)
date_created
=
datetime
.
utcnow
().
strftime
(
"
%Y-%m-dT%H:%M:%SZ
"
)
Variables
=
Enum
(
"
Variables
"
,
[
"
latitude
"
,
"
longitude
"
,
"
time
"
,
"
mean
"
,
"
std
"
,
"
n
"
])
GLOBAL
=
{
GLOBAL
=
{
"
title
"
:
"
foo
"
,
"
title
"
:
"
foo
"
,
"
date_created
"
:
date_created
,
"
date_created
"
:
date_created
,
...
@@ -31,11 +34,11 @@ ENCODING = {
...
@@ -31,11 +34,11 @@ ENCODING = {
"
time
"
:
{
"
dtype
"
:
"
int32
"
,
"
_FillValue
"
:
None
},
"
time
"
:
{
"
dtype
"
:
"
int32
"
,
"
_FillValue
"
:
None
},
"
latitude
"
:
{
"
latitude
"
:
{
"
dtype
"
:
"
int32
"
,
"
dtype
"
:
"
int32
"
,
"
_FillValue
"
:
None
,
"
_FillValue
"
:
-
1000
,
},
},
"
longitude
"
:
{
"
longitude
"
:
{
"
dtype
"
:
"
int32
"
,
"
dtype
"
:
"
int32
"
,
"
_FillValue
"
:
None
,
"
_FillValue
"
:
-
1000
,
},
},
"
mean
"
:
{
"
mean
"
:
{
"
dtype
"
:
"
float32
"
,
"
dtype
"
:
"
float32
"
,
...
@@ -55,5 +58,13 @@ ENCODING = {
...
@@ -55,5 +58,13 @@ ENCODING = {
}
}
def
get_variable_attributes
(
statistic
):
def
get_global_attributes
(
metadata
):
pass
def
get_variable_attributes
(
variable
:
Variables
):
pass
def
get_variable_encoding
(
variable
:
Variables
):
pass
pass
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