Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudnetpy/categorize/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cloudnetpy/cloudnetarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cloudnetpy/instruments/ceilometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions cloudnetpy/instruments/lufft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cloudnetpy/model_evaluation/tests/unit/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand 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)
Expand Down
2 changes: 1 addition & 1 deletion cloudnetpy/plotting/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion cloudnetpy/products/lwc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion cloudnetpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_concat_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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=[
[
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/test_falling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down