Skip to content

Commit bd6f4be

Browse files
authored
Merge pull request #14 from SWxTREC/fix/missing-fields
FIX: Skip variables that aren't present in the dataset
2 parents 78482e0 + 2c784a8 commit bd6f4be

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

enlilviz/io.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ def read_enlil2d(filename):
194194
'dd13_3d', 'vv13_3d', 'pp13_3d', 'cc13_3d',
195195
'dd23_3d', 'vv23_3d', 'pp23_3d', 'cc23_3d']
196196
for var in slice_variables:
197-
ds = _calibrate_variable(ds, var)
197+
try:
198+
ds = _calibrate_variable(ds, var)
199+
except KeyError:
200+
# Ignore if the variable wasn't found in the dataset
201+
pass
198202

199203
# Now work on the field line and satellite data
200204
for fieldline in fieldline_vars:
@@ -212,9 +216,13 @@ def read_enlil2d(filename):
212216
ds = ds.drop([sat + '_FLD_' + var for sat in _satellites])
213217
name += 'fld_'
214218
else:
215-
da = xr.concat([ds[sat + '_' + var] for sat in _satellites],
216-
dim='satellite')
217-
ds = ds.drop([sat + '_' + var for sat in _satellites])
219+
try:
220+
da = xr.concat([ds[sat + '_' + var] for sat in _satellites],
221+
dim='satellite')
222+
ds = ds.drop([sat + '_' + var for sat in _satellites])
223+
except KeyError:
224+
# If the variable isn't here, continue the loop
225+
continue
218226

219227
name += _variables[var]
220228
da.name = name

0 commit comments

Comments
 (0)