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
ef6c3f36
Commit
ef6c3f36
authored
1 year ago
by
Carsten Hinz
Browse files
Options
Downloads
Patches
Plain Diff
continued work on documentation
parent
5dec86cf
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
+18
-1
18 additions, 1 deletion
toargridding/grids.py
toargridding/variables.py
+40
-2
40 additions, 2 deletions
toargridding/variables.py
with
58 additions
and
3 deletions
toargridding/grids.py
+
18
−
1
View file @
ef6c3f36
...
...
@@ -16,9 +16,13 @@ from toargridding.metadata import (
from
toargridding.variables
import
Variable
,
Coordinate
GridType
=
Enum
(
"
GridType
"
,
[
"
regular
"
])
"""
list of available grids.
"""
class
GridDefinition
(
ABC
):
"""
factory and base class for definition of different grids
"""
cell_index_name
=
"
cell_index
"
def
__init__
(
self
):
...
...
@@ -36,20 +40,33 @@ class GridDefinition(ABC):
@property
@abstractmethod
def
description
(
self
):
"""
description of this grid
"""
pass
@staticmethod
def
from_netcdf
():
"""
loading of an arbitrary grid from a netCDF file
not yet implemented
"""
pass
@abstractmethod
def
as_xarray
(
timeseries
:
dict
[
str
,
pd
.
DataFrame
],
metadata
:
pd
.
DataFrame
)
->
dict
[
str
,
xr
.
Dataset
]:
"""
conversion of panda Dataframes to an xarray dataset
This includes the required setup to store the results as netCDF file according to CF (https://cfconventions.org/cf-conventions/cf-conventions.html)
"""
pass
class
RegularGrid
(
GridDefinition
):
"""
definition of a regular grid with longitude and latitude.
"""
Coord
=
namedtuple
(
"
Coord
"
,
[
"
lat
"
,
"
lon
"
])
def
__init__
(
self
,
lat_resolution
,
lon_resolution
):
...
...
This diff is collapsed.
Click to expand it.
toargridding/variables.py
+
40
−
2
View file @
ef6c3f36
...
...
@@ -5,9 +5,25 @@ import xarray as xr
from
toargridding.metadata
import
Variables
,
get_cf_metadata
,
Metadata
from
typing
import
Dict
@dataclass
class
Variable
:
"""
full variable including data and information according to CF
CF: https://cfconventions.org/cf-conventions/cf-conventions.html
Parameters:
----------
var:
name of the TOAR variable
data:
array with data
attributes:
metadata according to CF
encoding:
encoding of data type
"""
var
:
Variables
data
:
np
.
ndarray
attributes
:
dict
[
str
,
str
]
...
...
@@ -15,11 +31,15 @@ class Variable:
@classmethod
def
from_data
(
cls
,
data
,
variable
:
Variables
,
metadata
:
Metadata
|
None
,
**
kwargs
):
"""
construction from analysis results
"""
cf_metadata
=
get_cf_metadata
(
variable
,
metadata
=
metadata
)
# print(variable.name, cf_metadata)
return
cls
(
variable
,
data
,
**
cf_metadata
,
**
kwargs
)
def
as_data_array
(
self
,
dims
):
def
as_data_array
(
self
,
dims
)
->
xr
.
DataArray
:
"""
conversion to DataArray
"""
da
=
xr
.
DataArray
(
self
.
data
,
name
=
self
.
name
,
...
...
@@ -31,29 +51,43 @@ class Variable:
@property
def
name
(
self
):
"""
shortcut to variable name
"""
return
self
.
var
.
name
@property
def
size
(
self
):
"""
shortcut to length of data array
"""
return
self
.
data
.
size
@property
def
min
(
self
):
"""
shortcut to minimum of data array
"""
return
self
.
data
.
min
()
@property
def
max
(
self
):
"""
shortcut to maximum of data array
"""
return
self
.
data
.
max
()
@dataclass
class
Coordinate
(
Variable
):
"""
coordinate axis
"""
step
:
float
|
str
@classmethod
def
from_resolution
(
cls
,
variable
:
Variables
,
resolution
:
float
,
min
:
float
,
max
:
float
):
"""
construction from a data range and resolution
"""
span
=
max
-
min
n
=
int
(
span
/
resolution
)
# raise error if invalid inputs ?
data
=
np
.
linspace
(
min
,
max
,
n
+
1
)
...
...
@@ -61,8 +95,12 @@ class Coordinate(Variable):
return
cls
.
from_data
(
data
,
variable
,
None
,
step
=
resolution
)
def
as_data_array
(
self
):
"""
conversion to data array
"""
return
super
().
as_data_array
(
dims
=
self
.
name
)
def
get_encoding
(
variables
:
list
[
Variable
]):
def
get_encoding
(
variables
:
list
[
Variable
])
->
Dict
[
str
,
Dict
]:
"""
get dictionary encoding with encoding
"""
return
{
variable
.
name
:
variable
.
encoding
for
variable
in
variables
}
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