def test_horizon_bootstrap_1d(perfectModelEnsemble_initialized_control): """test horizon for pm.bootstrap for 1d.""" bskill = perfectModelEnsemble_initialized_control.bootstrap( iterations=201, metric="rmse", comparison="m2e", dim=["member", "init"], reference="uninitialized", ) ph = horizon(bskill.sel(results="p", skill="uninitialized") <= 0.05) assert ph.tos.attrs["units"] == "years", print(ph.tos) assert int(ph.tos) in [4, 5, 6, 7, 8] # should be 6, testing on the safe side
def test_horizon_smooth(perfectModelEnsemble_initialized_control, smooth): """test horizon for pm.smooth(lead).verify.""" pm = perfectModelEnsemble_initialized_control if smooth: pm = pm.smooth( {"lead": 2}, how="mean") # converts lead to '1-2', '2-3', ... after verify skill = pm.verify( metric="rmse", comparison="m2e", dim=["member", "init"], reference="persistence", ) assert skill.lead.attrs["units"] == "years", print(skill.lead.attrs) # initialized better than persistence if RMSE smaller cond = skill.sel(skill="initialized", drop=True) < skill.sel( skill="persistence", drop=True) ph = horizon(cond) assert ph.tos.attrs["units"] == "years", print("ph.tos.attrs = ", ph.tos.attrs) assert ph.tos.values == skill.lead.isel(lead=-1).values
def test_horizon_3d(hindcast_recon_3d): he = hindcast_recon_3d # set one grid to all nan mimicking land land = he._datasets["initialized"]["SST"][:, :, 0, 0] he._datasets["initialized"]["SST"][:, :, 0, 0] = land.where(land == 100000) # verify skill = he.verify( metric="acc", comparison="e2o", dim="init", alignment="maximize", reference=["persistence"], ) ph = horizon( skill.sel(skill="initialized") > skill.sel(skill="persistence")) # test all nan on land assert ph["SST"][0, 0].isnull() # test significant everywhere assert (ph >= 1).all() assert (ph.isel(nlat=-1) == 2).all()