def rebin_data(self, time: np.ndarray, time_new: np.ndarray) -> list: """Rebins `data` in time. Args: time: 1D time array. time_new: 1D new time array. Returns: Time indices without data. """ if self.data.ndim == 1: self.data = utils.rebin_1d(time, self.data, time_new) bad_indices = list(np.where(self.data == ma.masked)[0]) else: assert isinstance(self.data, ma.MaskedArray) self.data, bad_indices = utils.rebin_2d(time, self.data, time_new) return bad_indices
def rebin_data(self, time: np.ndarray, time_new: np.ndarray, height: Optional[np.ndarray] = None, height_new: Optional[np.ndarray] = None) -> None: """Rebins `data` in time and optionally interpolates in height. Args: time: 1D time array. time_new: 1D new time array. height: 1D height array. height_new: 1D new height array. Should be given if also `height` is given. """ if self.data.ndim == 1: self.data = utils.rebin_1d(time, self.data.astype(float), time_new) else: self.data = utils.rebin_2d(time, self.data, time_new) if height is not None and height_new is not None: self.data = utils.interpolate_2d_mask(time_new, height, self.data, time_new, height_new)
def test_rebin_1d_std(self): data_i = utils.rebin_1d(self.x, self.data, self.xnew, 'std') result = np.array([np.std([1, 2, 3]), np.std([4, 5]), np.std([6, 7])]) assert_array_almost_equal(data_i, result)
def test_rebin_1d(self): data_i = utils.rebin_1d(self.x, self.data, self.xnew) result = np.array([2, 4.5, 6.5]) assert_array_almost_equal(data_i, result)