Skip to content

Commit

Permalink
Merge pull request #287 from ericpre/fix_sum_EDS_detectors_emd_velox
Browse files Browse the repository at this point in the history
EMD Velox: fix reading EDS stream detector lazily with `sum_EDS_detectors=True`
  • Loading branch information
ericpre authored Jul 10, 2024
2 parents 707d80a + 634db2f commit 5eca5bb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 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
21 changes: 21 additions & 0 deletions rsciio/tests/test_emd_velox.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,27 @@ 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))
@pytest.mark.parametrize("sum_frames", (False, True))
def test_fei_si_4detectors_compare(self, lazy, sum_frames):
fname = self.fei_files_path / "fei_SI_EDS-HAADF-4detectors_2frames.emd"
kwargs = dict(lazy=lazy, sum_frames=sum_frames)
s_sum_EDS = hs.load(fname, sum_EDS_detectors=True, **kwargs)[-1]
s = hs.load(fname, sum_EDS_detectors=False, **kwargs)[-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
14 changes: 7 additions & 7 deletions rsciio/utils/fei_stream_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ def stream_to_array(
dtype=dtype,
)

_fill_array_with_stream(
spectrum_image=spectrum_image,
stream=stream,
first_frame=first_frame,
last_frame=last_frame,
rebin_energy=rebin_energy,
)
_fill_array_with_stream(
spectrum_image=spectrum_image,
stream=stream,
first_frame=first_frame,
last_frame=last_frame,
rebin_energy=rebin_energy,
)
else:
if spectrum_image is None:
spectrum_image = np.zeros(
Expand Down
4 changes: 4 additions & 0 deletions upcoming_changes/287.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:ref:`EMD Velox <emd_fei-format>` fixes for reading files containing multiple EDS streams:

- fix reading multiple EDS streams lazily with ``sum_EDS_detectors=True``,
- fix reading separate EDS stream and individual frames when using ``sum_EDS_detectors=False`` and ``sum_frames=False``.

0 comments on commit 5eca5bb

Please sign in to comment.