Commit 04577bd8 authored by Klaus Zimmermann's avatar Klaus Zimmermann
Browse files

Cleanup dataclasses based metadata handling (closes #126)

parent 469d9824
...@@ -17,7 +17,6 @@ import xdg.BaseDirectory ...@@ -17,7 +17,6 @@ import xdg.BaseDirectory
import yaml import yaml
from .index import Index from .index import Index
from .index_functions import SUPPORTED_OPERATORS, SUPPORTED_REDUCERS
from .period import PeriodSpecification from .period import PeriodSpecification
...@@ -86,6 +85,9 @@ class Parameter: ...@@ -86,6 +85,9 @@ class Parameter:
kind: ParameterKind kind: ParameterKind
PARAMETER_KINDS = {}
@dataclass @dataclass
class ParameterQuantity(Parameter): class ParameterQuantity(Parameter):
long_name: str long_name: str
...@@ -113,6 +115,9 @@ class ParameterQuantity(Parameter): ...@@ -113,6 +115,9 @@ class ParameterQuantity(Parameter):
self.units) self.units)
PARAMETER_KINDS['quantity'] = ParameterQuantity
@dataclass @dataclass
class ParameterOperator(Parameter): class ParameterOperator(Parameter):
operator: str operator: str
...@@ -127,6 +132,9 @@ class ParameterOperator(Parameter): ...@@ -127,6 +132,9 @@ class ParameterOperator(Parameter):
self.operator) self.operator)
PARAMETER_KINDS['operator'] = ParameterOperator
@dataclass @dataclass
class ParameterReducer(Parameter): class ParameterReducer(Parameter):
reducer: str reducer: str
...@@ -141,6 +149,9 @@ class ParameterReducer(Parameter): ...@@ -141,6 +149,9 @@ class ParameterReducer(Parameter):
self.reducer) self.reducer)
PARAMETER_KINDS['reducer'] = ParameterReducer
@dataclass @dataclass
class IndexFunction: class IndexFunction:
name: str name: str
...@@ -172,21 +183,7 @@ class IndexDefinition: ...@@ -172,21 +183,7 @@ class IndexDefinition:
def build_parameter(metadata): def build_parameter(metadata):
if metadata['kind'] == 'quantity': return PARAMETER_KINDS[metadata['kind']](**metadata)
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
def build_index(metadata): def build_index(metadata):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment