示例#1
0
def GetResampledData(r, start, end):

    ##INPUT:
    ##r; str; site
    ##start; datetime; start of rainfall data
    ##end; datetime; end of rainfall data

    ##OUTPUT:
    ##rainfall; dataframe containing start to end of rainfall data resampled to 30min

    #raw data from senslope rain gauge
    rainfall = q.GetRawRainData(r, start)
    rainfall = rainfall.set_index('ts')
    rainfall = rainfall.loc[rainfall['rain'] >= 0]

    if rainfall.index[-1:] <= end - timedelta(1):
        return pd.DataFrame(data=None)

    #data resampled to 30mins
    if rainfall.index[-1:] < end:
        blankdf = pd.DataFrame({'ts': [end], 'rain': [0]})
        blankdf = blankdf.set_index('ts')
        rainfall = rainfall.append(blankdf)
    rainfall = rainfall[(rainfall.index >= start)]
    rainfall = rainfall[(rainfall.index <= end)]
    rainfall = rainfall.resample('30min', how='sum', label='right')

    return rainfall
示例#2
0
def getrain(rainsite, start, end):
    raindf = q.GetRawRainData(rainsite, fromTime=start, toTime=end)

    raindf = raindf.set_index('ts')
    raindf = raindf.resample('30min', how='sum')

    raindf['one_d'] = pd.rolling_sum(raindf.rain, 48, min_periods=1)
    raindf['thr_d'] = pd.rolling_sum(raindf.rain, 144, min_periods=1)

    raindf = raindf.reset_index()
    raindf['gts'] = raindf.ts.apply(datenum)

    return raindf
示例#3
0
def GetData(r, offsetstart, end):
    #raw data from senslope rain gauge
    rainfall = q.GetRawRainData(r, offsetstart)
    rainfall = rainfall.loc[rainfall['rain'] >= 0]
    rain_timecheck = rainfall

    #data resampled to 30mins
    blankdf = pd.DataFrame({'ts': [offsetstart, end], 'rain': [np.nan] * 2})
    rainfall = rainfall.append(blankdf)
    rainfall = rainfall.drop_duplicates('ts')
    rainfall = rainfall.set_index('ts')
    if len(rain_timecheck) < 1:
        rainfall = rainfall.resample('30min', how='pad', label='right')
    else:
        rainfall = rainfall.resample('30min', how='sum', label='right')

    rainfall = rainfall[(rainfall.index >= offsetstart)]
    rainfall = rainfall[(rainfall.index <= end)]

    return rainfall
示例#4
0
def get_rain_df(rain_gauge, start, end):
    rain_df = qdb.GetRawRainData(rain_gauge,
                                 fromTime=pd.to_datetime(start) - timedelta(3),
                                 toTime=end)

    rain_df = rain_df[rain_df.rain >= 0]
    rain_df = rain_df.set_index('ts')
    rain_df = rain_df.resample('30min').sum()

    rain_df['one'] = rain_df.rain.rolling(window=48,
                                          min_periods=1,
                                          center=False).sum()
    rain_df['one'] = np.round(rain_df.one, 2)
    rain_df['three'] = rain_df.rain.rolling(window=144,
                                            min_periods=1,
                                            center=False).sum()
    rain_df['three'] = np.round(rain_df.three, 2)

    rain_df = rain_df[(rain_df.index >= start) & (rain_df.index <= end)]
    rain_df = rain_df.reset_index()

    return rain_df