def test_sprog( n_cascade_levels, ar_order, probmatching_method, domain, min_csi): """Tests SPROG nowcast.""" # inputs precip_input, metadata = get_precipitation_fields(num_prev_files=2, num_next_files=0, return_raw=False, metadata=True, upscale=2000) precip_input = precip_input.filled() precip_obs = get_precipitation_fields(num_prev_files=0, num_next_files=3, return_raw=False, upscale=2000)[1:, :, :] precip_obs = precip_obs.filled() # Retrieve motion field pytest.importorskip("cv2") oflow_method = motion.get_method("LK") retrieved_motion = oflow_method(precip_input) # Run nowcast nowcast_method = nowcasts.get_method("sprog") precip_forecast = nowcast_method( precip_input, retrieved_motion, n_timesteps=3, R_thr=metadata["threshold"], n_cascade_levels=n_cascade_levels, ar_order=ar_order, probmatching_method=probmatching_method, domain=domain, ) # result result = verification.det_cat_fct( precip_forecast[-1], precip_obs[-1], thr=0.1, scores="CSI")["CSI"] print(f"got CSI={result:.1f}, required > {min_csi:.1f}") assert result > min_csi
def test_sprog( n_cascade_levels, ar_order, probmatching_method, domain, timesteps, min_csi ): """Tests SPROG nowcast.""" # inputs precip_input, metadata = get_precipitation_fields( num_prev_files=2, num_next_files=0, return_raw=False, metadata=True, upscale=2000, ) precip_input = precip_input.filled() precip_obs = get_precipitation_fields( num_prev_files=0, num_next_files=3, return_raw=False, upscale=2000 )[1:, :, :] precip_obs = precip_obs.filled() pytest.importorskip("cv2") oflow_method = motion.get_method("LK") retrieved_motion = oflow_method(precip_input) nowcast_method = nowcasts.get_method("sprog") precip_forecast = nowcast_method( precip_input, retrieved_motion, timesteps=timesteps, R_thr=metadata["threshold"], n_cascade_levels=n_cascade_levels, ar_order=ar_order, probmatching_method=probmatching_method, domain=domain, ) assert precip_forecast.ndim == 3 assert precip_forecast.shape[0] == ( timesteps if isinstance(timesteps, int) else len(timesteps) ) result = verification.det_cat_fct( precip_forecast[-1], precip_obs[-1], thr=0.1, scores="CSI" )["CSI"] assert result > min_csi, f"CSI={result:.1f}, required > {min_csi:.1f}"
def test_anvil_rainrate(n_cascade_levels, ar_order, ar_window_radius, timesteps, min_csi): """Tests ANVIL nowcast using rain rate precipitation fields.""" # inputs precip_input, metadata = get_precipitation_fields( num_prev_files=4, num_next_files=0, return_raw=False, metadata=True, upscale=2000, ) precip_input = precip_input.filled() precip_obs = get_precipitation_fields(num_prev_files=0, num_next_files=3, return_raw=False, upscale=2000)[1:, :, :] precip_obs = precip_obs.filled() pytest.importorskip("cv2") oflow_method = motion.get_method("LK") retrieved_motion = oflow_method(precip_input) nowcast_method = nowcasts.get_method("anvil") precip_forecast = nowcast_method( precip_input[-(ar_order + 2):], retrieved_motion, timesteps=timesteps, rainrate=None, # no R(VIL) conversion is done n_cascade_levels=n_cascade_levels, ar_order=ar_order, ar_window_radius=ar_window_radius, ) assert precip_forecast.ndim == 3 assert precip_forecast.shape[0] == (timesteps if isinstance( timesteps, int) else len(timesteps)) result = verification.det_cat_fct(precip_forecast[-1], precip_obs[-1], thr=0.1, scores="CSI")["CSI"] assert result > min_csi, f"CSI={result:.2f}, required > {min_csi:.2f}"
def test_det_cat_fct(pred, obs, thr, scores, expected): """Test the det_cat_fct.""" assert_array_almost_equal( list(det_cat_fct(pred, obs, thr, scores).values()), expected)