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

EBSD signal axes not set correctly in the Bruker h5ebsd reader #346

Closed
hakonanes opened this issue Apr 23, 2021 · 9 comments · Fixed by #349
Closed

EBSD signal axes not set correctly in the Bruker h5ebsd reader #346

hakonanes opened this issue Apr 23, 2021 · 9 comments · Fixed by #349
Labels
bug Something isn't working
Milestone

Comments

@hakonanes
Copy link
Member

Issue reported by @Fred-Ad in #329 (I edited the post to just the relevant parts):

Hi Hakon,
I can load the dataset and produce the s.plot_virtual_bse_intensity(roi)
That's a good point, thanks !
However, there is an error when trying vbse_rgb_img = vbse_gen.get_rgb_image(r=red, g=green, b=blue)
this gives me this error :

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-18-7637d6229fcb> in <module>
----> 1 vbse_rgb_img = vbse_gen.get_rgb_image(r=red, g=green, b=blue)

D:\Python\WPy64-3880\python-3.8.8.amd64\lib\site-packages\kikuchipy\generators\virtual_bse_generator.py in get_rgb_image(self, r, g, b, percentiles, normalize, alpha, dtype_out, **kwargs)
    149             for roi in rois:
    150                 if isinstance(roi, tuple):
--> 151                     roi = self.roi_from_grid(roi)
    152                 roi_image = self.signal.get_virtual_bse_intensity(roi).data
    153                 if isinstance(roi_image, Array):

D:\Python\WPy64-3880\python-3.8.8.amd64\lib\site-packages\kikuchipy\generators\virtual_bse_generator.py in roi_from_grid(self, index)
    251         min_col = cols[min(index[:, 1])]
    252         max_col = cols[max(index[:, 1])] + cols[1]
--> 253         min_row = rows[min(index[:, 0])]
    254         max_row = rows[max(index[:, 0])] + rows[1]
    255 

IndexError: index 7 is out of bounds for axis 0 with size 6

Perhaps it si due to the count of columns and row, as

vbse_gen.grid_shape = (10, 10)
red = [(7, 1), (8, 1), (8, 2), (9, 1), (9, 2)]
green = [(8, 4), (8, 5), (9, 4), (9, 5)]
blue = [(7, 8), (8, 7), (8, 8), (9, 7), (9, 8)]
p = vbse_gen.plot_grid(
    rgb_channels=[red, green, blue],
    visible_indices=True,  # Default
    pattern_idx=(0, 0),  # Default is (0, 0)
)
p

gives the following image, with a problem with the squares coordinates. I tried with the Ni datadat, no problem. So it is only due to the hdf5 Bruker file.

Figure_epTest-coeur_Scan_1_Signal

Sorry to bother you. Hope this is not a big deal.

Regards
Fred

Originally posted by @Fred-Ad in #329 (reply in thread)

@hakonanes hakonanes added the bug Something isn't working label Apr 23, 2021
@hakonanes hakonanes added this to the v0.4.0 milestone Apr 23, 2021
@hakonanes
Copy link
Member Author

The scalebar and the number grid tile index positions (all crammed in the upper left) in the image (thanks for including this!) tells me that the signal axes are not calibrated correctly. Will look at this some more in the next couple of days and see if the error lies there.

@hakonanes
Copy link
Member Author

The signal axes scale aren't set correctly in the Bruker h5ebsd reader.

@Fred-Ad, could you try setting the scale manually?

# Load data and define roi
>>> s.axes_manager["dx"].scale = 1
>>> s.axes_manager["dy"].scale = 1
>>> s.plot_virtual_bse_intensity(roi)

@Fred-Ad
Copy link

Fred-Ad commented Apr 27, 2021

@hakonanes , it gives me this error :

ERROR:traits:Exception occurred in traits notification handler for object: dx axis, trait: scale, old value: 158.0, new value: 1.0
Traceback (most recent call last):
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 524, in _dispatch_change_event
    self.dispatch(handler, *args)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 486, in dispatch
    handler(*args)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/axes.py", line 1050, in _on_scale_changed
    self.events.any_axis_changed.trigger(obj=self)
  File "<string>", line 4, in trigger
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/events.py", line 422, in trigger
    function(**{kw: kwargs.get(kw, None) for kw in kwsl})
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py", line 300, in update
    self.events.changed.trigger(self)
  File "<string>", line 4, in trigger
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/events.py", line 422, in trigger
    function(**{kw: kwargs.get(kw, None) for kw in kwsl})
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/interactive.py", line 128, in update
    self.f(*self.args, out=self.out, **self.kwargs)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py", line 182, in __call__
    slices = self._make_slices(natax, axes)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py", line 132, in _make_slices
    ilow = ax.value2index(ranges[i][0])
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/axes.py", line 544, in value2index
    raise ValueError("The value is out of the axis limits")
ValueError: The value is out of the axis limits
ERROR:traits:Exception occurred in traits notification handler for object: dy axis, trait: scale, old value: 158.0, new value: 1.0
Traceback (most recent call last):
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 524, in _dispatch_change_event
    self.dispatch(handler, *args)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 486, in dispatch
    handler(*args)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/axes.py", line 1050, in _on_scale_changed
    self.events.any_axis_changed.trigger(obj=self)
  File "<string>", line 4, in trigger
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/events.py", line 422, in trigger
    function(**{kw: kwargs.get(kw, None) for kw in kwsl})
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py", line 300, in update
    self.events.changed.trigger(self)
  File "<string>", line 4, in trigger
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/events.py", line 422, in trigger
    function(**{kw: kwargs.get(kw, None) for kw in kwsl})
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/interactive.py", line 128, in update
    self.f(*self.args, out=self.out, **self.kwargs)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py", line 182, in __call__
    slices = self._make_slices(natax, axes)
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py", line 132, in _make_slices
    ilow = ax.value2index(ranges[i][0])
  File "/home/deuf/anaconda3/lib/python3.8/site-packages/hyperspy/axes.py", line 544, in value2index
    raise ValueError("The value is out of the axis limits")
ValueError: The value is out of the axis limits
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-07b6c9964e86> in <module>
      1 s.axes_manager["dx"].scale = 1
      2 s.axes_manager["dy"].scale = 1
----> 3 s.plot_virtual_bse_intensity(roi)

~/anaconda3/lib/python3.8/site-packages/kikuchipy/signals/ebsd.py in plot_virtual_bse_intensity(self, roi, out_signal_axes, **kwargs)
   1420 
   1421         # Get the sliced signal from the ROI
-> 1422         sliced_signal = roi.interactive(
   1423             self, axes=self.axes_manager.signal_axes
   1424         )

~/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py in interactive(self, signal, navigation_signal, out, color, snap, **kwargs)
    390                 [])
    391         if out is None:
--> 392             return interactive(self.__call__,
    393                                event=self.events.changed,
    394                                signal=signal,

~/anaconda3/lib/python3.8/site-packages/hyperspy/interactive.py in interactive(f, event, recompute_out_event, *args, **kwargs)
    130 
    131 def interactive(f, event="auto", recompute_out_event="auto", *args, **kwargs):
--> 132     cls = Interactive(f, event, recompute_out_event, *args, **kwargs)
    133     return cls.out
    134 

~/anaconda3/lib/python3.8/site-packages/hyperspy/interactive.py in __init__(self, f, event, recompute_out_event, *args, **kwargs)
     79             self.out = self.kwargs.pop('out')
     80         else:
---> 81             self.out = self.f(*self.args, **self.kwargs)
     82         # Reuse the `_plot_kwargs` for the roi if available
     83         if _plot_kwargs and 'signal' in self.kwargs:

~/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py in __call__(self, signal, out, axes)
    180 
    181         natax = signal.axes_manager._get_axes_in_natural_order()
--> 182         slices = self._make_slices(natax, axes)
    183         nav_axes = [ax.navigate for ax in axes]
    184         nav_dim = signal.axes_manager.navigation_dimension

~/anaconda3/lib/python3.8/site-packages/hyperspy/roi.py in _make_slices(self, axes_collection, axes, ranges)
    130                 i = axes.index(ax)
    131                 try:
--> 132                     ilow = ax.value2index(ranges[i][0])
    133                 except ValueError:
    134                     if ranges[i][0] < ax.low_value:

~/anaconda3/lib/python3.8/site-packages/hyperspy/axes.py in value2index(self, value, rounding)
    542                 return index
    543             else:
--> 544                 raise ValueError("The value is out of the axis limits")
    545 
    546     def index2value(self, index):

ValueError: The value is out of the axis limits

@hakonanes
Copy link
Member Author

Hm, thanks for trying it out, sorry it didn't work.

For some reason I cannot reproduce this on my side... Could you do me a favor and post the exact lines you're running, as well as the package versions you're running the code with (conda env list or pip freeze)?

@Fred-Ad
Copy link

Fred-Ad commented Apr 27, 2021

Strange... It didn't work on my archlinux config, but it worked on my windows (hyperspy bundle + kikuchipy and other things).

Thanks !!

I'll try to find the differences between the 2 configs.

Don't know if you consider it as resolved ?

@hakonanes
Copy link
Member Author

Ah, glad it worked there at least! I'm still interested in the configuration on your linux machine where this error was thrown, so yeah, would be nice if you could post that information.

Let's leave it open until we have solved the issue of the Bruker h5ebsd reader setting the wrong pixel size (EBSD.axes_manager["dx"].scale and EBSD.axes_manager["dy"].scale).

@Fred-Ad
Copy link

Fred-Ad commented Apr 27, 2021

That's okay. It worked after updating all my packages in archlinux ! Sorry to have worried you 😉

@hakonanes
Copy link
Member Author

@Fred-Ad, this should now be fixed in #349, and after that fix is released you should be able to read your data and start visualization directly, without setting the detector pixel sizes (axes manager scales) to 1. Thank you for reporting these issues! There were quite serious bugs resulting in this behaviour.

Don't know exactly when we should release the fix, but I think it is OK to wait for a v0.4 release in a month or so, so that we can get more bug fixes and functionality released along side it.

@Fred-Ad
Copy link

Fred-Ad commented Apr 30, 2021

Thanks a lot Hakon. For the moment that's okay for me, I can do what I need. I'll wait for the v0.4 iwth interest to discover all the new functionnality you'll bring.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants