Skip to content

Commit

Permalink
Merge pull request #1554 from HEXRD/do-not-rescale-cartesian
Browse files Browse the repository at this point in the history
Do not rescale the cartesian and polar views
  • Loading branch information
psavery authored Aug 3, 2023
2 parents ebbd675 + 4085b50 commit b85af6e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 31 deletions.
9 changes: 0 additions & 9 deletions hexrd/ui/calibration/cartesian_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,6 @@ def generate_image(self):

# In case there were any nans...
nan_mask = np.isnan(img)
img = np.ma.masked_array(img, mask=nan_mask, fill_value=0.)

# Rescale the data to match the scale of the original dataset
# TODO: try to get create_calibration_image to not rescale the
# result to be between 0 and 1 in the first place so this will
# not be necessary.
img = np.interp(img, (img.min(), img.max()), (self.min, self.max))

# Re-mask...
self.img = np.ma.masked_array(img, mask=nan_mask, fill_value=0.)

def update_images_dict(self):
Expand Down
6 changes: 1 addition & 5 deletions hexrd/ui/calibration/polar_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def all_detector_borders(self):
def angular_grid(self):
return self.pv.angular_grid

@property
def raw_rescaled_img(self):
return self.pv.raw_rescaled_img

@property
def raw_img(self):
return self.pv.raw_img
Expand Down Expand Up @@ -111,7 +107,7 @@ def write_image(self, filename='polar_image.npz'):
np.savetxt(filename, azimuthal_integration, delimiter=delimiter)
return

intensities = self.raw_rescaled_img
intensities = self.raw_img.data
intensities[self.raw_mask] = np.nan

# Prepare the data to write out
Expand Down
17 changes: 1 addition & 16 deletions hexrd/ui/calibration/polarview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np

from skimage.exposure import rescale_intensity
from skimage.filters.edges import binary_erosion
from skimage.morphology import rectangle
from skimage.transform import warp
Expand Down Expand Up @@ -347,7 +346,6 @@ def apply_tth_distortion(self, pimg):
# mask_warp = warp(pimg.mask, displ_field, mode='edge')
image1_warp = warp(pimg, displ_field, mode='edge')

# image1_warp = rescale_intensity(image1_warp, out_range=np.uint32)
return np.ma.array(image1_warp) # , mask=mask_warp)

def generate_image(self):
Expand All @@ -362,16 +360,12 @@ def generate_image(self):
self.raw_img = np.ma.sum(np.ma.stack(self.warp_dict.values()), axis=0)
self.apply_image_processing()

@property
def raw_rescaled_img(self):
return self.apply_rescale(self.raw_img.data)

@property
def raw_mask(self):
return self.raw_img.mask

def apply_image_processing(self):
img = self.raw_rescaled_img
img = self.raw_img.data
img = self.apply_snip(img)
# cache this step so we can just re-apply masks if needed
self.snipped_img = img
Expand All @@ -384,15 +378,6 @@ def apply_image_processing(self):

self.processed_img = img

def apply_rescale(self, img):
# Rescale the data to match the scale of the original dataset
kwargs = {
'image': img,
'in_range': (np.nanmin(img), np.nanmax(img)),
'out_range': (self.min, self.max),
}
return rescale_intensity(**kwargs)

def apply_snip(self, img):
# do SNIP if requested
img = img.copy()
Expand Down
2 changes: 1 addition & 1 deletion hexrd/ui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ def polar_show_snip1d(self):
background = self.iviewer.snip_background
else:
# We have to run it ourselves...
img = self.iviewer.raw_rescaled_img
img = self.iviewer.raw_img.data

no_nan_methods = [utils.SnipAlgorithmType.Fast_SNIP_1D]
if HexrdConfig().polar_snip1d_algorithm not in no_nan_methods:
Expand Down

0 comments on commit b85af6e

Please sign in to comment.