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 612
612
from iris .analysis .cartography import area_weights
613
613
from iris .coord_categorisation import add_year
614
614
from iris .coords import AuxCoord
615
+ from iris .exceptions import ConstraintMismatchError
615
616
from matplotlib .colors import CenteredNorm
616
617
from matplotlib .gridspec import GridSpec
617
618
from matplotlib .ticker import (
@@ -1107,7 +1108,22 @@ def _load_and_preprocess_data(self):
1107
1108
for dataset in input_data :
1108
1109
filename = dataset ['filename' ]
1109
1110
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
1111
1127
1112
1128
# Fix time coordinate if present
1113
1129
if cube .coords ('time' , dim_coords = True ):
You can’t perform that action at this time.
0 commit comments