Example #1
0
    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 = 18 + K2C
        cdd = atmos.cooling_degree_days(tas, thresh="18 C", freq="YS")

        x1 = tas.values[:, 0, 0]

        cdd1 = (x1[x1 > thresh] - thresh).sum()

        assert np.allclose(cdd1, cdd.values[0, 0, 0])

        assert np.isnan(cdd.values[0, 1, 0])

        assert np.isnan(cdd.values[0, -1, -1])
Example #2
0
    def test_convert_units(self):
        # test with 3d data
        tas = xr.open_dataset(self.nc_file).tasmax
        tas.values -= K2C
        tas.attrs["units"] = "C"
        # put a nan somewhere
        tas.values[180, 1, 0] = np.nan

        # compute with both skipna options
        thresh = 18
        cdd = atmos.cooling_degree_days(tas, thresh="18 C", freq="YS")

        x1 = tas.values[:, 0, 0]
        # x2 = tas.values[:, 1, 0]

        cdd1 = (x1[x1 > thresh] - thresh).sum()
        # gdd2 = (x2[x2 > thresh] - thresh).sum()

        assert np.allclose(cdd1, cdd.values[0, 0, 0])
        # assert (np.allclose(gdd1, gdds.values[0, 0, 0]))
        assert np.isnan(cdd.values[0, 1, 0])
        # assert (np.allclose(gdd2, gdds.values[0, 1, 0]))
        assert np.isnan(cdd.values[0, -1, -1])