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
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):
......
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