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
268faa52
Commit
268faa52
authored
Nov 11, 2019
by
Klaus Zimmermann
Browse files
Improve reporting of index problems (closes
#128
)
parent
2bce8047
Changes
1
Hide whitespace changes
Inline
Side-by-side
climix/metadata.py
View file @
268faa52
...
...
@@ -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
(
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
(
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
()}))
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'
]])
input
=
InputVariable
(
metadata
[
'input'
][
'var_name'
],
metadata
[
'input'
][
'standard_name'
],
[
CellMethod
(
*
cm
.
popitem
())
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
...
...
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