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
def test_convert_units(self, tasmin_series): i = 3650 A = 10. tn = np.zeros(i) + A * np.sin( np.arange(i) / 365. * 2 * np.pi) + .1 * np.random.rand(i) tn[10:20] -= 2 tn = tasmin_series(tn + K2C) tn.attrs['units'] = 'C' tn10 = percentile_doy(tn, per=.1) out = atmos.cold_spell_duration_index(tn, tn10, freq='AS-JUL') assert out[0] == 10
def test_nan_presence(self, tasmin_series): i = 3650 A = 10. tn = np.zeros(i) + K2C + A * np.sin( np.arange(i) / 365. * 2 * np.pi) + .1 * np.random.rand(i) tn[10:20] -= 2 tn[9] = np.nan tn = tasmin_series(tn) tn10 = percentile_doy(tn, per=.1) out = atmos.cold_spell_duration_index(tn, tn10, freq='AS-JUL') assert np.isnan(out[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 += K2C tn[10:20] -= 2 tn = tasmin_series(tn) tn10 = percentile_doy(tn, per=10).sel(percentiles=10) out = atmos.cold_spell_duration_index(tn, tn10, freq="AS-JUL") assert out[0] == 10