def test_get_LDC_2d(): a = np.random.rand(8760, 4) a = make_timeseries(a, freq='h') b = get_LDC(a) assert np.isclose(np.nansum(b[1]), np.nansum(a)) # check monotonicity assert np.all(np.diff(b[1].sum(1)) < 0)
def test_get_LDC_not_annual(): a = np.random.rand(10000) a = make_timeseries(a, freq='h') b = get_LDC(a) assert np.isclose(b[1].sum(), a.sum()) #check monotonicity assert np.all(np.diff(b[1]) < 0)
def test_get_stats(): a = np.ones(8760) a = make_timeseries(a, freq='h') b = get_load_stats(a) assert a.sum() == b.loc['Sum'].squeeze() assert np.asarray(b.loc['Ramps (98%)'])[0] == (0,0) assert np.isclose(0, b.loc['Trend'].squeeze()) assert 1 == b.loc['Load Factor (peakiness)'].squeeze()
def test_disag_hourly_to_minutes(self): x = np.arange(0, 8760) y = (np.cos(2 * np.pi / 8759 * x) * 50 + 100) y = make_timeseries(y, freq='h') disag_profile = np.random.rand(60) y_disag = disag_upsample(y, disag_profile, to_offset='t') assert np.isclose(np.sum(y_disag), np.sum(y)) # <= 0.001 #FIXME: np test equality assert len(y_disag) == 8760 * 60
def test_disag_daily_to_hourly(self): x = np.arange(0, 365) y = (np.cos(2 * np.pi / 364 * x) * 50 + 100) y = make_timeseries(y, freq='d') disag_profile = np.random.rand(24) y_disag = disag_upsample(y, disag_profile) assert np.isclose(np.sum(y_disag), np.sum(y)) # <= 0.001 #FIXME: np test equality assert len(y_disag) == 8760
def test_reshape_multiannual_dataframe(): a = np.random.rand(8760*2) a = pd.DataFrame(make_timeseries(a, year=2019, freq='h')) b = reshape_timeseries(a, x='dayofyear', y='hour', aggfunc='sum') assert b.shape == (24,365) assert np.isclose(b.sum().sum(), a.sum())
def test_ndarray_h(self): a = np.random.rand(8760) b = make_timeseries(a) assert isinstance(b, pd.Series) assert sum(a) == sum(b)
def test_multiannual_timeseries(self): a = np.random.rand(8760*2) b = make_timeseries(a, freq='h') assert isinstance(b, pd.Series) assert sum(a) == sum(b)
def test_empty_frame_to_indexed_empty(self): b = make_timeseries(freq='H', length=8760) assert isinstance(b, pd.Series) and len(b) == 8760
def test_2d_ndarray(self): a = np.random.rand(8760,5) b = make_timeseries(a) assert type(b) == pd.DataFrame
def test_pddataframe_2d(self): a = pd.DataFrame(np.random.rand(35040,3)) b = make_timeseries(a) assert type(b) == pd.DataFrame
def test_pddataframe(self): a = pd.DataFrame(np.random.rand(8760)) b = make_timeseries(a) assert type(b) == pd.DataFrame
def test_pdseries(self): a = pd.Series(np.random.rand(8760)) b = make_timeseries(a) assert isinstance(b, pd.Series) assert sum(a) == sum(b)
def test_ndarray_x(self): a = np.random.rand(8730) b = make_timeseries(a, freq='H') assert isinstance(b, pd.Series) assert sum(a) == sum(b)
def test_reshape_multiannual(): a = np.random.rand(8760 * 2) a = make_timeseries(a, freq='h') b = reshape_timeseries(a, x='dayofyear', y='hour', aggfunc='sum') assert b.shape == (24, 365) assert np.isclose(b.sum().sum(), a.sum())
def test_empty_frame(self): a = np.array([]) b = make_timeseries(a, freq='H') assert type(b) == pd.Series and len(b)==0
def test_get_stats_df(): a = np.ones(8760) a = make_timeseries(a, freq='h').to_frame() b = get_load_stats(a) assert a.sum().sum() == b.loc['Sum'].squeeze()
def test_countweekend_days_per_month(): a = make_timeseries(year=2015, length=8760, freq='h') b = countweekend_days_per_month(a.resample('d').mean()) assert len(b) == 12 assert sum(b) == 104 #weekend days in 2015