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
20f9c61d
Commit
20f9c61d
authored
1 year ago
by
Simon Grasse
Browse files
Options
Downloads
Patches
Plain Diff
improve creation of gridded data
parent
1a25b13d
No related branches found
No related tags found
1 merge request
!11
Creation of first beta release version
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
toargridding/metadata.py
+16
-11
16 additions, 11 deletions
toargridding/metadata.py
with
16 additions
and
11 deletions
toargridding/metadata.py
+
16
−
11
View file @
20f9c61d
...
@@ -7,16 +7,17 @@ import xarray as xr
...
@@ -7,16 +7,17 @@ import xarray as xr
date_created
=
datetime
.
utcnow
().
strftime
(
"
%Y-%m-dT%H:%M:%SZ
"
)
date_created
=
datetime
.
utcnow
().
strftime
(
"
%Y-%m-dT%H:%M:%SZ
"
)
D
AT
A
_VARIABLES
=
[
"
latitude
"
,
"
longitude
"
,
"
time
"
]
COORDIN
AT
E
_VARIABLES
=
[
"
latitude
"
,
"
longitude
"
,
"
time
"
]
COORDIN
AT
E
_VARIABLES
=
[
"
mean
"
,
"
std
"
,
"
n
"
]
D
AT
A
_VARIABLES
=
[
"
mean
"
,
"
std
"
,
"
n
"
]
DataVariables
=
Enum
(
"
DataVariables
"
,
DATA_VARIABLES
)
DataVariables
=
Enum
(
"
DataVariables
"
,
DATA_VARIABLES
)
Coordinates
=
Enum
(
"
Coordinates
"
,
COORDINATE_VARIABLES
)
Variables
=
Enum
(
"
Variables
"
,
[
*
DATA_VARIABLES
,
*
COORDINATE_VARIABLES
])
Variables
=
Enum
(
"
Variables
"
,
[
*
DATA_VARIABLES
,
*
COORDINATE_VARIABLES
])
@dataclass
@dataclass
class
Variable
:
class
Variable
:
name
:
str
var
:
Variables
data
:
np
.
ndarray
data
:
np
.
ndarray
attributes
:
dict
[
str
,
str
]
attributes
:
dict
[
str
,
str
]
encoding
:
dict
[
str
,
str
]
encoding
:
dict
[
str
,
str
]
...
@@ -24,15 +25,19 @@ class Variable:
...
@@ -24,15 +25,19 @@ class Variable:
@classmethod
@classmethod
def
from_data
(
cls
,
data
,
variable
:
Variables
,
**
kwargs
):
def
from_data
(
cls
,
data
,
variable
:
Variables
,
**
kwargs
):
metadata
=
Variable
.
get_metadata
(
variable
)
metadata
=
Variable
.
get_metadata
(
variable
)
return
cls
(
variable
.
name
,
data
,
**
metadata
,
**
kwargs
)
return
cls
(
variable
,
data
,
**
metadata
,
**
kwargs
)
@staticmethod
@staticmethod
def
get_metadata
(
variable
:
Variables
):
def
get_metadata
(
variable
:
Variables
):
return
VARIABLE_METADATA
[
variable
]
return
VARIABLE_METADATA
[
variable
.
name
]
def
as_data_array
(
self
,
dims
):
def
as_data_array
(
self
,
dims
):
return
xr
.
DataArray
(
self
.
data
,
name
=
self
.
name
,
dims
=
dims
,
attrs
=
self
.
attributes
)
return
xr
.
DataArray
(
self
.
data
,
name
=
self
.
name
,
dims
=
dims
,
attrs
=
self
.
attributes
)
@property
def
name
(
self
):
return
self
.
var
.
name
@property
@property
def
size
(
self
):
def
size
(
self
):
return
self
.
data
.
size
return
self
.
data
.
size
...
@@ -74,7 +79,7 @@ def get_variable_attributes(variable: Variables):
...
@@ -74,7 +79,7 @@ def get_variable_attributes(variable: Variables):
VARIABLE_METADATA
=
{
VARIABLE_METADATA
=
{
Variables
.
latitude
:
{
Variables
.
latitude
.
name
:
{
"
attributes
"
:
{
"
attributes
"
:
{
"
standard_name
"
:
"
latitude
"
,
"
standard_name
"
:
"
latitude
"
,
"
long_name
"
:
"
latitude in degrees north
"
,
"
long_name
"
:
"
latitude in degrees north
"
,
...
@@ -86,7 +91,7 @@ VARIABLE_METADATA = {
...
@@ -86,7 +91,7 @@ VARIABLE_METADATA = {
"
_FillValue
"
:
-
1000
,
"
_FillValue
"
:
-
1000
,
},
},
},
},
Variables
.
longitude
:
{
Variables
.
longitude
.
name
:
{
"
attributes
"
:
{
"
attributes
"
:
{
"
standard_name
"
:
"
longitude
"
,
"
standard_name
"
:
"
longitude
"
,
"
long_name
"
:
"
longitude in degrees east
"
,
"
long_name
"
:
"
longitude in degrees east
"
,
...
@@ -98,7 +103,7 @@ VARIABLE_METADATA = {
...
@@ -98,7 +103,7 @@ VARIABLE_METADATA = {
"
_FillValue
"
:
-
1000
,
"
_FillValue
"
:
-
1000
,
},
},
},
},
Variables
.
time
:
{
Variables
.
time
.
name
:
{
"
attributes
"
:
{
"
attributes
"
:
{
"
units
"
:
"
time since ...
"
,
"
units
"
:
"
time since ...
"
,
"
long_name
"
:
"
time
"
,
"
long_name
"
:
"
time
"
,
...
@@ -107,11 +112,11 @@ VARIABLE_METADATA = {
...
@@ -107,11 +112,11 @@ VARIABLE_METADATA = {
},
},
"
encoding
"
:
{
"
dtype
"
:
"
int32
"
,
"
_FillValue
"
:
None
},
"
encoding
"
:
{
"
dtype
"
:
"
int32
"
,
"
_FillValue
"
:
None
},
},
},
Variables
.
mean
:
{
Variables
.
mean
.
name
:
{
"
attributes
"
:
{},
"
attributes
"
:
{},
"
encoding
"
:
{
"
dtype
"
:
"
float32
"
,
"
_FillValue
"
:
np
.
nan
,
"
zlib
"
:
False
},
"
encoding
"
:
{
"
dtype
"
:
"
float32
"
,
"
_FillValue
"
:
np
.
nan
,
"
zlib
"
:
False
},
},
},
Variables
.
std
:
{
Variables
.
std
.
name
:
{
"
attributes
"
:
{},
"
attributes
"
:
{},
"
encoding
"
:
{
"
encoding
"
:
{
"
dtype
"
:
"
float32
"
,
"
dtype
"
:
"
float32
"
,
...
@@ -119,7 +124,7 @@ VARIABLE_METADATA = {
...
@@ -119,7 +124,7 @@ VARIABLE_METADATA = {
"
zlib
"
:
False
,
"
zlib
"
:
False
,
},
},
},
},
Variables
.
n
:
{
Variables
.
n
.
name
:
{
"
attributes
"
:
{},
"
attributes
"
:
{},
"
encoding
"
:
{
"
encoding
"
:
{
"
dtype
"
:
"
int32
"
,
"
dtype
"
:
"
int32
"
,
...
...
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