Skip to content

Commit

Permalink
Increase codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
Attolight-NTappy committed Jun 25, 2024
1 parent c6587c9 commit d914fda
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
7 changes: 2 additions & 5 deletions rsciio/digitalsurf/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,17 +676,14 @@ 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):
self.Xaxis = next(
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]
Expand Down Expand Up @@ -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)
Expand Down
49 changes: 45 additions & 4 deletions rsciio/tests/test_digitalsurf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down Expand Up @@ -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",
Expand All @@ -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])
Expand Down

0 comments on commit d914fda

Please sign in to comment.