How to use the pytesmo.time_series.anomaly.calc_climatology function in pytesmo

To help you get started, we’ve selected a few pytesmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TUW-GEO / pytesmo / tests / test_time_series / test_anomaly.py View on Github external
def test_climatology_interpolate_leapday():
    ts = pd.Series(np.arange(365), index=pd.date_range(
        '2001-01-01', freq='D', periods=365))
    # remove a part of the time series
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=False, fill=-1)
    assert clim[60] == -1
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=True, fill=-1)
    assert clim[366] == -1
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=False, fill=-1, interpolate_leapday=True)
    assert clim[60] == np.mean((clim[59], clim[61]))
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=True, fill=-1, interpolate_leapday=True)
    assert clim[366] == np.mean((clim[365], clim[1]))
github TUW-GEO / pytesmo / tests / test_time_series / test_anomaly.py View on Github external
def test_climatology_interpolate_leapday():
    ts = pd.Series(np.arange(365), index=pd.date_range(
        '2001-01-01', freq='D', periods=365))
    # remove a part of the time series
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=False, fill=-1)
    assert clim[60] == -1
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=True, fill=-1)
    assert clim[366] == -1
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=False, fill=-1, interpolate_leapday=True)
    assert clim[60] == np.mean((clim[59], clim[61]))
    clim = anomaly.calc_climatology(ts, wraparound=True, respect_leap_years=True, fill=-1, interpolate_leapday=True)
    assert clim[366] == np.mean((clim[365], clim[1]))
github TUW-GEO / pytesmo / tests / test_time_series / test_anomaly.py View on Github external
def test_climatology_closed():
    ts = pd.Series(np.arange(366), index=pd.date_range(
        '2000-01-01', freq='D', periods=366))
    # remove a part of the time series
    ts['2000-02-01': '2000-02-28'] = np.nan
    ts = ts.dropna()
    clim = anomaly.calc_climatology(ts, wraparound=True)
    assert clim.size == 366
    # test that the arange was closed during the second moving average
    assert clim.iloc[365] - 187.90 < 0.01
github TUW-GEO / pytesmo / tests / test_time_series / test_anomaly.py View on Github external
def test_climatology_always_366():
    ts = pd.Series(np.sin(np.arange(366) / 366. * 2 * np.pi), index=pd.date_range(
        '2000-01-01', freq='D', periods=366))
    # remove a part of the time series
    ts['2000-02-01': '2000-02-28'] = np.nan
    ts = ts.dropna()
    clim = anomaly.calc_climatology(ts)
    assert clim.size == 366
github TUW-GEO / pytesmo / src / pytesmo / time_series / plotting.py View on Github external
for i, grid in enumerate(gs):
            if i < nr_columns - 1:
                ax = fig.add_subplot(grid, sharex=last_axis)
                axes.append(ax)
                ax.xaxis.set_visible(False)
        axes.append(last_axis)

    else:
        own_axis = False

    for i, column in enumerate(df):
        Ser = df[column]
        ax = axes[i]

        if clim is None:
            clima = anom.calc_climatology(Ser)
        else:
            clima = pd.Series(clim[column])
        anomaly = anom.calc_anomaly(Ser, climatology=clima, return_clim=True)

        anomaly[Ser.name] = Ser
        anomaly = anomaly.dropna()

        pos_anom = anomaly[Ser.name].values > anomaly['climatology'].values
        neg_anom = anomaly[Ser.name].values < anomaly['climatology'].values

        ax.plot(anomaly.index, anomaly[Ser.name].values, 'o',
                markersize=markersize, mfc=mfc, mec=mec)

        ax.plot(anomaly.index, anomaly['climatology'].values,
                linestyle=clim_linestyle,
                color=clim_color,
github TUW-GEO / pytesmo / src / pytesmo / validation_framework / adapters.py View on Github external
def calc_anom(self, data):
        if self.columns is None:
            ite = data
        else:
            ite = self.columns
        for column in ite:
            clim = calc_climatology(data[column], **self.kwargs)
            data[column] = calc_anomaly(data[column], climatology=clim)
        return data
github TUW-GEO / pytesmo / examples / anomalies.py View on Github external
# 

ascat_ts = ascat_SSM_reader.read_ssm(45,0)
#plot soil moisture
ascat_ts.data['sm'].plot()

# 

#calculate anomaly based on moving +- 17 day window
anomaly = ts.anomaly.calc_anomaly(ascat_ts.data['sm'], window_size=35)
anomaly.plot()

# 

#calculate climatology
climatology = ts.anomaly.calc_climatology(ascat_ts.data['sm'])
climatology.plot()

# 

#calculate anomaly based on climatology
anomaly_clim = ts.anomaly.calc_anomaly(ascat_ts.data['sm'], climatology=climatology)
anomaly_clim.plot()