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