Commit 268faa52 authored by Klaus Zimmermann's avatar Klaus Zimmermann
Browse files

Improve reporting of index problems (closes #128)

parent 2bce8047
......@@ -175,6 +175,7 @@ class IndexDefinition:
output: OutputVariable
input: InputVariable
index_function: IndexFunction
source: str
def instantiate(self, parameters):
idx = IndexDefinition(
......@@ -182,7 +183,8 @@ class IndexDefinition:
self.period,
self.output.instantiate(parameters),
self.input.instantiate(parameters),
self.index_function.instantiate(parameters))
self.index_function.instantiate(parameters),
self.source)
return idx
......@@ -190,28 +192,30 @@ def build_parameter(metadata):
return PARAMETER_KINDS[metadata['kind']](**metadata)
def build_index(metadata):
idx = IndexDefinition(
metadata['reference'],
metadata['period'],
OutputVariable(
def build_index(metadata, source=None):
output = OutputVariable(
metadata['output']['var_name'],
metadata['output']['standard_name'],
metadata['output'].get('proposed_standard_name', None),
metadata['output']['long_name'],
metadata['output']['units'],
[CellMethod(*cm.popitem())
for cm in metadata['output']['cell_methods']]),
InputVariable(
for cm in metadata['output']['cell_methods']])
input = InputVariable(
metadata['input']['var_name'],
metadata['input']['standard_name'],
[CellMethod(*cm.popitem())
for cm in metadata['input']['cell_methods']]),
IndexFunction(
metadata['index_function']['name'],
{name: build_parameter(param)
for name, param in
metadata['index_function']['parameters'].items()}))
for cm in metadata['input']['cell_methods']])
params = metadata['index_function']['parameters']
if params is None:
parameters = {}
else:
parameters = {name: build_parameter(params[name])
for name in params}
index_function = IndexFunction(metadata['index_function']['name'],
parameters)
idx = IndexDefinition(metadata['reference'], metadata['period'],
output, input, index_function, source)
return idx
......@@ -289,7 +293,13 @@ class IndexCatalog:
for index in requested_indices:
definition = self.get_index_definition(index)
period_spec = select_period(definition.period)
index_function = build_index_function(definition.index_function)
try:
index_function = build_index_function(
definition.index_function)
except TypeError:
logging.error(f'Could not build index function for index '
f'{index} from definition {definition}')
raise
index = Index(index_function, definition.output, period_spec)
indices.append(index)
return indices
......
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