Skip to content

Commit

Permalink
Robust for missing or old data
Browse files Browse the repository at this point in the history
Be robust when a channel is missing (always nan), or when a file is of an
old format (no u-common).
  • Loading branch information
gerritholl committed Dec 12, 2018
1 parent 4835ffd commit 2ab8814
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions FCDR_HIRS/analysis/summarise_fcdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ def plot_period_ptiles(self, start, end, fields,
"fcdr_type": fcdr_type,
"satname": sat},
NO_CACHE=True)
if all(summary.isnull().all()[fields].all().variables.values()):
if all(summary.isnull().all()[
[f for f in fields if f in summary.data_vars.keys()]].all().variables.values()):
raise DataFileError(f"All data invalid for {sat:s}!")
except DataFileError:
continue
Expand All @@ -365,6 +366,15 @@ def plot_period_ptiles(self, start, end, fields,
f"{start:%Y-%m-%d}--{end:%Y-%m-%d}")
(f, a_all) = figs[channel]
for (i, (fld, a)) in enumerate(zip(fields, a_all.ravel())):
try:
if not numpy.isfinite(summary[fld].sel(channel=channel)).any():
logging.error(f"All nans for channel {channel:d} "
f"{fld:s}, skipping")
continue
except KeyError as e:
logging.error("Can't plot ptiles for "
f"channel {channel:d} {fld:s}, no {e.args[0]:s}")
continue
#summary[fld].values[summary[fld]==0] = numpy.nan # workaround #126, redundant after fix
for (ptile, ls, color) in zip(sorted(ptiles), pstyles, pcolors):
if i!=0:
Expand Down Expand Up @@ -396,6 +406,8 @@ def plot_period_ptiles(self, start, end, fields,
a.grid(True, axis="both")
# prepare some info for later, with zoomed-in y-axes
for (fld, a) in zip(fields, a_all.ravel()):
if not fld in summary.data_vars.keys():
continue
lo = scipy.stats.mstats.mquantiles(
numpy.ma.masked_invalid(
summary[fld].sel(channel=channel).sel(ptile=25).values),
Expand Down Expand Up @@ -480,9 +492,13 @@ def plot_period_hists(self, start, end, fcdr_type="easy"):
y = summary[f"hist_u_{lab_struc:s}"].sel(channel=ch).sum("date")
a.plot(x, y, label=f"Ch. {ch:d}, {lab_struc:s}",
color=f"C{k:d}", linestyle="-")
y = summary[f"hist_u_{lab_comm:s}"].sel(channel=ch).sum("date")
a.plot(x, y, label=f"Ch. {ch:d}, {lab_comm:s}",
color=f"C{k:d}", linestyle=":")
try:
y = summary[f"hist_u_{lab_comm:s}"].sel(channel=ch).sum("date")
except KeyError as e:
logging.error(f"Cannot plot hist for channel {ch:d}: " + e.args[0])
else:
a.plot(x, y, label=f"Ch. {ch:d}, {lab_comm:s}",
color=f"C{k:d}", linestyle=":")
a.legend()
a.set_xlim([0,
float(summary[f"bins_u_{lab_struc:s}"].sel(channel=chs[0]).isel(bin_edges=idx_hi))])
Expand Down

0 comments on commit 2ab8814

Please sign in to comment.