示例#1
0
 def test_rebin_2d_n_min(self):
     data_i, empty_ind = utils.rebin_2d(self.x,
                                        self.data,
                                        self.xnew,
                                        n_min=2)
     expected_data = np.array([[2, 4.5, 6.5], [2, 4.5, 6.5]]).T
     assert_array_almost_equal(data_i.data, expected_data)
     assert empty_ind == []
示例#2
0
 def test_rebin_2d_n_min_2(self):
     data_i, empty_ind = utils.rebin_2d(self.x,
                                        self.data,
                                        self.xnew,
                                        n_min=3)
     expected_data = np.array([[2, 4.5, 6.5], [2, 4.5, 6.5]]).T
     expected_mask = np.array([[0, 1, 1], [0, 1, 1]]).T
     assert_array_almost_equal(data_i.data, expected_data)
     assert_array_almost_equal(data_i.mask, expected_mask)  # pylint: disable=E1101
     assert empty_ind == [1, 2]
示例#3
0
    def rebin_velocity(
        self,
        time: np.ndarray,
        time_new: np.ndarray,
        folding_velocity: Union[float, np.ndarray],
        sequence_indices: list,
    ) -> None:
        """Rebins Doppler velocity in polar coordinates.

        Args:
            time: 1D time array.
            time_new: 1D new time array.
            folding_velocity: Folding velocity (m/s). Can be float when it's the same for all
                altitudes, or np.ndarray when it matches difference altitude regions
                (defined in `sequence_indices`).
            sequence_indices: List containing indices of different folding regions,
                e.g. [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10]].

        """

        def _get_scaled_vfold() -> np.ndarray:
            vfold_scaled = math.pi / folding_velocity
            if isinstance(vfold_scaled, float):
                vfold_scaled = np.array([float(vfold_scaled)])
            return vfold_scaled

        def _scale_by_vfold(data_in: np.ndarray, fun) -> np.ndarray:
            data_out = ma.copy(data_in)
            for i, ind in enumerate(sequence_indices):
                data_out[:, ind] = fun(data_in[:, ind], folding_velocity_scaled[i])
            return data_out

        folding_velocity_scaled = _get_scaled_vfold()
        data_scaled = _scale_by_vfold(self.data, np.multiply)
        vel_x = ma.cos(data_scaled)
        vel_y = ma.sin(data_scaled)
        vel_x_mean, _ = utils.rebin_2d(time, vel_x, time_new)
        vel_y_mean, _ = utils.rebin_2d(time, vel_y, time_new)
        mean_vel_scaled = np.arctan2(vel_y_mean, vel_x_mean)
        self.data = _scale_by_vfold(mean_vel_scaled, np.divide)
示例#4
0
    def calc_linear_std(self, time: np.ndarray, time_new: np.ndarray) -> None:
        """Calculates std of radar velocity.

        Args:
            time: 1D time array.
            time_new: 1D new time array.

        Notes:
            The result is masked if the bin contains masked values.
        """
        data_as_float = self.data.astype(float)
        assert isinstance(data_as_float, ma.MaskedArray)
        self.data, _ = utils.rebin_2d(time, data_as_float, time_new, "std")
示例#5
0
    def calc_linear_std(self, time: np.ndarray, time_new: np.ndarray) -> None:
        """Calculates std of radar velocity.

        Args:
            time: 1D time array.
            time_new: 1D new time array.

        Notes:
            The result is masked if the bin contains masked values.

        """
        self.data = utils.rebin_2d(time, self.data.astype(float), time_new,
                                   'std')
示例#6
0
    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
示例#7
0
    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)
示例#8
0
 def test_rebin_2d_std(self):
     data_i = utils.rebin_2d(self.x, self.data, self.xnew, 'std')
     result = np.array([np.std([1, 2, 3]), np.std([4, 5]), np.std([6, 7])])
     result = np.array([result, result]).T
     assert_array_almost_equal(data_i, result)
示例#9
0
 def test_rebin_2d_n_min_2(self):
     data_i = utils.rebin_2d(self.x, self.data, self.xnew, n_min=3)
     result = np.array([False, True, True])
     result = np.array([result, result]).T
     assert_array_almost_equal(data_i.mask, result)
示例#10
0
 def test_rebin_2d_n_min(self):
     data_i = utils.rebin_2d(self.x, self.data, self.xnew, n_min=2)
     result = np.array([2, 4.5, 6.5])
     result = np.array([result, result]).T
     assert_array_almost_equal(data_i, result)
示例#11
0
 def test_rebin_2d(self):
     data_i = utils.rebin_2d(self.x, self.data, self.xnew)
     result = np.array([[2, 4.5, 6.5], [2, 4.5, 6.5]]).T
     assert_array_almost_equal(data_i, result)
示例#12
0
 def test_rebin_2d(self):
     data_i, empty_ind = utils.rebin_2d(self.x, self.data, self.xnew)
     expected_data = np.array([[2, 4.5, 6.5], [2, 4.5, 6.5]]).T
     assert_array_almost_equal(data_i.data, expected_data)
     assert bool(data_i.mask) is False  # pylint: disable=E1101
     assert empty_ind == []