pyxem / kikuchipy

Toolbox for analysis of electron backscatter diffraction (EBSD) patterns
https://kikuchipy.org
GNU General Public License v3.0
80 stars 30 forks source link

Thin or bin data set along navigation axes (fewer patterns but same ROI) #71

Closed hakonanes closed 4 years ago

hakonanes commented 5 years ago

Is your feature request related to a problem? Please describe. A convenience method to bin data along the navigation axes, i.e. removing e.g. every other pattern along x and y, would be nice to have when e.g. a data set is large.

Describe the solution you'd like A method called perhaps thin() or trim() should accept parameters called perhaps xstep and ystep stating which patterns to remove (e.g. xstep=2 removes every other pattern from the x-direction). The distance between each pattern must be the same for all patterns in each direction. Step sizes in axes_manager must of course be updated.

Describe alternatives you've considered This should work

import numpy as np
original = np.arange(25).reshape(5, 5)
xstep = 2
ystep = 2
thinned = original[::ystep, ::xstep]

I am not sure what is the most cost effective way in terms of memory and speed.

hakonanes commented 5 years ago

This could either be done by averaging or dropping patterns from the data (as an input parameter to the user).

hakonanes commented 5 years ago

So HyperSpy's rebin functionality does this for both signal and navigation axes, but it e.g. casts results to uint64 and does not overwrite original data using dask.array.store(). It would be ideal to be able to bin either signal or navigation axes with the rebin() method without casting to uint64 and overwrite results using dask.array.store(), directly using dask arrays. This might need dask.array.map_overlap() when wanting to average patterns for binning navigation axes.

hakonanes commented 4 years ago

Using HyperSpy's rebin() method, although casting to uint64 and not operating using dask.array.store(), is powerful and general, so for now our own rebin() method uses HyperSpy's.

Using s.inav[::2, ::2] works nicely. This will be included in the documentation where navigation and signal axes manipulation is explained.