From d914fda926ef0a7e1f7374b08d2d4a88b88d0827 Mon Sep 17 00:00:00 2001 From: Nicolas Tappy Date: Tue, 25 Jun 2024 11:06:44 +0200 Subject: [PATCH] Increase codecov --- rsciio/digitalsurf/_api.py | 7 ++--- rsciio/tests/test_digitalsurf.py | 49 +++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/rsciio/digitalsurf/_api.py b/rsciio/digitalsurf/_api.py index 0930c9da..718c5db9 100644 --- a/rsciio/digitalsurf/_api.py +++ b/rsciio/digitalsurf/_api.py @@ -676,6 +676,7 @@ def _split_spectrum( nax_nav = self._n_ax_nav nax_sig = self._n_ax_sig + # _split_signal_dict ensures that the correct dims are sent here. if (nax_nav, nax_sig) == (0, 1) or (nax_nav, nax_sig) == (1, 0): self.Xaxis = self.signal_dict["axes"][0] elif (nax_nav, nax_sig) == (1, 1): @@ -683,10 +684,6 @@ def _split_spectrum( ax for ax in self.signal_dict["axes"] if not ax["navigate"] ) self.Yaxis = next(ax for ax in self.signal_dict["axes"] if ax["navigate"]) - else: - raise MountainsMapFileError( - f"Dimensions ({nax_nav})|{nax_sig}) invalid for export as spectrum type" - ) self.data_split = [self.signal_dict["data"]] self.objtype_split = [obj_type] @@ -2281,7 +2278,7 @@ def _unpack_data(self, file, encoding="latin-1"): # Packing data into ints or float, with or without scaling. if self._is_data_int(): - _points = _points + pass #Case left here for future modification elif self._is_data_scaleint(): _points = (_points.astype(float) - Zmin) * scale + offset _points = np.round(_points).astype(int) diff --git a/rsciio/tests/test_digitalsurf.py b/rsciio/tests/test_digitalsurf.py index 9fdafcdd..43655966 100644 --- a/rsciio/tests/test_digitalsurf.py +++ b/rsciio/tests/test_digitalsurf.py @@ -675,17 +675,24 @@ def test_norm_int_data(dtype, special, fullscale): assert Zmin == off assert Zmax == maxval - -def test_writeRGB(tmp_path): +@pytest.mark.parametrize("transpose", [True, False]) +def test_writetestobjects_rgb(tmp_path,transpose): # This is just a different test function because the # comparison of rgb data must be done differently # (due to hyperspy underlying structure) df = TEST_DATA_PATH.joinpath("test_RGB.sur") d = hs.load(df) fn = tmp_path.joinpath("test_RGB.sur") - d.save(fn, is_special=False) + + if transpose: + d = d.T + with pytest.warns(): + d.save(fn) + else: + d.save(fn) + d2 = hs.load(fn) - d2.save(fn, is_special=False) + d2.save(fn) d3 = hs.load(fn) for k in ["R", "G", "B"]: @@ -723,6 +730,35 @@ def test_writegeneric_validtypes(tmp_path, dtype, compressed): gen2 = hs.load(fgen) assert np.allclose(gen2.data, gen.data) +@pytest.mark.parametrize("compressed", [True, False]) +def test_writegeneric_nans(tmp_path, compressed): + """This test establishes the capability of saving a generic signal + generated from numpy array containing floats""" + gen = hs.signals.Signal1D(np.random.random(size=301)) + + gen.data[66] = np.nan + gen.data[111] = np.nan + + fgen = tmp_path.joinpath("test.pro") + + gen.save(fgen, compressed=compressed, is_special=True, overwrite=True) + + gen2 = hs.load(fgen) + assert np.allclose(gen2.data, gen.data, equal_nan=True) + +def test_writegeneric_transposedprofile(tmp_path): + """This test checks the expected behaviour that a transposed profile gets + correctly saved but a warning is raised.""" + gen = hs.signals.Signal1D(np.random.random(size=99)) + gen = gen.T + + fgen = tmp_path.joinpath("test.pro") + + with pytest.warns(): + gen.save(fgen, overwrite=True) + + gen2 = hs.load(fgen) + assert np.allclose(gen2.data, gen.data) @pytest.mark.parametrize( "dtype", @@ -738,6 +774,11 @@ def test_writegeneric_failingtypes(tmp_path, dtype): with pytest.raises(MountainsMapFileError): gen.save(fgen, overwrite=True) +def test_writegeneric_failingformat(tmp_path): + gen = hs.signals.Signal1D(np.zeros((3,4,5,6))) + fgen = tmp_path.joinpath("test.sur") + with pytest.raises(MountainsMapFileError): + gen.save(fgen, overwrite=True) @pytest.mark.parametrize("dtype", [(np.uint8, "rgba8"), (np.uint16, "rgba16")]) @pytest.mark.parametrize("compressed", [True, False])