Exemplo n.º 1
0
def test_aggregate_ninterval_groupby():
    """Test API ValueError, ninterval and groupby."""
    with pytest.raises(ValueError):
        _ = tstoolbox.aggregate(statistic="sum",
                                groupby="7D",
                                ninterval=7,
                                input_ts="tests/data_flat.csv")
Exemplo n.º 2
0
def test_aggregate_ninterval_groupby():
    """Test API ValueError, ninterval and groupby."""
    with pytest.raises(ValueError):
        _ = tstoolbox.aggregate(statistic="sum",
                                groupby="7D",
                                ninterval=7,
                                input_ts="tests/data_flat.csv")
Exemplo n.º 3
0
def test_aggregate_groupby():
    """Test API ValueError, groupby and agg_interval."""
    with pytest.raises(ValueError):
        _ = tstoolbox.aggregate(statistic="sum",
                                groupby="D",
                                agg_interval="D",
                                input_ts="tests/data_flat.csv")
Exemplo n.º 4
0
 def test_aggregate_direct_sum(self):
     ''' Test daily mean summation
     '''
     out = tstoolbox.aggregate(statistic='sum',
                               agg_interval='daily',
                               input_ts='tests/data_flat.csv')
     assert_frame_equal(out, self.aggregate_direct_sum)
Exemplo n.º 5
0
def daily_to_daytime_hourly_trapezoid(
                   latitude,
                   statistic='mean',
                   input_ts='-',
                   start_date=None,
                   end_date=None,
                   float_format='%g',
                   print_input=''):
    '''
    Daily to hourly disaggregation based on a trapezoidal shape.
    '''
    from tstoolbox import tstoolbox
    tsd = tsutils.common_kwds(tsutils.read_iso_ts(input_ts),
                             start_date=start_date,
                             end_date=end_date,
                             pick=None)
    lrad = latitude*np.pi/180.0

    ad = 0.40928*np.cos(0.0172141*(172 - tsd.index.dayofyear))
    ss = np.sin(lrad)*np.sin(ad)
    cs = np.cos(lrad)*np.cos(ad)
    x2 = -ss/cs
    delt = 7.6394*(np.pi/2.0 - np.arctan(x2/np.square(1 - x2**2)))
    sunr = 12.0 - delt/2.0

    #develop hourly distribution given sunrise,
    #sunset and length of day (DELT)
    dtr2 = delt / 2.0
    dtr4 = delt / 4.0
    crad = 2.0/3.0/dtr2/60 # using minutes...
    tr2 = sunr + dtr4
    tr3 = tr2 + dtr2
    tr4 = tr3 + dtr4

    sdate = datetime.datetime(tsd.index[0].year, tsd.index[0].month,
            tsd.index[0].day)
    edate = datetime.datetime(tsd.index[-1].year, tsd.index[-1].month,
            tsd.index[-1].day) + datetime.timedelta(days=1) - datetime.timedelta(hours=1)
    datevalue = pandas.DatetimeIndex(start=sdate, end=edate,
            freq='MIN')
    fdata = pandas.Series([np.nan]*(len(datevalue)), index=datevalue)
    fdata[0] = 0.0
    fdata[-1] = 0.0
    for index in range(len(sunr)):
        cdate = tsd.index[index]
        fdata[datetime.datetime(cdate.year, cdate.month, cdate.day, int(sunr[index]), int((sunr[index] - int(sunr[index]))*60))] = 0.0
        fdata[datetime.datetime(cdate.year, cdate.month, cdate.day, int(tr4[index]), int((tr4[index] - int(tr4[index]))*60))] = 0.0
        fdata[datetime.datetime(cdate.year, cdate.month, cdate.day, int(tr2[index]), int((tr2[index] - int(tr2[index]))*60))] = crad[index]
        fdata[datetime.datetime(cdate.year, cdate.month, cdate.day, int(tr3[index]), int((tr3[index] - int(tr3[index]))*60))] = crad[index]
    fdata = fdata.interpolate('linear')

    fdata = fdata.fillna(0.0)

    fdata = tstoolbox.aggregate(statistic=statistic,
                                agg_interval='H',
                                input_ts=fdata
                                )
    return tsutils.print_input(print_input, tsd, fdata, None,
                               float_format=float_format)
Exemplo n.º 6
0
def test_aggregate_groupby():
    """Test API ValueError, groupby and agg_interval."""
    with pytest.raises(ValueError):
        _ = tstoolbox.aggregate(
            statistic="sum",
            groupby="D",
            agg_interval="D",
            input_ts="tests/data_flat.csv",
        )
Exemplo n.º 7
0
import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pytest

from tstoolbox import tstoolbox

# Pull this in once.
df = tstoolbox.aggregate(agg_interval="D",
                         clean=True,
                         input_ts="tests/02234500_65_65.csv")
# Pull this in once.
dfa = tstoolbox.aggregate(agg_interval="A",
                          clean=True,
                          input_ts="tests/02234500_65_65.csv")


@pytest.mark.mpl_image_compare(tolerance=6)
def test_time_plot():
    plt.close("all")
    return tstoolbox.plot(
        type="time",
        columns=1,
        clean=True,
        input_ts="tests/02234500_65_65.csv",
        ofilename=None,
        plot_styles="classic",
    )

Exemplo n.º 8
0
def test_aggregate_agg_interval():
    """Test API agg_interval."""
    with pytest.warns(UserWarning):
        _ = tstoolbox.aggregate(statistic="mean",
                                agg_interval="D",
                                input_ts="tests/data_flat.csv")
Exemplo n.º 9
0
def test_aggregate_bad_statistic():
    """Test API statistic name."""
    with pytest.raises(ValueError):
        _ = tstoolbox.aggregate(statistic="camel",
                                groupby="D",
                                input_ts="tests/data_flat.csv")
Exemplo n.º 10
0
 def test_aggregate_direct_sum(self):
     """Test daily mean summation."""
     out = tstoolbox.aggregate(statistic='sum',
                               groupby='daily',
                               input_ts='tests/data_flat.csv')
     assert_frame_equal(out, self.aggregate_direct_sum)
Exemplo n.º 11
0
import matplotlib
matplotlib.use('Agg')

import pytest

from tstoolbox import tstoolbox

# Pull this in once.
df = tstoolbox.aggregate(agg_interval='D',
                         clean=True,
                         input_ts='tests/02234500_65_65.csv')
# Pull this in once.
dfa = tstoolbox.aggregate(agg_interval='A',
                          clean=True,
                          input_ts='tests/02234500_65_65.csv')

@pytest.mark.mpl_image_compare
def test_time_plot():
    return tstoolbox.plot(type='time',
                          columns=1,
                          clean=True,
                          input_ts='tests/02234500_65_65.csv',
                          ofilename=None)

@pytest.mark.mpl_image_compare
def test_time_multiple_traces_plot():
    return tstoolbox.plot(type='time',
                          columns=[2,3],
                          style='b-,r*',
                          input_ts='tests/data_daily_sample.csv',
                          ofilename=None)
Exemplo n.º 12
0
def test_aggregate_bad_statistic():
    """Test API statistic name."""
    with pytest.raises(ValueError):
        _ = tstoolbox.aggregate(statistic="camel",
                                groupby="D",
                                input_ts="tests/data_flat.csv")
Exemplo n.º 13
0
 def test_aggregate_direct_sum(self):
     """Test daily mean summation."""
     out = tstoolbox.aggregate(statistic="sum",
                               groupby="daily",
                               input_ts="tests/data_flat.csv")
     assert_frame_equal(out, self.aggregate_direct_sum)
Exemplo n.º 14
0
def test_aggregate_ninterval():
    """Test API ninterval."""
    with pytest.warns(UserWarning):
        _ = tstoolbox.aggregate(statistic="mean",
                                ninterval=7,
                                input_ts="tests/data_flat.csv")