Esempio n. 1
0
    def test_tn90p_simple(self, tasmin_series):
        i = 366
        tas = np.array(range(i))
        tas = tasmin_series(tas, start="1/1/2000")
        t90 = percentile_doy(tas, per=0.1)

        # create cold spell in june
        tas[175:180] = 1

        out = xci.tn90p(tas, t90, freq="MS")
        assert out[0] == 30
        assert out[1] == 29
        assert out[5] == 25
Esempio n. 2
0
    def test_simple(self, tasmax_series):
        i = 3650
        A = 10.0
        tx = (
            np.zeros(i)
            + A * np.sin(np.arange(i) / 365.0 * 2 * np.pi)
            + 0.1 * np.random.rand(i)
        )
        tx[10:20] += 2
        tx = tasmax_series(tx)
        tx90 = percentile_doy(tx, per=0.9)

        out = xci.warm_spell_duration_index(tx, tx90, freq="YS")
        assert out[0] == 10
Esempio n. 3
0
    def test_tg10p_simple(self, tas_series):
        i = 366
        tas = np.array(range(i))
        tas = tas_series(tas, start="1/1/2000")
        t10 = percentile_doy(tas, per=0.1)

        # create cold spell in june
        tas[175:180] = 1

        out = xci.tg10p(tas, t10, freq="MS")
        assert out[0] == 1
        assert out[5] == 5

        with pytest.raises(AttributeError):
            out = xci.tg10p(tas, tas, freq="MS")
Esempio n. 4
0
    def test_convert_units(self, tasmin_series):
        i = 3650
        A = 10.0
        tn = (
            np.zeros(i)
            + A * np.sin(np.arange(i) / 365.0 * 2 * np.pi)
            + 0.1 * np.random.rand(i)
        )
        tn[10:20] -= 2
        tn = tasmin_series(tn + K2C)
        tn.attrs["units"] = "C"
        tn10 = percentile_doy(tn, per=0.1)

        out = atmos.cold_spell_duration_index(tn, tn10, freq="AS-JUL")
        assert out[0] == 10
Esempio n. 5
0
    def test_simple(self, tasmin_series):
        i = 3650
        A = 10.0
        tn = (
            np.zeros(i)
            + A * np.sin(np.arange(i) / 365.0 * 2 * np.pi)
            + 0.1 * np.random.rand(i)
        )
        tn[10:20] -= 2
        tn = tasmin_series(tn)
        tn10 = percentile_doy(tn, per=0.1)

        out = xci.cold_spell_duration_index(tn, tn10, freq="YS")
        assert out[0] == 10
        assert out.units == "days"
Esempio n. 6
0
    def test_nan_presence(self, tasmin_series):
        i = 3650
        A = 10.0
        tn = (
            np.zeros(i)
            + K2C
            + A * np.sin(np.arange(i) / 365.0 * 2 * np.pi)
            + 0.1 * np.random.rand(i)
        )
        tn[10:20] -= 2
        tn[9] = np.nan
        tn = tasmin_series(tn)
        tn10 = percentile_doy(tn, per=0.1)

        out = atmos.cold_spell_duration_index(tn, tn10, freq="AS-JUL")
        assert np.isnan(out[0])
Esempio n. 7
0
    def test_doy_interpolation(self):
        pytest.importorskip('xarray', '0.11.4')

        # Just a smoke test
        fn_clim = os.path.join(
            TESTS_DATA, 'CanESM2_365day',
            'tasmin_day_CanESM2_rcp85_r1i1p1_na10kgrid_qm-moving-50bins-detrend_2095.nc'
        )
        fn = os.path.join(
            TESTS_DATA, 'HadGEM2-CC_360day',
            'tasmin_day_HadGEM2-CC_rcp85_r1i1p1_na10kgrid_qm-moving-50bins-detrend_2095.nc'
        )

        with xr.open_dataset(fn_clim) as ds:
            t10 = percentile_doy(ds.tasmin.isel(lat=0, lon=0), per=.1)

        with xr.open_dataset(fn) as ds:
            xci.tn10p(ds.tasmin.isel(lat=0, lon=0), t10, freq='MS')
Esempio n. 8
0
 def test_simple(self, tas_series):
     tas = tas_series(np.arange(365), start="1/1/2001")
     tas = xr.concat((tas, tas), "dim0")
     p1 = percentile_doy(tas, window=5, per=0.5)
     assert p1.sel(dayofyear=3, dim0=0).data == 2
     assert p1.attrs["units"] == "K"
Esempio n. 9
0
 def test_simple(self, tas_series):
     tas = tas_series(np.arange(365), start='1/1/2001')
     p1 = percentile_doy(tas, window=5, per=.5)
     assert p1.sel(dayofyear=3).data == 2
     assert p1.attrs['units'] == 'K'