File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
esmvaltool/diag_scripts/monitor Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 612612from iris .analysis .cartography import area_weights
613613from iris .coord_categorisation import add_year
614614from iris .coords import AuxCoord
615+ from iris .exceptions import ConstraintMismatchError
615616from matplotlib .colors import CenteredNorm
616617from matplotlib .gridspec import GridSpec
617618from matplotlib .ticker import (
@@ -1107,7 +1108,22 @@ def _load_and_preprocess_data(self):
11071108 for dataset in input_data :
11081109 filename = dataset ['filename' ]
11091110 logger .info ("Loading %s" , filename )
1110- cube = iris .load_cube (filename )
1111+ cubes = iris .load (filename )
1112+ if len (cubes ) == 1 :
1113+ cube = cubes [0 ]
1114+ else :
1115+ var_name = dataset ['short_name' ]
1116+ try :
1117+ cube = cubes .extract_cube (iris .NameConstraint (
1118+ var_name = var_name
1119+ ))
1120+ except ConstraintMismatchError as exc :
1121+ var_names = [c .var_name for c in cubes ]
1122+ raise ValueError (
1123+ f"Cannot load data: multiple variables ({ var_names } ) "
1124+ f"are available in file { filename } , but not the "
1125+ f"requested '{ var_name } '"
1126+ ) from exc
11111127
11121128 # Fix time coordinate if present
11131129 if cube .coords ('time' , dim_coords = True ):
You can’t perform that action at this time.
0 commit comments