Skip to content

Commit

Permalink
Merge pull request #256 from pstradio/calc_debugging
Browse files Browse the repository at this point in the history
Calc debugging
  • Loading branch information
s-scherrer authored Dec 16, 2021
2 parents f1e4518 + f481c3c commit 4e2cd40
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/pytesmo/validation_framework/metric_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,17 +1717,18 @@ def calc_metrics(self, data, gpi_info):
result = super().calc_metrics(data, gpi_info)
n_obs = len(data)
result["n_obs"][0] = n_obs
if n_obs < self.min_obs:
warnings.warn(
"Not enough observations to calculate metrics.", UserWarning
)
return result

# get the remaining metrics template for this specific combination
othernames = list(data.columns)
othernames.remove(self.refname)
result.update(self._get_metric_template(self.refname, othernames))

if n_obs < self.min_obs:
warnings.warn(
"Not enough observations to calculate metrics.", UserWarning
)
return result

# calculate triple collocation metrics
ds_names = (self.refname, *othernames)
arrays = (data[name].values for name in ds_names)
Expand All @@ -1737,10 +1738,16 @@ def calc_metrics(self, data, gpi_info):
for j, metric in enumerate(["snr", "err_std", "beta"]):
result[(metric, name)][0] = res[j][i]
else:
res = tcol_metrics_with_bootstrapped_ci(*arrays)
for i, name in enumerate(ds_names):
for j, metric in enumerate(["snr", "err_std", "beta"]):
result[(metric, name)][0] = res[j][0][i]
result[(metric + "_ci_lower", name)][0] = res[j][1][i]
result[(metric + "_ci_upper", name)][0] = res[j][2][i]
try:
# handle failing bootstrapping because e.g.
# too small sample size
res = tcol_metrics_with_bootstrapped_ci(*arrays)
for i, name in enumerate(ds_names):
for j, metric in enumerate(["snr", "err_std", "beta"]):
result[(metric, name)][0] = res[j][0][i]
result[(metric + "_ci_lower", name)][0] = res[j][1][i]
result[(metric + "_ci_upper", name)][0] = res[j][2][i]
except ValueError:
# if the calculation fails, the template results (np.nan) are used
pass
return result

0 comments on commit 4e2cd40

Please sign in to comment.