def test_3d_data_with_nans(self): # test with 3d data pr = xr.open_dataset(self.nc_pr).pr # mm/s prMM = xr.open_dataset(self.nc_pr).pr prMM *= 86400 prMM.attrs["units"] = "mm/day" # put a nan somewhere prMM.values[10, 1, 0] = np.nan pr.values[10, 1, 0] = np.nan out1 = atmos.precip_accumulation(pr, freq="MS") out2 = atmos.precip_accumulation(prMM, freq="MS") # test kg m-2 s-1 pr.attrs["units"] = "kg m-2 s-1" out3 = atmos.precip_accumulation(pr, freq="MS") np.testing.assert_array_almost_equal(out1, out2, 3) np.testing.assert_array_almost_equal(out1, out3) # check some vector with and without a nan x1 = prMM[:31, 0, 0].values prTot = x1.sum() np.testing.assert_almost_equal(prTot, out1.values[0, 0, 0], 4) assert np.isnan(out1.values[0, 1, 0]) assert np.isnan(out1.values[0, -1, -1])
def test_with_different_phases(self): # test with different phases pr = open_dataset(self.nc_pr).pr # mm/s tasmin = open_dataset(self.nc_tasmin).tasmin # K out_tot = atmos.precip_accumulation(pr, freq="MS") out_sol = atmos.solid_precip_accumulation(pr, tas=tasmin, freq="MS") out_liq = atmos.liquid_precip_accumulation(pr, tas=tasmin, freq="MS") np.testing.assert_array_almost_equal(out_liq + out_sol, out_tot, 4) assert "solid" in out_sol.long_name assert "liquid" in out_liq.long_name assert out_sol.standard_name == "lwe_thickness_of_snowfall_amount" # With a non-default threshold out_sol = atmos.solid_precip_accumulation(pr, tas=tasmin, thresh="40 degF", freq="MS") out_liq = atmos.liquid_precip_accumulation(pr, tas=tasmin, thresh="40 degF", freq="MS") np.testing.assert_array_almost_equal(out_liq + out_sol, out_tot, 4)
def test_simple(self): pr = open_dataset("ERA5/daily_surface_cancities_1990-1993.nc").pr thresh = "1 mm/day" out = atmos.wet_precip_accumulation(pr, thresh=thresh) # Reference value t = core.units.convert_units_to(thresh, pr) pa = atmos.precip_accumulation(pr.where(pr >= t, 0)) np.testing.assert_array_equal(out, pa)