def test_3d_data_with_nans(self): # test with 3d data tas = xr.open_dataset(self.nc_file).tasmax # put a nan somewhere tas.values[180, 1, 0] = np.nan # compute with both skipna options thresh = 17 + K2C hdd = atmos.heating_degree_days(tas, freq="YS") x1 = tas.values[:, 0, 0] hdd1 = (thresh - x1).clip(min=0).sum() assert np.allclose(hdd1, hdd.values[0, 0, 0]) assert np.isnan(hdd.values[0, 1, 0]) assert np.isnan(hdd.values[0, -1, -1])
def test_convert_units(self): # test with 3d data tas = xr.open_dataset(self.nc_file).tasmax # put a nan somewhere tas.values[180, 1, 0] = np.nan tas.values -= K2C tas.attrs['units'] = 'C' # compute with both skipna options thresh = 17 hdd = atmos.heating_degree_days(tas, freq='YS') x1 = tas.values[:, 0, 0] hdd1 = (thresh - x1).clip(min=0).sum() assert (np.allclose(hdd1, hdd.values[0, 0, 0])) assert (np.isnan(hdd.values[0, 1, 0])) assert (np.isnan(hdd.values[0, -1, -1]))
def test_convert_units(self): # test with 3d data tas = open_dataset(self.nc_file).tasmax # put a nan somewhere tas.values[180, 1, 0] = np.nan tas.values -= K2C tas.attrs["units"] = "C" tas.attrs["cell_methods"] = "time: mean within days" # compute with both skipna options thresh = 17 hdd = atmos.heating_degree_days(tas, freq="YS") x1 = tas.values[:, 0, 0] hdd1 = (thresh - x1).clip(min=0).sum() assert np.allclose(hdd1, hdd.values[0, 0, 0]) assert np.isnan(hdd.values[0, 1, 0]) assert np.isnan(hdd.values[0, -1, -1])