Skip to content

Commit

Permalink
Merge pull request #848 from psavery/subtract-minimum
Browse files Browse the repository at this point in the history
Add option in transform dialog to subtract minimum
  • Loading branch information
joelvbernier authored Mar 24, 2021
2 parents 5d78b53 + 1dba396 commit 7375059
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
15 changes: 15 additions & 0 deletions hexrd/ui/extra_ops_processed_image_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from hexrd.imageseries.process import ProcessedImageSeries


class ExtraOpsProcessedImageSeries(ProcessedImageSeries):
"""This class is here to add extra ops that aren't in hexrd..."""

SUBTRACT = 'subtract'

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.addop(self.SUBTRACT, self._subtract)

def _subtract(self, img, subtrahend):
return img - subtrahend
11 changes: 10 additions & 1 deletion hexrd/ui/image_load_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from PySide2.QtWidgets import QMessageBox

from hexrd.ui.async_worker import AsyncWorker
from hexrd.ui.extra_ops_processed_image_series import (
ExtraOpsProcessedImageSeries)
from hexrd.ui.hexrd_config import HexrdConfig
from hexrd.ui.image_file_manager import ImageFileManager
from hexrd.ui.progress_dialog import ProgressDialog
Expand Down Expand Up @@ -278,6 +280,11 @@ def apply_operations(self, ims_dict):
self.update_progress_text('Aggregating dark images...')
dark_images = self.aggregate_dark_multithread(dark_aggr_ops)

if 'zero-min' in self.state:
# Get the minimum over all the detectors
all_mins = [imageseries.stats.min(x) for x in ims_dict.values()]
global_min = min([x.min() for x in all_mins])

# Apply the operations to the imageseries
for idx, key in enumerate(ims_dict.keys()):
ops = []
Expand All @@ -288,9 +295,11 @@ def apply_operations(self, ims_dict):
self.get_flip_op(ops, idx)
if 'rect' in self.state:
ops.append(('rectangle', self.state['rect'][idx]))
if 'zero-min' in self.state:
ops.append(('subtract', global_min))

frames = self.get_range(ims_dict[key])
ims_dict[key] = imageseries.process.ProcessedImageSeries(
ims_dict[key] = ExtraOpsProcessedImageSeries(
ims_dict[key], ops, frame_list=frames)
HexrdConfig().set_instrument_config_val(
['detectors', key, 'pixels', 'columns', 'value'],
Expand Down
16 changes: 16 additions & 0 deletions hexrd/ui/resources/ui/transforms_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="subtract_minimum">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Subtract the minimum value of all the data from each of the detectors.&lt;/p&gt;&lt;p&gt;This can be used to get rid of negative values, for instance.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Subtract minimum</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
Expand Down Expand Up @@ -127,6 +137,12 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>update_all</tabstop>
<tabstop>update_each</tabstop>
<tabstop>transform_all_menu</tabstop>
<tabstop>subtract_minimum</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
Expand Down
13 changes: 12 additions & 1 deletion hexrd/ui/transform_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,19 @@ def apply_transforms(self):
else:
for combo in self.det_cboxes:
trans.append(combo.currentIndex())

ilm = ImageLoadManager()
state = HexrdConfig().load_panel_state
state['trans'] = trans
ilm.set_state({ 'trans': trans , 'agg': state.get('agg', 0) })

new_state = {
'trans': trans,
'agg': state.get('agg', 0),
}

if self.ui.subtract_minimum.isChecked():
new_state['zero-min'] = None
state['zero-min'] = None

ilm.set_state(new_state)
ilm.begin_processing(postprocess=True)

0 comments on commit 7375059

Please sign in to comment.