def test_bad_frequency(self): with pytest.raises(ValueError): n = 365 times = pd.date_range("2000-01-01", freq="12H", periods=n) da = xr.DataArray(np.arange(n), [("time", times)], attrs={"units": "K"}) tg_mean(da)
def test_Tmean_3d_data(self): ds_tmax = xr.open_dataset(self.nc_files[0]) ds_tmin = xr.open_dataset(self.nc_files[1]) tas = atmos.tg(ds_tmin.tasmin, ds_tmax.tasmax) tas_C = atmos.tg(ds_tmin.tasmin, ds_tmax.tasmax) tas_C.values -= K2C tas_C.attrs["units"] = "C" # put a nan somewhere tas.values[180, 1, 0] = np.nan tas_C.values[180, 1, 0] = np.nan tmmean = atmos.tg_mean(tas) tmmeanC = atmos.tg_mean(tas_C) x1 = tas.values[:, 0, 0] tmmean1 = x1.mean() # TODO: Investigate the differences between the two outputs. # The conversion to K is done after / before the mean. np.testing.assert_array_almost_equal(tmmeanC, tmmean, 3) # test single point vs manual assert np.allclose(tmmean1, tmmean.values[0, 0, 0], tmmeanC.values[0, 0, 0]) # test single nan point assert np.isnan(tmmean.values[0, 1, 0]) # test all nan point assert np.isnan(tmmean.values[0, -1, -1])
def test_bad_frequency(self): with pytest.raises(ValueError): n = 365 times = pd.date_range('2000-01-01', freq='12H', periods=n) da = xr.DataArray(np.arange(n), [('time', times)], attrs={'units': 'K'}) tg_mean(da)
def test_duplicate_dates(self): with pytest.raises(ValueError): n = 365 times = pd.date_range("2000-01-01", freq="1D", periods=n) times = times.append( pd.date_range("2000-12-29", freq="1D", periods=n)) da = xr.DataArray(np.arange(2 * n), [("time", times)], attrs={"units": "K"}) tg_mean(da)
def test_missing_one_day_between_two_years(self): with pytest.raises(ValueError): n = 365 times = pd.date_range("2000-01-01", freq="1D", periods=n) times = times.append( pd.date_range("2001-01-01", freq="1D", periods=n)) da = xr.DataArray(np.arange(2 * n), [("time", times)], attrs={"units": "K"}) tg_mean(da)
def test_duplicate_dates(self): with pytest.raises(ValueError): n = 365 times = pd.date_range('2000-01-01', freq='1D', periods=n) times = times.append( pd.date_range('2000-12-29', freq='1D', periods=n)) da = xr.DataArray(np.arange(2 * n), [('time', times)], attrs={'units': 'K'}) tg_mean(da)
def test_missing_one_day_between_two_years(self): with pytest.raises(ValueError): n = 365 times = pd.date_range('2000-01-01', freq='1D', periods=n) times = times.append( pd.date_range('2001-01-01', freq='1D', periods=n)) da = xr.DataArray(np.arange(2 * n), [('time', times)], attrs={'units': 'K'}) tg_mean(da)
def test_indicator_output(tas_series): tas = tas_series(np.zeros(365)) with set_options(metadata_locales=["fr"]): tgmean = atmos.tg_mean(tas, freq="YS") assert "long_name_fr" in tgmean.attrs assert (tgmean.attrs["description_fr"] == "Moyenne annuelle de la température journalière moyenne")
def test_assert_daily(self): n = 365 # one day short of a full year times = pd.date_range("2000-01-01", freq="1D", periods=n) da = xr.DataArray(np.arange(n), [("time", times)], attrs={"units": "K"}) tg_mean(da)
def test_assert_daily(self): n = 365 # one day short of a full year times = pd.date_range('2000-01-01', freq='1D', periods=n) da = xr.DataArray(np.arange(n), [('time', times)], attrs={'units': 'K'}) tg_mean(da)