Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for lazy loading DPC and FFT #2651

Merged
merged 3 commits into from
Mar 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RELEASE_next_patch (Unreleased)
* Use dask chunking when saving lazy signal instead of rechunking and leave the user to decide what is the suitable chunking (`#2629 <https://github.com/hyperspy/hyperspy/pull/2629>`_)
* Fix incorrect chunksize when saving EMD NCEM file and specifying chunks (`#2629 <https://github.com/hyperspy/hyperspy/pull/2629>`_)
* Fix ``find_peaks`` GUIs call with laplacian/difference of gaussian methods (`#2622 <https://github.com/hyperspy/hyperspy/issues/2622>`_ and `#2647 <https://github.com/hyperspy/hyperspy/pull/2647>`_)
* Added lazy reading support for FFT and DPC datasets in FEI emd datasets (`#2651 <https://github.com/hyperspy/hyperspy/pull/2651>`_).


Changelog
Expand Down
6 changes: 2 additions & 4 deletions doc/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,11 @@ the data size in memory.

FFTs made in Velox are loaded in as-is as a HyperSpy ComplexSignal2D object.
The FFT is not centered and only positive frequencies are stored in the file.
Lazy reading of these datasets is not supported. Making FFTs with HyperSpy
from the respective image datasets is recommended.
Making FFTs with HyperSpy from the respective image datasets is recommended.

.. note::

DPC data is loaded in as a HyperSpy ComplexSignal2D object. Lazy reading of these
datasets is not supported.
DPC data is loaded in as a HyperSpy ComplexSignal2D object.

.. note::

Expand Down
17 changes: 10 additions & 7 deletions hyperspy/io_plugins/emd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,15 +1092,18 @@ def _read_image(self, image_group, image_sub_group_key):
('imagFloat', '<f4')]
if h5data.dtype == fft_dtype or h5data.dtype == dpc_dtype:
_logger.debug("Found an FFT or DPC, loading as Complex2DSignal")
if self.lazy:
_logger.warning("Lazy not supported for FFT or DPC")
data = np.empty(h5data.shape, h5data.dtype)
h5data.read_direct(data)
real = h5data.dtype.descr[0][0]
imag = h5data.dtype.descr[1][0]
data = data[real] + 1j * data[imag]
# Set the axes in frame, y, x order
data = np.rollaxis(data, axis=2)
if self.lazy:
data = da.from_array(h5data, chunks=h5data.chunks)
data = data[real] + 1j * data[imag]
data = da.transpose(data, axes=[2, 0, 1])
else:
data = np.empty(h5data.shape, h5data.dtype)
h5data.read_direct(data)
data = data[real] + 1j * data[imag]
# Set the axes in frame, y, x order
data = np.rollaxis(data, axis=2)
else:
if self.lazy:
data = da.transpose(
Expand Down
3 changes: 3 additions & 0 deletions hyperspy/tests/io/test_emd.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,9 @@ def test_fei_complex_loading():
signal = load(os.path.join(my_path, 'emd_files', 'fei_example_complex_fft.emd'))
assert isinstance(signal, ComplexSignal2D)

def test_fei_complex_loading_lazy():
signal = load(os.path.join(my_path, 'emd_files', 'fei_example_complex_fft.emd'), lazy=True)
assert isinstance(signal, ComplexSignal2D)

def test_fei_no_frametime():
signal = load(os.path.join(my_path, 'emd_files', 'fei_example_tem_stack.emd'))
Expand Down