Skip to content

Commit ace5114

Browse files
authored
Merge pull request #1149 from psavery/brightness-contrast-editor-improvements
Use current view data for B&C editor histogram and auto button
2 parents 3034c8f + 5ad9882 commit ace5114

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

hexrd/ui/brightness_contrast_editor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def data_bounds(self):
9797
return (0, 1)
9898

9999
data = self.data_list
100-
mins = [x.min() for x in data]
101-
maxes = [x.max() for x in data]
100+
mins = [np.nanmin(x) for x in data]
101+
maxes = [np.nanmax(x) for x in data]
102102
return (min(mins), max(maxes))
103103

104104
def reset_data_range(self):

hexrd/ui/hexrd_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class HexrdConfig(QObject, metaclass=QSingleton):
4545
"""Emitted when new plane data is generated for the active material"""
4646
new_plane_data = Signal()
4747

48+
"""Emitted when an image view has finished loading
49+
50+
The dict contains the images. This is used, for instance, to update
51+
the brightness and contrast histogram with the new image data.
52+
"""
53+
image_view_loaded = Signal(dict)
54+
4855
"""Emitted when overlay configuration has changed"""
4956
overlay_config_changed = Signal()
5057

hexrd/ui/image_canvas.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ def load_images(self, image_names):
114114

115115
images_dict = HexrdConfig().images_dict
116116

117+
def apply_masks(img, name):
118+
visible_masks = HexrdConfig().visible_masks
119+
for mask_name, data in HexrdConfig().masks.items():
120+
for det, mask in data:
121+
if mask_name in visible_masks and det == name:
122+
img[~mask] = 0
123+
117124
if (self.mode != ViewType.raw or
118125
len(image_names) != len(self.axes_images)):
119126
# Either we weren't in image mode before, we have a different
@@ -134,11 +141,7 @@ def load_images(self, image_names):
134141
img = images_dict[name]
135142

136143
# Apply any masks
137-
for mask_name, data in HexrdConfig().masks.items():
138-
for det, mask in data:
139-
if (mask_name in HexrdConfig().visible_masks and
140-
det == name):
141-
img[~mask] = 0
144+
apply_masks(img, name)
142145

143146
axis = self.figure.add_subplot(rows, cols, i + 1)
144147
axis.set_title(name)
@@ -158,11 +161,7 @@ def load_images(self, image_names):
158161
img = images_dict[name]
159162

160163
# Apply any masks
161-
for mask_name, data in HexrdConfig().masks.items():
162-
for det, mask in data:
163-
if (mask_name in HexrdConfig().visible_masks and
164-
det == name):
165-
img[~mask] = 0
164+
apply_masks(img, name)
166165
self.axes_images[i].set_data(img)
167166

168167
# This will call self.draw_idle()
@@ -173,6 +172,8 @@ def load_images(self, image_names):
173172
self.update_auto_picked_data()
174173
self.update_overlays()
175174

175+
HexrdConfig().image_view_loaded.emit(images_dict)
176+
176177
msg = 'Image view loaded!'
177178
HexrdConfig().emit_update_status_bar(msg)
178179

@@ -605,6 +606,8 @@ def finish_show_cartesian(self, iviewer):
605606
self.update_overlays()
606607
self.draw_detector_borders()
607608

609+
HexrdConfig().image_view_loaded.emit({'img': img})
610+
608611
msg = 'Cartesian view loaded!'
609612
HexrdConfig().emit_update_status_bar(msg)
610613

@@ -711,6 +714,8 @@ def finish_show_polar(self, iviewer):
711714
self.update_overlays()
712715
self.draw_detector_borders()
713716

717+
HexrdConfig().image_view_loaded.emit({'img': img})
718+
714719
msg = 'Polar view loaded!'
715720
HexrdConfig().emit_update_status_bar(msg)
716721

hexrd/ui/main_window.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def setup_connections(self):
274274
self.enforce_view_mode)
275275

276276
HexrdConfig().instrument_config_loaded.connect(self.update_config_gui)
277+
HexrdConfig().image_view_loaded.connect(self.on_image_view_loaded)
277278

278279
def set_icon(self, icon):
279280
self.ui.setWindowIcon(icon)
@@ -988,3 +989,8 @@ def on_action_llnl_import_tool_triggered(self):
988989

989990
def on_action_image_stack_triggered(self):
990991
self.image_stack_dialog.show()
992+
993+
def on_image_view_loaded(self, images):
994+
# Update the data, but don't reset the bounds
995+
# This will update the histogram in the B&C editor
996+
self.color_map_editor.data = images

hexrd/ui/snip_viewer_dialog.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ def setup_connections(self):
3535
def setup_color_map(self):
3636
self.color_map_editor = ColorMapEditor(self, self.ui)
3737
self.ui.color_map_editor_layout.addWidget(self.color_map_editor.ui)
38-
39-
no_nans_data = np.nan_to_num(self.data)
40-
self.color_map_editor.update_bounds(no_nans_data)
38+
self.color_map_editor.update_bounds(self.data)
4139

4240
def setup_canvas(self):
4341
canvas = FigureCanvas(Figure(tight_layout=True))

0 commit comments

Comments
 (0)