Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

38863 Update Engineering Diffraction Calibration region of interest functionality #38870

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
30 changes: 29 additions & 1 deletion Testing/SystemTests/tests/framework/EnginXScriptTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def runTest(self):
) # North
enginx.main(plot_cal=False, plot_foc=False)
# store workspaces for validation
self._ws_foc = ADS.retrieve("299080_engggui_focusing_output_ws_Cropped")
self._ws_foc = ADS.retrieve("299080_engggui_focusing_output_ws_Cropped_1-1200")

def validate(self):
# only assert diff constants (both banks tests normalisation etc.)
Expand All @@ -85,6 +85,34 @@ def cleanup(self):
_try_delete_cal_and_focus_dirs(CWDIR)


class TestSwappingCustomCroppingChangesFocussing(systemtesting.MantidSystemTest):
def runTest(self):
enginx = EnginX(
vanadium_run="ENGINX307521",
focus_runs=["ENGINX305761"],
save_dir=CWDIR,
full_inst_calib_path=FULL_CALIB,
ceria_run="ENGINX305738",
group=GROUP.CROPPED,
spectrum_num="1-1200",
)
enginx.main()
self._dataY = ADS.retrieve("305761_engggui_focusing_output_ws_Cropped_1-1200").extractY().max()

# run again with different cropping window and store the resulting diff consts
enginx.calibration.set_spectra_list("1-100")
enginx.calibration.update_group_ws_from_group()
enginx.main()
self._dataY2 = ADS.retrieve("305761_engggui_focusing_output_ws_Cropped_1-100").extractY().max()

def validate(self):
self.assertNotAlmostEqual(self._dataY, self._dataY2, delta=0.005)

def cleanup(self):
ADS.clear()
_try_delete_cal_and_focus_dirs(CWDIR)


class FocusTexture(systemtesting.MantidSystemTest):
def runTest(self):
enginx = EnginX(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ This test covers the Cropping functionality in the ``Calibration`` tab.

1. Change the ``RB Number`` to ``North``, this is purely to separate the cropped output files into their own space.

2. Go to the ``Calibration`` tab, select ``Create New Calibration`` and tick the ``Crop Calibration`` option. In the drop down ``Region of Interest`` select ``1 (North)``.
2. Go to the ``Calibration`` tab, select ``Create New Calibration`` and tick the ``Set Calibration Region of Interest`` option. In the drop down ``Region of Interest`` select ``1 (North)``.

3. Check the ``Plot Calibrated Workspace`` checkbox and click ``Calibrate``.

Expand All @@ -146,7 +146,7 @@ This test covers the loading and plotting focused data in the fitting tab.
.. note:: Sometimes it will be tricky to load ENGINX files from the archive and the red ``*`` next to the ``Browse`` button won't disappear. Proceeding with the red ``*`` will raise an error saying ``Check run numbers/path is valid.`` or ``Mantid is searching for data files. Please wait``. In such cases, please try re-entering the text and wait till the red ``*`` is cleared before proceeding. If the log level is set to Information, found path = 1 will be visible in the message log when the runs are found from the archive.

1. Ensure you can access the ISIS data archive. In the ``Calibration`` tab, select ``Create New Calibration`` and enter ``Calibration sample`` # ``305738``. Before proceeding, make sure the red ``*`` next to the ``Browse`` button is disappeared when clicked somewhere outside that text box.
Untick ``Crop Calibration`` option and click on ``Calibrate`` button.
Untick ``Set Calibration Region of Interest`` option and click on ``Calibrate`` button.

2. On the ``Focus`` tab, set ``Sample Run #`` to ``305793-305795`` and ``Vanadium #`` to ``307521``. These sample runs have different stress and strain log values. Make sure the red ``*`` s next to the two ``Browse`` buttons are cleared when clicked outside the text boxes or wait otherwise. Then click ``Focus``.

Expand Down Expand Up @@ -288,7 +288,7 @@ Please test this on IDAaaS: an ENGINX instance should have MantidWorkbenchNightl

1. Close and re-open the Engineering Diffraction interface.

2. Go to the ``Calibration`` tab, select ``Create New Calibration`` and un-tick the ``Crop Calibration`` option.
2. Go to the ``Calibration`` tab, select ``Create New Calibration`` and un-tick the ``Set Calibration Region of Interest`` option.

3. For the ``Calibration Sample #`` enter ``305738`` and click the ``Calibrate`` button.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Cropping
^^^^^^^^

The interface also provides the ability to restrict a new calibration to a particular region of interest:
one of the two banks on ENGIN-X, a custom .cal file, a list of spectra (referred to as cropped), Texture20 grouping
one of the two banks on ENGIN-X, a custom grouping file, a list of spectra (referred to as cropped), Texture20 grouping
(consists of 10 groupings per detector bank - 20 in total) and Texture30 (15 groupings per detector bank - 30 in total).

Parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- When Focusing, either within the interface or in a script, you should no longer be able to unknowingly apply an outdated vanadium correction. Previously, when focusing had already been run on a user defined region of interest (Custom or Cropped), the vanadium correction was calculated and saved in the ADS as ``engggui_curves_Custom`` or ``engggui_curves_Cropped``. If this ROI was then updated and recalibrated, when focus was run again, it would load the existing ``engggui_curves`` from the ADS which would be from the old ROI. Now, the naming of these files should be more unique to the specific ROI, and in the case where a file is loaded from the ADS which may be wrong, a warning is supplied to the user.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Renamed ``Crop Calibration`` within the ``Engineering Diffraction`` calibration interface to ``Set Calibration Region of Interest`` to more accurately reflect its functionality.
- Renamed ``Custom CalFile`` to ``Custom Grouping File`` and allowed the provided file to be ``.xml`` as well as ``.`cal``. This brings it inline with the current detector grouping IO algorithms, :ref:`algm-SaveDetectorsGrouping-v1` and :ref:`algm-LoadDetectorsGroupingFile-v1`.
- Changed the naming suffix for custom file example_group.xml from _Custom to _Custom_example_group so they don't get overwritten when custom grouping is changed (also more clear to the user what grouping is being used).
- Changed the naming suffix for cropped spectrum list: example_list from _Cropped to _Cropped_example_list so they don't get overwritten when custom grouping is changed (also more clear to the user what grouping is being used).
- Added a warning to Focusing for when the vanadium normalisation has been loaded from the ADS
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ QGroupBox:title {
</widget>
</item>
<item row="7" column="0" colspan="3">
<widget class="QCheckBox" name="check_cropCalib">
<widget class="QCheckBox" name="check_roiCalib">
<property name="text">
<string>Crop Calibration</string>
<string>Set Calibration Region of Interest</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -255,7 +255,7 @@ QGroupBox:title {
<tabstop>finder_sample</tabstop>
<tabstop>radio_loadCalib</tabstop>
<tabstop>finder_path</tabstop>
<tabstop>check_cropCalib</tabstop>
<tabstop>check_roiCalib</tabstop>
<tabstop>widget_cropping.combo_bank</tabstop>
<tabstop>widget_cropping.edit_crop</tabstop>
<tabstop>widget_cropping.finder_custom</tabstop>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ def update_calibration_from_view(self):
# loading calibration from path to .prm
self.current_calibration.set_calibration_from_prm_fname(self.view.get_path_filename())
else:
# make a new calibration
# update current calibration with new data
sample_file = self.view.get_sample_filename()
self.current_calibration.set_calibration_paths(self.instrument, sample_file)
# set group and any additional parameters needed
if self.view.get_crop_checked():
self.current_calibration.set_group(self.cropping_widget.get_group())
if self.current_calibration.group == GROUP.CUSTOM:
self.current_calibration.set_cal_file(self.cropping_widget.get_custom_calfile())
self.current_calibration.set_grouping_file(self.cropping_widget.get_custom_groupingfile())
elif self.current_calibration.group == GROUP.CROPPED:
self.current_calibration.set_spectra_list(self.cropping_widget.get_custom_spectra())
else:
# default if no cropping
self.current_calibration.set_group(GROUP.BOTH)
# ensure the updated group is translated to an updated group_ws
self.current_calibration.update_group_ws_from_group()

def on_calibrate_clicked(self):
if self.view.get_new_checked() and self._validate():
Expand Down Expand Up @@ -113,10 +115,12 @@ def load_last_calibration(self) -> None:
Loads the most recently created or loaded calibration into the interface instance. To be used on interface
startup.
"""
last_cal_path = get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "last_calibration_path")
if last_cal_path:
last_grouping_path = get_setting(
output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "last_calibration_path"
)
if last_grouping_path:
self.view.set_load_checked(True)
self.view.set_file_text_with_search(last_cal_path)
self.view.set_file_text_with_search(last_grouping_path)

def set_instrument_override(self, instrument):
instrument = INSTRUMENT_DICT[instrument]
Expand All @@ -135,8 +139,8 @@ def _validate(self):
create_error_message(self.view, "Check run numbers/path is valid.")
return False
if self.view.get_crop_checked():
if self.cropping_widget.get_custom_calfile_enabled() and not self.cropping_widget.is_calfile_valid():
create_error_message(self.view, "Check custom calfile path is valid.")
if self.cropping_widget.get_custom_groupingfile_enabled() and not self.cropping_widget.is_groupingfile_valid():
create_error_message(self.view, "Check custom grouping file path is valid.")
return False
if self.cropping_widget.get_custom_spectra_enabled() and not self.cropping_widget.is_spectra_valid():
create_error_message(self.view, "Check custom spectra are valid.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_update_calibration_from_view_no_cropping(self):

self.presenter.current_calibration.set_calibration_paths.assert_called_once_with("ENGINX", "193749")
self.presenter.current_calibration.set_group.assert_called_once_with(GROUP.BOTH)
self.presenter.current_calibration.set_cal_file.assert_not_called()
self.presenter.current_calibration.set_grouping_file.assert_not_called()
self.presenter.current_calibration.set_spectra_list.assert_not_called()

def test_update_calibration_from_view_cropped_to_bank(self):
Expand All @@ -49,7 +49,7 @@ def test_update_calibration_from_view_cropped_to_bank(self):

self.presenter.current_calibration.set_calibration_paths.assert_called_once_with("ENGINX", "193749")
self.presenter.current_calibration.set_group.assert_called_once_with(self.presenter.cropping_widget.get_group())
self.presenter.current_calibration.set_cal_file.assert_not_called()
self.presenter.current_calibration.set_grouping_file.assert_not_called()
self.presenter.current_calibration.set_spectra_list.assert_not_called()

def test_update_calibration_from_view_cropped_to_texture30(self):
Expand All @@ -64,7 +64,7 @@ def test_update_calibration_from_view_cropped_to_texture30(self):

self.presenter.current_calibration.set_calibration_paths.assert_called_once_with("ENGINX", "193749")
self.presenter.current_calibration.set_group.assert_called_once_with(self.presenter.cropping_widget.get_group())
self.presenter.current_calibration.set_cal_file.assert_not_called()
self.presenter.current_calibration.set_grouping_file.assert_not_called()
self.presenter.current_calibration.set_spectra_list.assert_not_called()

def test_update_calibration_from_view_cropped_to_spectra(self):
Expand All @@ -81,14 +81,14 @@ def test_update_calibration_from_view_cropped_to_spectra(self):

self.presenter.current_calibration.set_calibration_paths.assert_called_once_with("ENGINX", "193749")
self.presenter.current_calibration.set_group.assert_called_once_with(self.presenter.cropping_widget.get_group())
self.presenter.current_calibration.set_cal_file.assert_not_called()
self.presenter.current_calibration.set_grouping_file.assert_not_called()
self.presenter.current_calibration.set_spectra_list.assert_called_once_with(self.presenter.cropping_widget.get_custom_spectra())

def test_update_calibration_from_view_custom_calfile(self):
self.view.get_load_checked.return_value = False
self.view.get_crop_checked.return_value = True
self.presenter.cropping_widget.get_group.return_value = GROUP.CUSTOM
self.presenter.cropping_widget.get_custom_calfile.return_value = "cal"
self.presenter.cropping_widget.get_custom_groupingfile.return_value = "cal"
self.presenter.instrument = "ENGINX"
self.view.get_sample_filename.return_value = "193749"
self.presenter.current_calibration = mock.create_autospec(CalibrationInfo(), instance=True)
Expand All @@ -98,7 +98,9 @@ def test_update_calibration_from_view_custom_calfile(self):

self.presenter.current_calibration.set_calibration_paths.assert_called_once_with("ENGINX", "193749")
self.presenter.current_calibration.set_group.assert_called_once_with(self.presenter.cropping_widget.get_group())
self.presenter.current_calibration.set_cal_file.assert_called_once_with(self.presenter.cropping_widget.get_custom_calfile())
self.presenter.current_calibration.set_grouping_file.assert_called_once_with(
self.presenter.cropping_widget.get_custom_groupingfile()
)
self.presenter.current_calibration.set_spectra_list.assert_not_called()

@patch(tab_path + ".presenter.create_error_message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def set_update_field_connection(self, slot):
self.sig_update_sample_field.connect(slot)

def set_on_check_cropping_state_changed(self, slot):
self.check_cropCalib.stateChanged.connect(slot)
self.check_roiCalib.stateChanged.connect(slot)

# =================
# Component Setters
Expand Down Expand Up @@ -90,10 +90,10 @@ def set_cropping_widget_visibility(self, visible):
self.widget_cropping.setVisible(visible)

def set_check_cropping_enabled(self, enabled):
self.check_cropCalib.setEnabled(enabled)
self.check_roiCalib.setEnabled(enabled)

def set_check_cropping_checked(self, checked):
self.check_cropCalib.setChecked(checked)
self.check_roiCalib.setChecked(checked)

# =================
# Component Getters
Expand Down Expand Up @@ -121,7 +121,7 @@ def get_load_checked(self):
return self.radio_loadCalib.isChecked()

def get_crop_checked(self):
return self.check_cropCalib.isChecked()
return self.check_roiCalib.isChecked()

def get_cropping_widget(self):
return self.widget_cropping
Expand Down Expand Up @@ -151,7 +151,7 @@ def setup_tabbing_order(self):
self.setTabOrder(self.radio_newCalib, self.finder_sample.focusProxy())
self.setTabOrder(self.finder_sample.focusProxy(), self.radio_loadCalib)
self.setTabOrder(self.radio_loadCalib, self.finder_path.focusProxy())
self.setTabOrder(self.finder_path.focusProxy(), self.check_cropCalib)
self.setTabOrder(self.check_cropCalib, self.widget_cropping)
self.setTabOrder(self.finder_path.focusProxy(), self.check_roiCalib)
self.setTabOrder(self.check_roiCalib, self.widget_cropping)
self.setTabOrder(self.widget_cropping, self.check_plotOutput)
self.setTabOrder(self.check_plotOutput, self.button_calibrate)
Loading