def test_formatting(self, pr_series): out = atmos.wetdays(pr_series(np.arange(366)), thresh=1.0 * units.mm / units.day) assert out.attrs[ "long_name"] == "Number of wet days (precip >= 1 mm/day)" out = atmos.wetdays(pr_series(np.arange(366)), thresh=1.5 * units.mm / units.day) assert out.attrs[ "long_name"] == "Number of wet days (precip >= 1.5 mm/day)"
def test_simple(self, pr_series): pr = np.zeros(100) pr[5:10] = 1 pr = pr_series(pr) out = xci.precip_accumulation(pr, freq='M') np.testing.assert_array_equal(out[0], 5 * 3600 * 24)
def test_cfunits2pint(self, pr_series): u = units2pint(pr_series([1, 2])) assert (str(u)) == "kilogram / meter ** 2 / second" assert pint2cfunits(u) == "kg m-2 s-1" u = units2pint("m^3 s-1") assert str(u) == "meter ** 3 / second" assert pint2cfunits(u) == "m^3 s-1"
def test_cfunits2pint(self, pr_series): u = cfunits2pint(pr_series([1, 2])) assert (str(u)) == 'kilogram / meter ** 2 / second' assert pint2cfunits(u) == 'kg m-2 s-1' u = cfunits2pint('m^3 s-1') assert str(u) == 'meter ** 3 / second' assert pint2cfunits(u) == 'm^3 s-1'
def test_factory(self, pr_series): attrs = dict(identifier='test', units='days', required_units='[length] / [time]', long_name='long name', standard_name='standard name', context='hydro' ) cls = Indicator.factory(attrs) assert issubclass(cls, Indicator) da = pr_series(np.arange(365)) cls(compute=ind.wetdays)(da)
def test_simple(self, pr_series, tas_series): pr = np.ones(450) pr = pr_series(pr, start='12/1/2000') tas = np.zeros(450) - 1 tas[10:20] += 10 tas = tas_series(tas + K2C, start='12/1/2000') out = xci.winter_rain_ratio(pr, tas=tas) np.testing.assert_almost_equal(out, [10. / (31 + 31 + 28), 0])
def test_consecutive_rain(self, tas_series, pr_series): tas = np.zeros(30) - 1 pr = np.zeros(30) tas[10:16] += 5 pr[10:16] += 5 tas = tas_series(tas + K2C) pr = pr_series(pr) out = xci.rain_on_frozen_ground_days(pr, tas, freq='MS') assert out[0] == 1
def test_small_rain(self, tas_series, pr_series): tas = np.zeros(30) - 1 pr = np.zeros(30) tas[10] += 5 pr[10] += .5 tas = tas_series(tas + K2C) pr = pr_series(pr / 3600 / 24) out = xci.rain_on_frozen_ground_days(pr, tas, freq='MS') assert out[0] == 0
def test_simple(self, pr_series, tas_series): pr = np.zeros(100) pr[10:20] = 1 pr = pr_series(pr) tas = np.zeros(100) tas[:14] -= 20 tas[14:] += 10 tas = tas_series(tas + K2C) out = xci.liquid_precip_ratio(pr, tas=tas, freq="M") np.testing.assert_almost_equal(out[:1], [0.6])
def test_simple(self, tas_series, pr_series): tas = np.zeros(30) - 1 pr = np.zeros(30) tas[10] += 5 pr[10] += 2 tas = tas_series(tas + K2C) pr = pr_series(pr / 3600 / 24) out = xci.rain_on_frozen_ground_days(pr, tas, freq="MS") assert out[0] == 1
def test_multi_max(self, pr_series): a = pr_series(np.array([3, 4, 20, 20, 0, 6, 15, 25, 0, 0])) rxnday = xci.max_n_day_precipitation_amount(a, 2) assert rxnday == 40 * 3600 * 24 assert len(rxnday) == 1 assert rxnday.time.dt.year == 2000
def test_sumlength_max(self, pr_series): a = pr_series(np.array([3, 4, 20, 20, 0, 6, 9, 25, 0, 0])) rxnday = xci.max_n_day_precipitation_amount(a, len(a)) assert rxnday == a.sum('time') * 3600 * 24 assert rxnday.time.dt.year == 2000
def test_run_start_at_0(self, pr_series): a = np.zeros(365) + 10 a[:10] = 0 pr = pr_series(a) out = xci.maximum_consecutive_dry_days(pr, freq='M') assert out[0] == 10
def test_simple(self, pr_series): a = np.zeros(365) + 10 a[5:15] = 0 pr = pr_series(a) out = xci.maximum_consecutive_dry_days(pr, freq='M') assert out[0] == 10
def test_mm(self, pr_series): pr = pr_series(np.zeros(365)) pr[3:8] += [.5, 1, 2, 3, 4] pr.attrs['units'] = 'mm/d' out = xci.daily_pr_intensity(pr, thresh='1 mm/day') np.testing.assert_array_almost_equal(out[0], 2.5)
def test_simple(self, pr_series): pr = pr_series(np.zeros(365)) pr[3:8] += [.5, 1, 2, 3, 4] out = xci.daily_pr_intensity(pr, thresh='1 kg/m**2/s') np.testing.assert_array_equal(out[0], 2.5 * 3600 * 24)
def test_pint_multiply(self, pr_series): a = pr_series([1, 2, 3]) out = utils.pint_multiply(a, 1 * units.days) assert out[0] == 1 * 60 * 60 * 24 assert out.units == 'kg m-2'
def test_mm(self, pr_series): pr = pr_series(np.zeros(365)) pr[3:8] += [0.5, 1, 2, 3, 4] pr.attrs["units"] = "mm/d" out = xci.daily_pr_intensity(pr, thresh="1 mm/day") np.testing.assert_array_almost_equal(out[0], 2.5)