Skip to content

Commit

Permalink
EMD Velox: fix reading EDS stream detector lazily with `sum_EDS_detec…
Browse files Browse the repository at this point in the history
…tors=True`. When summing the stream, the same stream was used several times
  • Loading branch information
ericpre committed Jun 28, 2024
1 parent e9ff520 commit 0a8f446
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 2 additions & 3 deletions rsciio/emd/_emd_velox.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ def stream_to_sparse_array(self, stream_data):
"""
# Here we load the stream data into memory, which is fine is the
# arrays are small. We could load them lazily when lazy.
stream_data = self.stream_group["Data"][:].T[0]
sparse_array = stream_readers.stream_to_sparse_COO_array(
stream_data=stream_data,
spatial_shape=self.reader.spatial_shape,
Expand All @@ -967,8 +966,8 @@ def stream_to_array(self, stream_data, spectrum_image=None):
Parameters
----------
stream_data: array
spectrum_image: array or None
stream_data : numpy.ndarray
spectrum_image : numpy.ndarray or None
If array, the data from the stream are added to the array.
Otherwise it creates a new array and returns it.
Expand Down
19 changes: 19 additions & 0 deletions rsciio/tests/test_emd_velox.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,25 @@ def test_fei_si_4detectors(self, lazy, sum_EDS_detectors):
assert len(signal) == length
# TODO: add parsing azimuth_angle

@pytest.mark.parametrize("lazy", (False, True))
def test_fei_si_4detectors_compare(self, lazy):
fname = self.fei_files_path / "fei_SI_EDS-HAADF-4detectors_2frames.emd"
s_sum_EDS = hs.load(fname, sum_EDS_detectors=True, lazy=lazy)[-1]
s = hs.load(fname, sum_EDS_detectors=False, lazy=lazy)[-4:]
if lazy:
s_sum_EDS.compute()
for s_ in s:
s_.compute()

s2 = hs.stack(s, new_axis_name="detector").sum("detector")

np.testing.assert_allclose(s[-1].data.sum(), 865236)
np.testing.assert_allclose(s[-2].data.sum(), 913682)
np.testing.assert_allclose(s[-3].data.sum(), 867647)
np.testing.assert_allclose(s[-4].data.sum(), 916174)
np.testing.assert_allclose(s2.data.sum(), 3562739)
np.testing.assert_allclose(s2.data, s_sum_EDS.data)

def test_fei_emd_ceta_camera(self):
signal = hs.load(self.fei_files_path / "1532 Camera Ceta.emd")
np.testing.assert_allclose(signal.data, np.zeros((64, 64)))
Expand Down

0 comments on commit 0a8f446

Please sign in to comment.