def init_masks(self): self.resmask = ma.make_mask_none(self.data.shape) self.colmask = ma.make_mask_none(self.data.shape) self.incmask = ma.make_mask_none(self.data.shape) self.fitmask = ma.make_mask_none(self.data.shape) self.masks = (self.resmask, self.colmask, self.incmask, self.fitmask) self.masknames = ("resmask", "colmask", "incmask", "fitmask")
def rcolclean(x, col_eff, cs): iqrange = iqr(col_eff) low = quantile(col_eff, 0.25) - cs * iqrange high = quantile(col_eff, 0.75) + cs * iqrange colkill = where((col_eff < low) | (col_eff > high)) mask = ma.make_mask_none(x.shape[1]) mask[colkill] = np.ones(mask[colkill].shape, dtype=bool) return mask
def fitclean(date, x, t): def covar(x, y): '''Returns the covariance of x and y''' cmat = cov(x, y) return cmat[0, 1] def slope(y, x): '''Returns the absolute value of the SLR slope''' reg = vstack((ones(x.shape), x)) (beta, res, rank, singular) = linalg.lstsq(reg.transpose(), y) return beta[1] # slopes = np.apply_along_axis(slope, 0, x, date) # using the var/cov formula for slope is faster than doing least squares varx = var(date) covxy = np.apply_along_axis(covar, 0, x, date) slopes = abs(covxy / varx) colkill = where(slopes > t) mask = ma.make_mask_none(x.shape[1]) mask[colkill] = ones(mask[colkill].shape, dtype=bool) return mask
def mask(self): out = ma.make_mask_none(self.data.shape) for mask in self.masks: #(self.resmask, self.colmask, self.incmask, self.fitmask): out = ma.mask_or(out, mask) return out
def seqclean(x, t): contigs = np.apply_along_axis(longest_contig_max, 0, x) colkill = where(contigs >= t) mask = ma.make_mask_none(x.shape[1]) mask[:, colkill] = np.ones(mask[:, colkill].shape, dtype=bool) return mask