Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Klaus Zimmermann
climix
Commits
04577bd8
Commit
04577bd8
authored
Nov 11, 2019
by
Klaus Zimmermann
Browse files
Cleanup dataclasses based metadata handling (closes #126)
parent
469d9824
Changes
1
Hide whitespace changes
Inline
Side-by-side
climix/metadata.py
View file @
04577bd8
...
...
@@ -17,7 +17,6 @@ import xdg.BaseDirectory
import
yaml
from
.index
import
Index
from
.index_functions
import
SUPPORTED_OPERATORS
,
SUPPORTED_REDUCERS
from
.period
import
PeriodSpecification
...
...
@@ -86,6 +85,9 @@ class Parameter:
kind
:
ParameterKind
PARAMETER_KINDS
=
{}
@
dataclass
class
ParameterQuantity
(
Parameter
):
long_name
:
str
...
...
@@ -113,6 +115,9 @@ class ParameterQuantity(Parameter):
self
.
units
)
PARAMETER_KINDS
[
'quantity'
]
=
ParameterQuantity
@
dataclass
class
ParameterOperator
(
Parameter
):
operator
:
str
...
...
@@ -127,6 +132,9 @@ class ParameterOperator(Parameter):
self
.
operator
)
PARAMETER_KINDS
[
'operator'
]
=
ParameterOperator
@
dataclass
class
ParameterReducer
(
Parameter
):
reducer
:
str
...
...
@@ -141,6 +149,9 @@ class ParameterReducer(Parameter):
self
.
reducer
)
PARAMETER_KINDS
[
'reducer'
]
=
ParameterReducer
@
dataclass
class
IndexFunction
:
name
:
str
...
...
@@ -172,21 +183,7 @@ class IndexDefinition:
def
build_parameter
(
metadata
):
if
metadata
[
'kind'
]
==
'quantity'
:
param
=
ParameterQuantity
(
ParameterKind
.
QUANTITY
,
metadata
[
'long_name'
],
metadata
[
'standard_name'
],
metadata
[
'data'
],
metadata
[
'units'
])
elif
metadata
[
'kind'
]
==
'operator'
:
param
=
ParameterOperator
(
ParameterKind
.
OPERATOR
,
metadata
[
'operator'
])
elif
metadata
[
'kind'
]
==
'reducer'
:
param
=
ParameterReducer
(
ParameterKind
.
REDUCER
,
metadata
[
'reducer'
])
else
:
raise
RuntimeError
(
f
'Unknown parameter kind
{
metadata
}
'
)
return
param
return
PARAMETER_KINDS
[
metadata
[
'kind'
]](
**
metadata
)
def
build_index
(
metadata
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment