Skip to content

Commit

Permalink
Coverage of repr_html increased
Browse files Browse the repository at this point in the history
  • Loading branch information
CSSFrancis committed Jan 17, 2022
1 parent 4a50da5 commit e707707
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/user_guide/big_data.rst
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions hyperspy/_signals/lazy.py
Expand Up @@ -199,22 +199,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 += "<b>"+str(chunks)+"</b>,"
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 += "<b>"+str(chunks)+"</b>,"
else:
string += str(chunks) +","
string += str(chunks) + ","
string = string.rstrip(",")
string +=")"
string += ")"
return string

def compute(self, close_file=False, show_progressbar=None, **kwargs):
Expand Down
15 changes: 15 additions & 0 deletions hyperspy/tests/signals/test_lazy.py
Expand Up @@ -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|<b>6</b>,<b>6</b>)")
s.data = s.data.rechunk((6, 6, 2, 3))
s_string = s._get_chunk_string()
assert (s_string == "(<b>6</b>,<b>6</b>|3,2)")

def test_get_chunk_size(self):
sig = _signal()
s = sig.get_chunk_size()
assert s == ((2, 1, 3), (4, 5))

0 comments on commit e707707

Please sign in to comment.