Skip to content

Commit

Permalink
Merge pull request #115 from neutrons/remove_functional_background
Browse files Browse the repository at this point in the history
Remove functional background from background settings
  • Loading branch information
backmari authored Mar 18, 2024
2 parents ca1750b + 35d3dba commit 8ec3321
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 88 deletions.
4 changes: 0 additions & 4 deletions RefRed/calculations/lr_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def __init__(
self.back: List[int] = [0, 0] # lower and upper boundaries for the first background
self.back2: List[int] = [0, 0] # lower and upper boundaries for the second background
self.back_flag: bool = True
self.functional_background: bool = False
self.two_backgrounds: bool = False

self.all_plot_axis = AllPlotAxis()
Expand All @@ -202,7 +201,6 @@ def __init__(
self.low_res = [int(lconfig.data_low_res[0]), int(lconfig.data_low_res[1])]
self.low_res_flag = bool(lconfig.data_low_res_flag)
self.back_flag = bool(lconfig.data_back_flag)
self.functional_background = bool(lconfig.data_functional_background)
self.two_backgrounds = bool(lconfig.data_two_backgrounds)
else:
self.peak = [int(lconfig.norm_peak[0]), int(lconfig.norm_peak[1])]
Expand All @@ -211,7 +209,6 @@ def __init__(
self.low_res = [int(lconfig.norm_low_res[0]), int(lconfig.norm_low_res[1])]
self.low_res_flag = bool(lconfig.norm_low_res_flag)
self.back_flag = bool(lconfig.norm_back_flag)
self.functional_background = bool(lconfig.norm_functional_background)
self.two_backgrounds = bool(lconfig.norm_two_backgrounds)

elif reduction_table_cell is not None:
Expand All @@ -225,7 +222,6 @@ def __init__(
self.low_res = reduction_table_cell.low_res
self.low_res_flag = reduction_table_cell.low_res_flag
self.back_flag = reduction_table_cell.back_flag
self.functional_background = reduction_table_cell.functional_background
self.two_backgrounds = reduction_table_cell.two_backgrounds

else:
Expand Down
9 changes: 0 additions & 9 deletions RefRed/configuration/export_xml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def main_part(self):
data_back2 = _data.back2
data_low_res = _data.low_res
data_back_flag = _data.back_flag
data_functional_background = _data.functional_background
data_two_backgrounds = _data.two_backgrounds
data_low_res_flag = bool(_data.low_res_flag)
data_lambda_requested = _data.lambda_requested
Expand All @@ -105,7 +104,6 @@ def main_part(self):
norm_back = _norm.back
norm_back2 = _norm.back2
norm_back_flag = _norm.back_flag
norm_functional_background = _norm.functional_background
norm_two_backgrounds = _norm.two_backgrounds

norm_low_res = _norm.low_res
Expand All @@ -116,7 +114,6 @@ def main_part(self):
norm_peak = [0, 255]
norm_back = [0, 255]
norm_back_flag = False
norm_functional_background = False
norm_two_backgrounds = False
norm_low_res = [0, 255]
norm_low_res_flag = False
Expand All @@ -126,9 +123,6 @@ def main_part(self):
str_array.append(' <to_peak_pixels>' + str(data_peak[1]) + '</to_peak_pixels>\n')
str_array.append(' <peak_discrete_selection>N/A</peak_discrete_selection>\n')
str_array.append(' <background_flag>' + str(data_back_flag) + '</background_flag>\n')
str_array.append(
' <functional_background>' + str(data_functional_background) + '</functional_background>\n'
)
str_array.append(' <two_backgrounds>' + str(data_two_backgrounds) + '</two_backgrounds>\n')
str_array.append(' <back_roi1_from>' + str(data_back[0]) + '</back_roi1_from>\n')
str_array.append(' <back_roi1_to>' + str(data_back[1]) + '</back_roi1_to>\n')
Expand Down Expand Up @@ -166,9 +160,6 @@ def main_part(self):
str_array.append(' <norm_from_peak_pixels>' + str(norm_peak[0]) + '</norm_from_peak_pixels>\n')
str_array.append(' <norm_to_peak_pixels>' + str(norm_peak[1]) + '</norm_to_peak_pixels>\n')
str_array.append(' <norm_background_flag>' + str(norm_back_flag) + '</norm_background_flag>\n')
str_array.append(
' <norm_functional_background>' + str(norm_functional_background) + '</norm_functional_background>\n'
)
str_array.append(' <norm_two_backgrounds>' + str(norm_two_backgrounds) + '</norm_two_backgrounds>\n')
str_array.append(' <norm_from_back_pixels>' + str(norm_back[0]) + '</norm_from_back_pixels>\n')
str_array.append(' <norm_to_back_pixels>' + str(norm_back[1]) + '</norm_to_back_pixels>\n')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def update_lrdata(self, lrdata=None, lconfig=None, type='data', row=0):
back2_1 = int(lconfig.data_back2[0])
back2_2 = int(lconfig.data_back2[1])
back_flag = lconfig.data_back_flag
functional_background = lconfig.data_functional_background
two_backgrounds = lconfig.data_two_backgrounds
low_res1 = int(lconfig.data_low_res[0])
low_res2 = int(lconfig.data_low_res[1])
Expand All @@ -115,7 +114,6 @@ def update_lrdata(self, lrdata=None, lconfig=None, type='data', row=0):
back2_1 = int(lconfig.norm_back2[0])
back2_2 = int(lconfig.norm_back2[1])
back_flag = lconfig.norm_back_flag
functional_background = lconfig.norm_functional_background
two_backgrounds = lconfig.norm_two_backgrounds
low_res1 = int(lconfig.norm_low_res[0])
low_res2 = int(lconfig.norm_low_res[1])
Expand All @@ -130,7 +128,6 @@ def update_lrdata(self, lrdata=None, lconfig=None, type='data', row=0):
lrdata.back = [back1_1, back1_2]
lrdata.back2 = [back2_1, back2_2]
lrdata.back_flag = back_flag
lrdata.functional_background = functional_background
lrdata.two_backgrounds = two_backgrounds
lrdata.low_res = [low_res1, low_res2]
lrdata.low_res_flag = low_res_flag
Expand Down
2 changes: 0 additions & 2 deletions RefRed/configuration/loading_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def get_item_boolean(item_name: str, default) -> bool:

# background settings for reflectivity data
iMetadata.data_back_flag = get_item_boolean("background_flag", default=True)
iMetadata.data_functional_background = get_item_boolean("functional_background", default=False)
iMetadata.data_two_backgrounds = get_item_boolean("two_backgrounds", default=False)

_low_res_flag = str2bool(self.getNodeValue(node, 'x_range_flag'))
Expand Down Expand Up @@ -258,7 +257,6 @@ def get_item_boolean(item_name: str, default) -> bool:

# background settings for normalization data
iMetadata.norm_back_flag = get_item_boolean("norm_background_flag", default=True)
iMetadata.norm_functional_background = get_item_boolean("norm_functional_background", default=False)
iMetadata.norm_two_backgrounds = get_item_boolean("norm_two_backgrounds", default=False)

_low_res_flag = str2bool(self.getNodeValue(node, 'norm_x_range_flag'))
Expand Down
42 changes: 4 additions & 38 deletions RefRed/interfaces/background_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>260</width>
<height>160</height>
<height>101</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -19,10 +19,10 @@
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>13</x>
<y>19</y>
<x>10</x>
<y>10</y>
<width>241</width>
<height>131</height>
<height>81</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -63,40 +63,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="functional_background">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Fit the background region(s) with a linear function. Functional background is necessary when using two background regions. It is optional when using a single region. In that case, the background is estimated by simple averaging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Use functional background</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
Expand Down
2 changes: 0 additions & 2 deletions RefRed/lconfigdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class LConfigDataset(object):
data_back2: List[int] = [0, 0] # lower and upper boundaries for the second background
data_low_res = [50, 200]
data_back_flag: bool = True
data_functional_background: bool = False
data_two_backgrounds: bool = False
data_low_res_flag = True
data_lambda_requested = -1
Expand All @@ -38,7 +37,6 @@ class LConfigDataset(object):
norm_back = [0, 0]
norm_back2: List[int] = [0, 0] # lower and upper boundaries for the second background
norm_back_flag: bool = True
norm_functional_background: bool = False
norm_two_backgrounds: bool = False

norm_low_res = [50, 200]
Expand Down
31 changes: 7 additions & 24 deletions RefRed/plot/background_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
class BackgroundSettingsModel(QObject):
signal_first_background = Signal(bool)
signal_second_background = Signal(bool)
signal_functional_background = Signal(bool)
signal_two_backgrounds = Signal(bool)

def __init__(self):
super(BackgroundSettingsModel, self).__init__()
self._subtract_background = True
self._functional_background = False
self._two_backgrounds = False
self.maingui = None

Expand All @@ -37,17 +35,6 @@ def subtract_background(self, value: bool):
self.signal_first_background.emit(value)
self.signal_second_background.emit(value and self.two_backgrounds)

@property
def functional_background(self) -> bool:
return self._functional_background

@functional_background.setter
def functional_background(self, value: bool):
previous = self._functional_background # backup
self._functional_background = value
if previous != value: # emit changes
self.signal_functional_background.emit(value)

@property
def two_backgrounds(self) -> bool:
return self._two_backgrounds
Expand All @@ -60,13 +47,10 @@ def two_backgrounds(self, value: bool):
if previous != value: # emit changes
self.signal_second_background.emit(self.subtract_background and value)

def update_all_settings(
self, subtract_background: bool = True, functional_background: bool = False, two_backgrounds: bool = False
):
def update_all_settings(self, subtract_background: bool = True, two_backgrounds: bool = False):
# we access the private attributes to prevent emitting any of the signals that could be emitted by
# the setter functions of the associated properties
self._subtract_background = subtract_background
self._functional_background = functional_background
self._two_backgrounds = two_backgrounds

def set_spinbox_visibilities(self, parent: QWidget, first_background: Tuple[str], second_background: Tuple[str]):
Expand Down Expand Up @@ -148,7 +132,7 @@ def update_from_table(self, active_row_index: int, is_data: bool):
if data is None: # the active row in the reduction table has no reflectivity and/or direct-beam data
return
updater = {True: self.data.update_all_settings, False: self.norm.update_all_settings}
updater[is_data](data.back_flag, data.functional_background, data.two_backgrounds)
updater[is_data](data.back_flag, data.two_backgrounds)

def table_updater_factory(self, setting: str, data_type: str):
r"""Generate anonymous functions to serve as callback when any of the background settings
Expand All @@ -161,8 +145,7 @@ def table_updater_factory(self, setting: str, data_type: str):
Parameters
----------
setting
the background setting in `big_table` to update. One of `back_flag`, `functional_background`,
`two_backgrounds`
the background setting in `big_table` to update. One of `back_flag` and `two_backgrounds`
data_type
whether to update the reflectivity or the normalization `LRData` instances for the currently active
row in the reduction table
Expand Down Expand Up @@ -202,9 +185,9 @@ def _initialize_reduction_table_updaters(self):
`data` or `norm` BackgroundSettingsModel instances.
"""
# names of some of the signals emitted by self.data and self.norm
signal_names = ["signal_first_background", "signal_functional_background", "signal_two_backgrounds"]
signal_names = ["signal_first_background", "signal_two_backgrounds"]
# names of the background settings attributes in the LRData instances of `big_table_data`
setting_names = ["back_flag", "functional_background", "two_backgrounds"]
setting_names = ["back_flag", "two_backgrounds"]
# connect the signals to dedicated slots that will update the LRData instances
for signal_name, setting_name in zip(signal_names, setting_names):
signal = getattr(self.data, signal_name)
Expand All @@ -219,7 +202,7 @@ def _initialize_reduction_table_updaters(self):
class BackgroundSettingsView(QDialog):

# checkbox names as well as names for the model properties
options = ["subtract_background", "functional_background", "two_backgrounds"]
options = ["subtract_background", "two_backgrounds"]

def __init__(self, parent: QWidget, run_type="data"):
super().__init__(parent)
Expand All @@ -229,7 +212,7 @@ def __init__(self, parent: QWidget, run_type="data"):
self._set_connections()

def _set_connections(self):
for box_name in ["subtract_background", "functional_background", "two_backgrounds"]:
for box_name in ["subtract_background", "two_backgrounds"]:
checkbox: QCheckBox = getattr(self.ui, box_name)
# signal stateChanged emits `state`, which we pass to our anonymous `lambda`
# `option=box_name` in effect allows us to define a different lambda` function for each checkbox
Expand Down
4 changes: 0 additions & 4 deletions RefRed/preview_config/preview_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class PreviewConfig(QtWidgets.QMainWindow):
"to_peak_pixels",
"peak_discrete_selection",
"background_flag",
"functional_background",
"two_backgrounds",
"back_roi1_from",
"back_roi1_to",
Expand All @@ -38,7 +37,6 @@ class PreviewConfig(QtWidgets.QMainWindow):
"norm_from_peak_pixels",
"norm_to_peak_pixels",
"norm_background_flag",
"norm_functional_background",
"norm_two_backgrounds",
"norm_from_back_pixels",
"norm_to_back_pixels",
Expand All @@ -61,9 +59,7 @@ class PreviewConfig(QtWidgets.QMainWindow):
# may have default values. This way we will load configuration files missing these entries
# and preview them with the default values.
data_name_defaults = {
"functional_background": False,
"two_backgrounds": False,
"norm_functional_background": False,
"norm_two_backgrounds": False,
}

Expand Down
2 changes: 1 addition & 1 deletion RefRed/reduction/individual_reduction_settings_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def norm_setting(setting: str) -> Optional[Any]:
data_peak_range=self._data_peak_range,
subtract_background=self.data.back_flag,
two_backgrounds=self.data.two_backgrounds, # should we use both background regions?
functional_background=self.data.functional_background,
functional_background=self.data.two_backgrounds, # should have same value as `two_backgrounds`
background_roi=self._data_back_range,
data_x_range_flag=self._data_low_res_flag,
data_x_range=self._data_low_res_range,
Expand Down
2 changes: 1 addition & 1 deletion RefRed/reduction/live_reduction_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run(self):
template_data,
info=True,
normalize=reduction_pars['apply_normalization'],
functional_background=reduction_pars['functional_background'],
functional_background=reduction_pars['two_backgrounds'],
)
self.save_reduction(row_index, refl=[q, r, dr], info=info)
except:
Expand Down

2 comments on commit 8ec3321

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for refred-dev has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/conda-legacy-deploy/-/pipelines/540625"

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for refred-qa has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/conda-legacy-deploy/-/pipelines/540686"

Please sign in to comment.