def test_visualization_plot_precip_field( source, type, bbox, colorscale, probthr, title, colorbar, axis, ): if type == "intensity": field, metadata = get_precipitation_fields(0, 0, True, True, None, source) field = field.squeeze() field, metadata = conversion.to_rainrate(field, metadata) elif type == "depth": field, metadata = get_precipitation_fields(0, 0, True, True, None, source) field = field.squeeze() field, metadata = conversion.to_raindepth(field, metadata) elif type == "prob": field, metadata = get_precipitation_fields(0, 10, True, True, None, source) field, metadata = conversion.to_rainrate(field, metadata) field = ensemblestats.excprob(field, probthr) ax = plot_precip_field( field, type=type, bbox=bbox, geodata=metadata, colorscale=colorscale, probthr=probthr, units=metadata["unit"], title=title, colorbar=colorbar, axis=axis, ) pl.close()
def worker(lt, R_thr): if not np.any(np.isfinite(R_obs[lt, :, :])): return P_fct = excprob(R_fct[:, lt, :, :], R_thr) probscores.reldiag_accum(results[ws]["reldiag"][R_thr][lt], P_fct, R_obs[lt, :, :]) ensscores.rankhist_accum(results[ws]["rankhist"][R_thr][lt], R_fct[:, lt, :, :], R_obs[lt, :, :]) probscores.ROC_curve_accum(results[ws]["ROC"][R_thr][lt], P_fct, R_obs[lt, :, :])
def test_visualization_plot_precip_field( source, plot_type, bbox, colorscale, probthr, title, colorbar, axis, ): if plot_type == "intensity": field, metadata = get_precipitation_fields(0, 0, True, True, None, source) field = field.squeeze() field, metadata = conversion.to_rainrate(field, metadata) elif plot_type == "depth": field, metadata = get_precipitation_fields(0, 0, True, True, None, source) field = field.squeeze() field, metadata = conversion.to_raindepth(field, metadata) elif plot_type == "prob": field, metadata = get_precipitation_fields(0, 10, True, True, None, source) field, metadata = conversion.to_rainrate(field, metadata) field = ensemblestats.excprob(field, probthr) field_orig = field.copy() ax = plot_precip_field( field.copy(), type=plot_type, bbox=bbox, geodata=None, colorscale=colorscale, probthr=probthr, units=metadata["unit"], title=title, colorbar=colorbar, axis=axis, ) # Check that plot_precip_field does not modify the input data field_orig = np.ma.masked_invalid(field_orig) field_orig.data[field_orig.mask] = -100 field = np.ma.masked_invalid(field) field.data[field.mask] = -100 assert np.array_equal(field_orig.data, field.data)
def worker(lt, scale_km): lt_idx = int(lt / v_accu_min - 1) if not np.any(np.isfinite(R_obs_c[lt_idx, :, :])): return R_fct_s, _ = aggregate_fields_space(R_fct_c, metafct_c, scale_km * 1000, ignore_nan=False) R_obs_s, _ = aggregate_fields_space(R_obs_c, metaobs_c, scale_km * 1000, ignore_nan=False) for R_thr in R_thrs: P_fct = excprob(R_fct_s[:, lt_idx, :, :], R_thr, ignore_nan=True) probscores.reldiag_accum( results[c, m]["reldiag"][R_thr][scale_km][lt], P_fct, R_obs_s[lt_idx, :, :]) ensscores.rankhist_accum( results[c, m]["rankhist"][R_thr][scale_km][lt], R_fct_s[:, lt_idx, :, :], R_obs_s[lt_idx, :, :]) probscores.ROC_curve_accum( results[c, m]["ROC"][R_thr][scale_km][lt], P_fct, R_obs_s[lt_idx, :, :]) # Only for lowest threshold probscores.CRPS_accum( results[c, m]["CRPS"][R_thrs[0]][scale_km][lt], R_fct_s[:, lt_idx, :, :], R_obs_s[lt_idx, :, :]) results[c,m][skill_varname][R_thrs[0]][scale_km][lt]["sum"] +=\ ensscores.ensemble_skill(R_fct_s[:, lt_idx, :, :],R_obs_s[lt_idx, :, :],spread_skill_metric) results[c,m][spread_varname][R_thrs[0]][scale_km][lt]["sum"] +=\ ensscores.ensemble_spread(R_fct_s[:, lt_idx, :, :],spread_skill_metric) results[c, m][skill_varname][ R_thrs[0]][scale_km][lt]["n"] += 1 results[c, m][spread_varname][ R_thrs[0]][scale_km][lt]["n"] += 1
R_f_mean = np.mean(R_f[:, -1, :, :], axis=0) pyplot.figure() plot_precip_field(R_f_mean, map="basemap", geodata=metadata, drawlonlatlines=True, basemap_resolution='h') pyplot.savefig("STEPS_ensemble_mean.png", bbox_inches="tight", dpi=300) pyplot.figure() plot_precip_field(R_f[0, -1, :, :], map="basemap", geodata=metadata, drawlonlatlines=True, basemap_resolution='h') pyplot.savefig("STEPS_ensemble_member.png", bbox_inches="tight", dpi=300) pyplot.figure() P = excprob(R_f[:, -1, :, :], 0.5) plot_precip_field(P, map="basemap", geodata=metadata, drawlonlatlines=True, basemap_resolution='h', type="prob", units="mm/h", probthr=0.5) pyplot.savefig("STEPS_excprob_0.5.png", bbox_inches="tight", dpi=300)
def test_exceptions_excprob(X): with pytest.raises(Exception): excprob(X, 2.0)
def test_ensemblestats_excprob(X, X_thr, ignore_nan, expected): """Test ensemblestats excprob.""" assert_array_almost_equal(excprob(X, X_thr, ignore_nan), expected)
def test_ROC_curve_area(X_f, X_o, X_min, n_prob_thrs, compute_area, expected): """Test the ROC_curve.""" P_f = excprob(X_f, X_min, ignore_nan=False) assert_array_almost_equal( probscores.ROC_curve(P_f, X_o, X_min, n_prob_thrs, compute_area)[2], expected)
def test_reldiag_sum(X_f, X_o, X_min, n_bins, min_count, expected): """Test the reldiag.""" P_f = excprob(X_f, X_min, ignore_nan=False) assert_array_almost_equal( np.sum(probscores.reldiag(P_f, X_o, X_min, n_bins, min_count)[1]), expected)
fn_ext, 5, 0, num_next_files=12) # read the observations Z_obs, _, metadata = io.read_timeseries(fns, import_fmi_pgm, gzipped=True, num_next_files=12) R_obs = conversion.to_rainrate(Z_obs, metadata, 223.0, 1.53)[0] # iterate over the nowcast lead times for lt in range(R_f.shape[1]): # compute the exceedance probability of 0.1 mm/h from the ensemble P_f = ensemblestats.excprob(R_f[:, lt, :, :], 0.1, ignore_nan=True) # compute and plot the ROC curve roc = verification.ROC_curve_init(0.1, n_prob_thrs=10) verification.ROC_curve_accum(roc, P_f, R_obs[lt + 1, :, :]) fig = figure() verification.plot_ROC(roc, ax=fig.gca(), opt_prob_thr=True) pyplot.savefig("ROC_%02d.eps" % (lt + 1), bbox_inches="tight") pyplot.close() # compute and plot the reliability diagram reldiag = verification.reldiag_init(0.1) verification.reldiag_accum(reldiag, P_f, R_obs[lt + 1, :, :]) fig = figure() verification.plot_reldiag(reldiag, ax=fig.gca()) pyplot.savefig("reldiag_%02d.eps" % (lt + 1), bbox_inches="tight")