diff --git a/cloudnetpy/categorize/containers.py b/cloudnetpy/categorize/containers.py index 5ac98fe9..1631036b 100644 --- a/cloudnetpy/categorize/containers.py +++ b/cloudnetpy/categorize/containers.py @@ -163,6 +163,6 @@ def _find_clutter( """ is_clutter = np.zeros(v.shape, dtype=bool) filled = False - tiny_velocity = (np.abs(v[:, :n_gates]) < v_lim).filled(filled) + tiny_velocity = ma.less(ma.abs(v[:, :n_gates]), v_lim).filled(filled) is_clutter[:, :n_gates] = tiny_velocity * utils.transpose(~is_rain) return is_clutter diff --git a/cloudnetpy/cloudnetarray.py b/cloudnetpy/cloudnetarray.py index 98629440..b45d6004 100644 --- a/cloudnetpy/cloudnetarray.py +++ b/cloudnetpy/cloudnetarray.py @@ -111,7 +111,7 @@ def filter_vertical_stripes(self) -> None: def _filter(self, fun: Callable[[npt.NDArray], npt.NDArray]) -> None: if not isinstance(self.data, ma.MaskedArray): - self.data = ma.masked_array(self.data) + self.data = ma.array(self.data) is_data = (~self.data.mask).astype(int) is_data_filtered = fun(is_data) self.data[is_data_filtered == 0] = ma.masked diff --git a/cloudnetpy/instruments/ceilometer.py b/cloudnetpy/instruments/ceilometer.py index f833af0f..60de970b 100644 --- a/cloudnetpy/instruments/ceilometer.py +++ b/cloudnetpy/instruments/ceilometer.py @@ -273,7 +273,7 @@ def _remove_noise( ind = self._get_altitude_ind() snr[:, ind] *= snr_scale_factor if ma.isMaskedArray(array) is False: - array = ma.masked_array(array) + array = ma.array(array) if keep_negative is True: array[np.abs(snr) < snr_limit] = ma.masked else: diff --git a/cloudnetpy/instruments/lufft.py b/cloudnetpy/instruments/lufft.py index 85231661..8007d1b2 100644 --- a/cloudnetpy/instruments/lufft.py +++ b/cloudnetpy/instruments/lufft.py @@ -43,7 +43,7 @@ def _fetch_beta_raw(self, calibration_factor: float | None = None) -> None: logging.warning("Using default calibration factor") calibration_factor = 3e-12 beta_raw = self._getvar("beta_raw", "beta_att") - beta_raw = ma.masked_array(beta_raw) + beta_raw = ma.array(beta_raw) old_version = self._get_old_software_version() if old_version is not None: self.is_old_version = True @@ -53,7 +53,7 @@ def _fetch_beta_raw(self, calibration_factor: float | None = None) -> None: ) data_std = self._getvar("stddev") normalised_apd = self._get_nn() - beta_raw *= utils.transpose(ma.masked_array(data_std / normalised_apd)) + beta_raw *= utils.transpose(ma.array(data_std / normalised_apd)) beta_raw *= self.data["range"] ** 2 beta_raw *= calibration_factor self.data["calibration_factor"] = float(calibration_factor) diff --git a/cloudnetpy/model_evaluation/tests/unit/test_tools.py b/cloudnetpy/model_evaluation/tests/unit/test_tools.py index 4040c76c..9226d148 100644 --- a/cloudnetpy/model_evaluation/tests/unit/test_tools.py +++ b/cloudnetpy/model_evaluation/tests/unit/test_tools.py @@ -37,7 +37,7 @@ def test_calculate_advection_time_hour(model_file) -> None: expected = resolution * 1000 / wind / 60**2 expected[expected > 1 / sampling] = 1 / sampling expected = np.asarray([[timedelta(hours=float(t)) for t in tt] for tt in expected]) - result = tools.calculate_advection_time(resolution, ma.masked_array(wind), sampling) + result = tools.calculate_advection_time(resolution, ma.array(wind), sampling) assert result.all() == expected.all() @@ -49,14 +49,14 @@ def test_calculate_advection_time_10min(model_file) -> None: expected = resolution * 1000 / wind / 60**2 expected[expected > 1 / sampling] = 1 / sampling expected = np.asarray([[timedelta(hours=float(t)) for t in tt] for tt in expected]) - result = tools.calculate_advection_time(resolution, ma.masked_array(wind), sampling) + result = tools.calculate_advection_time(resolution, ma.array(wind), sampling) assert result.all() == expected.all() def test_calculate_advection_time_fractional_resolution() -> None: # A sub-kilometre / fractional resolution must not be truncated to int. resolution = 0.5 - wind = ma.masked_array([[2.0]]) + wind = ma.array([[2.0]]) sampling = 6 result = tools.calculate_advection_time(resolution, wind, sampling) expected = timedelta(hours=resolution * 1000 / 2.0 / 60**2) diff --git a/cloudnetpy/plotting/plotting.py b/cloudnetpy/plotting/plotting.py index 15caaa97..32c91e62 100644 --- a/cloudnetpy/plotting/plotting.py +++ b/cloudnetpy/plotting/plotting.py @@ -671,7 +671,7 @@ def _indicate_rainy_profiles(self, figure_data: FigureData) -> None: if "rain_detected" not in figure_data.file.variables: return rain = figure_data.file.variables["rain_detected"][:] - is_rain: ma.MaskedArray = ma.masked_array(np.zeros_like(rain), mask=(rain == 0)) + is_rain: ma.MaskedArray = ma.array(np.zeros_like(rain), mask=(rain == 0)) if is_rain.mask.all(): return self._ax.plot( diff --git a/cloudnetpy/products/lwc.py b/cloudnetpy/products/lwc.py index e7327ac0..80de7fc6 100644 --- a/cloudnetpy/products/lwc.py +++ b/cloudnetpy/products/lwc.py @@ -344,7 +344,7 @@ def _calc_lwc_relative_error(self) -> npt.NDArray: def _calc_lwc_gradient(self) -> npt.NDArray: if not isinstance(self.lwc, ma.MaskedArray): - self.lwc = ma.masked_array(self.lwc) + self.lwc = ma.array(self.lwc) gradient_elements = np.gradient(self.lwc.filled(0)) return utils.l2norm(*gradient_elements) diff --git a/cloudnetpy/utils.py b/cloudnetpy/utils.py index 8e1b43f4..c1a5dc6c 100644 --- a/cloudnetpy/utils.py +++ b/cloudnetpy/utils.py @@ -146,7 +146,7 @@ def rebin_2d( stat_fn = REBIN_STAT_FN[statistic] shape = array.shape if keepdim else (n_bins, array.shape[1]) - result: ma.MaskedArray = ma.masked_array(np.ones(shape, dtype="float32"), mask=True) + result: ma.MaskedArray = ma.array(np.ones(shape, dtype="float32"), mask=True) for bin_ind in range(n_bins): if counts[bin_ind] < n_min: diff --git a/tests/unit/test_concat_lib.py b/tests/unit/test_concat_lib.py index 4cc94b89..fd4950d1 100644 --- a/tests/unit/test_concat_lib.py +++ b/tests/unit/test_concat_lib.py @@ -210,24 +210,24 @@ def test_consistent_masked_arrays(self): self._write_array( self.file1, "kissa", - ma.masked_array([1, 2, 3], mask=[True, False, True]), + ma.array([1, 2, 3], mask=[True, False, True]), ) self._write_array( self.file2, "kissa", - ma.masked_array([3, 2, 1], mask=[True, False, True]), + ma.array([3, 2, 1], mask=[True, False, True]), ) with concat_lib._Concat(self.files, str(self.output)) as concat: concat.concat_data() assert ma.allequal( concat.concatenated_file["kissa"][:], - ma.masked_array([1, 2, 3], mask=[True, False, True]), + ma.array([1, 2, 3], mask=[True, False, True]), ) def test_inconsistent_masked_arrays(self): - arr1: npt.NDArray = ma.masked_array([1, 2, 3], mask=[True, False, True]) - arr2: npt.NDArray = ma.masked_array([3, 2, 1], mask=[True, False, True]) + arr1: npt.NDArray = ma.array([1, 2, 3], mask=[True, False, True]) + arr2: npt.NDArray = ma.array([3, 2, 1], mask=[True, False, True]) self._write_array( self.file1, "kissa", diff --git a/tests/unit/test_droplet.py b/tests/unit/test_droplet.py index d4e2e4ca..306f7c5a 100644 --- a/tests/unit/test_droplet.py +++ b/tests/unit/test_droplet.py @@ -8,7 +8,7 @@ class TestIndBase: x = ma.array([0, 0.5, 1, -99, 4, 8, 5]) - mx: ma.MaskedArray = ma.masked_array( + mx: ma.MaskedArray = ma.array( x, mask=[False, False, False, True, False, False, False] ) diffu = np.diff(mx) @@ -61,7 +61,7 @@ def test_ind_base_3(self): ) def test_ind_base_4(self): - mx: ma.MaskedArray = ma.masked_array( + mx: ma.MaskedArray = ma.array( self.x, mask=[True, False, True, True, True, False, False] ) diffu = ma.diff(mx) @@ -73,7 +73,7 @@ def test_ind_base_4(self): class TestIndTop: x = np.array([1, 3, 8, 4, -99, 1, 0.5, 0]) - mx: ma.MaskedArray = ma.masked_array( + mx: ma.MaskedArray = ma.array( x, mask=[False, False, False, False, True, False, False, False] ) diffu = np.diff(mx) @@ -136,7 +136,7 @@ def test_ind_top_3(self): ) def test_ind_top_4(self): - mx: ma.MaskedArray = ma.masked_array( + mx: ma.MaskedArray = ma.array( self.x, mask=[True, False, True, False, True, False, True, False] ) diffu = ma.diff(mx) @@ -203,7 +203,7 @@ def test_correct_liquid_top(): class Obs: def __init__(self): self.height = np.arange(11) - self.z: ma.MaskedArray = ma.masked_array( + self.z: ma.MaskedArray = ma.array( np.random.random((3, 10)), mask=[ [ diff --git a/tests/unit/test_falling.py b/tests/unit/test_falling.py index eb858594..4c2fd6f3 100644 --- a/tests/unit/test_falling.py +++ b/tests/unit/test_falling.py @@ -55,11 +55,11 @@ def test_find_cold_aerosols(): @pytest.mark.parametrize( "z, ind_top, result", [ - (ma.masked_array([1, 1, 1, 1], mask=[False, False, False, False]), 2, False), - (ma.masked_array([1, 1, 1, 1], mask=[False, False, False, False]), 2, False), - (ma.masked_array([1, 1, 1, 1], mask=[False, False, False, False]), 3, False), - (ma.masked_array([1, 1, 1, 1], mask=[True, True, True, True]), 3, False), - (ma.masked_array([1, 1, 1, 1], mask=[False, False, False, True]), 2, True), + (ma.array([1, 1, 1, 1], mask=[False, False, False, False]), 2, False), + (ma.array([1, 1, 1, 1], mask=[False, False, False, False]), 2, False), + (ma.array([1, 1, 1, 1], mask=[False, False, False, False]), 3, False), + (ma.array([1, 1, 1, 1], mask=[True, True, True, True]), 3, False), + (ma.array([1, 1, 1, 1], mask=[False, False, False, True]), 2, True), ], ) def test_is_z_missing_above_liquid(z, ind_top, result): @@ -69,11 +69,11 @@ def test_is_z_missing_above_liquid(z, ind_top, result): @pytest.mark.parametrize( "z, ind_base, ind_top, result", [ - (ma.masked_array([1, 1, 1, 1], mask=[False, False, False, False]), 1, 2, False), - (ma.masked_array([1, 1, 2, 1], mask=[False, False, False, False]), 1, 2, True), - (ma.masked_array([1, 2, 1, 1], mask=[False, False, False, False]), 1, 2, False), - (ma.masked_array([1, 1, 2, 3], mask=[False, False, True, False]), 1, 3, True), - (ma.masked_array([1, 2, 3, 4], mask=[False, True, True, True]), 1, 3, False), + (ma.array([1, 1, 1, 1], mask=[False, False, False, False]), 1, 2, False), + (ma.array([1, 1, 2, 1], mask=[False, False, False, False]), 1, 2, True), + (ma.array([1, 2, 1, 1], mask=[False, False, False, False]), 1, 2, False), + (ma.array([1, 1, 2, 3], mask=[False, False, True, False]), 1, 3, True), + (ma.array([1, 2, 3, 4], mask=[False, True, True, True]), 1, 3, False), ], ) def test_is_z_increasing(z, ind_top, ind_base, result):