Skip to content

Commit

Permalink
Merge 978a406 into c810bf1
Browse files Browse the repository at this point in the history
  • Loading branch information
hakonanes committed Sep 23, 2019
2 parents c810bf1 + 978a406 commit 971699a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
26 changes: 13 additions & 13 deletions kikuchipy/_signals/ebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,23 +366,23 @@ def static_background_correction(
dtype = np.int16
static_bg = static_bg.astype(dtype)

# Create dask array of signal patterns and do processing on this
dask_array = kpud._get_dask_array(signal=self, dtype=dtype)

# Get min./max. input patterns intensity after correction
if relative: # Scale relative to min./max. intensity in scan
signal_min = dask_array.min(axis=(0, 1))
signal_max = dask_array.max(axis=(0, 1))
signal_min = self.data.min(axis=(0, 1))
signal_max = self.data.max(axis=(0, 1))
if operation == 'subtract':
imin = da.subtract(signal_min, static_bg, dtype=dtype).min()
imax = da.subtract(signal_max, static_bg, dtype=dtype).max()
imin = (signal_min - static_bg).astype(dtype).min()
imax = (signal_max - static_bg).astype(dtype).max()
else: # Divide
imin = da.divide(signal_min, static_bg, dtype=dtype).min()
imax = da.divide(signal_max, static_bg, dtype=dtype).max()
imin = (signal_min / static_bg).astype(dtype).min()
imax = (signal_max / static_bg).astype(dtype).max()
in_range = (imin, imax)
else: # Scale relative to min./max. intensity in each pattern
in_range = None

# Create dask array of signal patterns and do processing on this
dask_array = kpud._get_dask_array(signal=self, dtype=dtype)

# Correct static background and rescale intensities chunk by chunk
corrected_patterns = dask_array.map_blocks(
kpue._static_background_correction_chunk, static_bg=static_bg,
Expand Down Expand Up @@ -490,15 +490,15 @@ def rescale_intensities(self, relative=False, dtype_out=None):
if dtype_out is None:
dtype_out = self.data.dtype.type

# Create dask array of signal patterns and do processing on this
dask_array = kpud._get_dask_array(signal=self)

# Determine min./max. intensity of input pattern to rescale to
if relative: # Scale relative to min./max. intensity in scan
in_range = (dask_array.min(), dask_array.max())
in_range = (self.data.min(), self.data.max())
else: # Scale relative to min./max. intensity in each pattern
in_range = None

# Create dask array of signal patterns and do processing on this
dask_array = kpud._get_dask_array(signal=self)

# Rescale patterns
rescaled_patterns = dask_array.map_blocks(
kpue._rescale_pattern_chunk, in_range=in_range, dtype_out=dtype_out,
Expand Down
36 changes: 18 additions & 18 deletions kikuchipy/_signals/test/test_ebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,7 @@ def test_dynamic_background_correction(

dummy_signal.dynamic_background_correction(
operation=operation, sigma=sigma)
if operation == 'subtract' and sigma == 1:
answer = np.array(
[153, 255, 204, 255, 255, 204, 255, 51, 0, 255, 198, 226, 198,
0, 226, 226, 226, 198, 0, 95, 63, 159, 63, 255, 63, 63, 223,
223, 0, 191, 159, 127, 255, 223, 63, 95, 113, 0, 255, 0, 28, 0,
56, 56, 141, 255, 191, 0, 127, 223, 223, 223, 191, 0, 204, 51,
255, 153, 204, 0, 102, 102, 51, 127, 229, 204, 102, 153, 0, 76,
255, 76, 212, 0, 0, 127, 85, 127, 0, 85, 255],
dtype=np.uint8).reshape((3, 3, 3, 3))
elif operation == 'subtract' and sigma == 2:
if operation == 'subtract' and sigma == 2:
answer = np.array(
[182, 218, 182, 255, 218, 182, 218, 36, 0, 255, 191, 223, 223,
0, 223, 255, 223, 191, 0, 85, 85, 141, 56, 255, 85, 85, 255,
Expand All @@ -199,16 +190,16 @@ def test_dynamic_background_correction(
255, 127, 170, 0, 42, 42, 0, 141, 255, 226, 113, 170, 0, 56,
255, 56, 255, 72, 36, 145, 109, 145, 0, 109, 255],
dtype=np.uint8).reshape((3, 3, 3, 3))
elif operation == 'divide' and sigma == 1:
elif operation == 'subtract' and sigma == 3:
answer = np.array(
[159, 255, 212, 223, 255, 212, 255, 63, 0, 218, 170, 194, 170,
0, 194, 194, 255, 218, 0, 127, 85, 212, 85, 255, 85, 85, 191,
162, 0, 139, 115, 115, 255, 162, 46, 115, 113, 0, 255, 0, 28,
0, 56, 56, 141, 255, 191, 0, 127, 223, 223, 223, 191, 0, 255,
63, 255, 191, 255, 0, 127, 127, 0, 94, 170, 151, 75, 113, 0,
56, 255, 56, 159, 0, 0, 127, 85, 127, 0, 85, 255],
[182, 218, 218, 255, 218, 182, 218, 36, 0, 255, 191, 223, 191,
0, 223, 223, 223, 159, 0, 85, 85, 141, 56, 255, 85, 85, 255,
255, 0, 218, 182, 109, 255, 255, 36, 36, 141, 28, 255, 28, 56,
0, 85, 85, 141, 255, 191, 0, 127, 223, 223, 223, 191, 0, 170,
42, 255, 127, 170, 0, 42, 42, 0, 141, 255, 226, 113, 170, 0,
56, 255, 56, 255, 72, 36, 145, 109, 109, 0, 109, 218],
dtype=np.uint8).reshape((3, 3, 3, 3))
else: # operation == 'divide' and sigma == 2
elif operation == 'divide' and sigma == 2:
answer = np.array(
[182, 218, 182, 255, 218, 182, 218, 36, 0, 191, 148, 170, 223,
0, 170, 255, 223, 191, 0, 85, 85, 141, 56, 255, 85, 85, 255,
Expand All @@ -217,6 +208,15 @@ def test_dynamic_background_correction(
42, 255, 127, 170, 0, 42, 42, 0, 141, 255, 226, 113, 170, 0,
56, 255, 56, 255, 72, 36, 145, 109, 145, 0, 109, 255],
dtype=np.uint8).reshape((3, 3, 3, 3))
else: # operation == 'divide' and sigma == 3:
answer = np.array(
[182, 218, 242, 255, 218, 182, 218, 36, 0, 255, 198, 226, 198,
0, 226, 226, 237, 170, 0, 85, 85, 141, 56, 255, 85, 85, 255,
255, 0, 218, 182, 109, 255, 255, 36, 36, 226, 0, 255, 0, 56,
0, 113, 113, 141, 255, 191, 0, 127, 223, 223, 223, 191, 0, 170,
42, 255, 127, 170, 0, 42, 42, 0, 141, 255, 226, 113, 170, 0,
56, 255, 56, 255, 72, 36, 145, 109, 101, 0, 109, 189],
dtype=np.uint8).reshape((3, 3, 3, 3))
assert dummy_signal.data.all() == answer.all()
assert dummy_signal.data.dtype == answer.dtype

Expand Down

0 comments on commit 971699a

Please sign in to comment.