diff --git a/doc/user_guide/big_data.rst b/doc/user_guide/big_data.rst index 647391eb03..82fc09f91e 100644 --- a/doc/user_guide/big_data.rst +++ b/doc/user_guide/big_data.rst @@ -308,6 +308,7 @@ it is sometimes possible to manually set a more optimal chunking manually. There many operations take a ``rechunk`` or ``optimize`` keyword argument to disable automatic rechunking. +.. _lazy._repr_html_: For more recent versions of dask (dask>2021.11) when using hyperspy in a jupyter notebook a helpful html representation is available. .. code-block::python diff --git a/hyperspy/_signals/lazy.py b/hyperspy/_signals/lazy.py index 9a30481d85..aede87a46b 100644 --- a/hyperspy/_signals/lazy.py +++ b/hyperspy/_signals/lazy.py @@ -200,22 +200,22 @@ def _repr_html_(self): def _get_chunk_string(self): nav_chunks = self.data.chunksize[:len(self.axes_manager.navigation_shape)][::-1] string = "(" - for chunks,axis in zip(nav_chunks,self.axes_manager.navigation_shape): + for chunks, axis in zip(nav_chunks, self.axes_manager.navigation_shape): if chunks == axis: string += ""+str(chunks)+"," else: - string += str(chunks) +"," - string= string.rstrip(",") - string +="|" + string += str(chunks) + "," + string = string.rstrip(",") + string += "|" sig_chunks = self.data.chunksize[len(self.axes_manager.navigation_shape):][::-1] - for chunks,axis in zip(sig_chunks,self.axes_manager.signal_shape): + for chunks, axis in zip(sig_chunks, self.axes_manager.signal_shape): if chunks == axis: string += ""+str(chunks)+"," else: - string += str(chunks) +"," + string += str(chunks) + "," string = string.rstrip(",") - string +=")" + string += ")" return string def compute(self, close_file=False, show_progressbar=None, **kwargs): diff --git a/hyperspy/tests/signals/test_lazy.py b/hyperspy/tests/signals/test_lazy.py index c4e1120bb3..d73e8cc726 100644 --- a/hyperspy/tests/signals/test_lazy.py +++ b/hyperspy/tests/signals/test_lazy.py @@ -403,3 +403,18 @@ def test_html_rep_zero_dim_nav(self): def test_html_rep_zero_dim_sig(self): s = hs.signals.BaseSignal(da.random.random((500, 1000))).as_lazy().T s._repr_html_() + + def test_get_chunk_string(self): + s = hs.signals.BaseSignal(da.random.random((6, 6, 6, 6))).as_lazy() + s = s.transpose(2) + s.data = s.data.rechunk((3, 2, 6, 6)) + s_string = s._get_chunk_string() + assert (s_string == "(2,3|6,6)") + s.data = s.data.rechunk((6, 6, 2, 3)) + s_string = s._get_chunk_string() + assert (s_string == "(6,6|3,2)") + + def test_get_chunk_size(self): + sig = _signal() + s = sig.get_chunk_size() + assert s == ((2, 1, 3), (4, 5))