def period_standardize(self, axis=None, dtype=None, ddof=1, period=None): """ Standardizes data by substracting the average over a reference period, and by dividing by the standard deviation over the same period. Parameters ---------- %(axis)s %(dtype)s %(ddof)s %(period)s Warnings -------- The default ``ddof`` is 1: by default, the method returns the unbiased estimate of the standard deviation. """ if period is None: period = self.refperiod elif not isinstance(period, (tuple, list, ndarray)): msg = "Period should be a tuple (starting date, ending date)!" raise ValueError, msg refdata = mask_outside_period(self, period[0], period[1], include_edges=False) refavg = refdata.mean(axis=axis, dtype=dtype) refstd = refdata.std(axis=axis, dtype=dtype, ddof=ddof) if not axis: result = (self - refavg) * 1. / refstd else: result = (self - ma.expand_dims(refavg)).astype(float) result /= ma.expand_dims(refstd) return result
def period_std(self, axis=None, dtype=None, out=None, ddof=1, period=None): """ Returns the standard deviation over a reference period. Parameters ---------- %(axis)s %(dtype)s %(out)s %(ddof)s %(period)s Warnings -------- The default ``ddof`` is 1: by default, the method returns the unbiased estimate of the standard deviation. """ if period is None: period = self.refperiod elif not isinstance(period, (tuple, list, ndarray)): msg = "Period should be a tuple (starting date, ending date)!" raise ValueError, msg refdata = mask_outside_period(self, period[0], period[1], include_edges=False) return refdata.std(axis=axis, dtype=dtype, out=out, ddof=ddof)
def period_average(self, axis=None, dtype=None, out=None, period=None): """ Returns the series averaged over the reference period, along the given axis. Parameters ---------- %(axis)s %(dtype)s %(out)s %(period)s """ if period is None: period = self.refperiod elif not isinstance(period, (tuple, list, ndarray)): msg = "Period should be a tuple (starting date, ending date)!" raise ValueError, msg refdata = mask_outside_period(self, period[0], period[1], include_edges=False) return refdata.mean(axis=axis, dtype=dtype, out=out)