Skip to content

Commit

Permalink
Merge pull request #91 from neutrons/reduce_two_samples
Browse files Browse the repository at this point in the history
Reduce two samples
  • Loading branch information
backmari authored Oct 29, 2024
2 parents 8174025 + 7d8aea8 commit 3a52a26
Show file tree
Hide file tree
Showing 16 changed files with 1,990 additions and 195 deletions.
1 change: 1 addition & 0 deletions docs/releasenotes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Notes for major and minor releases. Notes for Patch releases are deferred.

**Of interest to the User**:

- PR #91: Add ability to reduce multiple samples from the same run
- PR #104: Update Mantid version to 6.10
- PR #95: Optional dead-time correction (disabled by default)

Expand Down
26 changes: 25 additions & 1 deletion reflectivity_ui/interfaces/data_handling/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,32 @@ def set_parameter(self, param, value):
logging.error("Could not set parameter %s %s", param, value)
return has_changed

def calculate_reflectivity(self, direct_beam=None, configuration=None):
def calculate_reflectivity(self, direct_beam=None, configuration=None, ws_suffix: str = ""):
"""
Loop through the cross-section data sets and update
the reflectivity.
Parameters
----------
direct_beam: CrossSectionData | None
Direct beam data
configuration: Configuration | None
The configuration
ws_suffix: str
String to add to reflectivity workspace name
Example
-------
`ws_suffix` is used when reducing multiple ROIs for the same run and cross-section, to
differentiate the workspace names in the Mantid data service
peak_index = 2
# update the active reduction list
data_manager.set_active_reduction_list_index(peak_index)
# get the first data set of the active reduction list
nexus_data = data_manager.reduction_list[0]
# calculate the reflectivity for this data set
nexus_data.calculate_reflectivity(ws_suffix=str(peak_index))
"""
if configuration is not None:
self.configuration = copy.deepcopy(configuration)
Expand Down Expand Up @@ -282,6 +304,8 @@ def _as_ints(a):
)
_ws = ws if len(ws_list) > 1 else [ws]
for xs in _ws:
# add suffix to avoid overwriting ws in mantid data service, needed for multiple peaks
api.RenameWorkspace(str(xs), str(xs) + ws_suffix)
xs_id = xs.getRun().getProperty("cross_section_id").value
self.cross_sections[xs_id].q = xs.readX(0)[:].copy()
self.cross_sections[xs_id]._r = np.ma.masked_equal(xs.readY(0)[:].copy(), 0)
Expand Down
48 changes: 32 additions & 16 deletions reflectivity_ui/interfaces/data_handling/processing_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
format_5cols=False,
output_sample_size=10,
output_directory="",
output_file_template="(instrument)_{numbers}_{item}_{state}.{type}",
output_file_template="{instrument}_{numbers}_{peak}_{item}_{state}.{type}",
email_send=False,
email_zip_data=False,
email_send_plots=False,
Expand Down Expand Up @@ -70,23 +70,34 @@ def execute(self, progress=None):
if not self.data_manager.reduction_states:
return

if self.output_options["export_specular"]:
if progress is not None:
progress(10, "Computing reflectivity")
self.specular_reflectivity()
# store current peak shown in the UI
active_peak = self.data_manager.active_reduction_list_index

for peak_index in self.data_manager.peak_reduction_lists.keys():
# set active data based on peak index
self.data_manager.set_active_reduction_list_index(peak_index)
self.data_manager.set_active_data_from_reduction_list(0)

if self.output_options["export_specular"]:
if progress is not None:
progress(10, "Computing reflectivity")
self.specular_reflectivity()

if self.output_options["export_offspec"] or self.output_options["export_offspec_smooth"]:
if progress is not None:
progress(20, "Computing off-specular reflectivity")
self.offspec(
raw=self.output_options["export_offspec"], binned=self.output_options["export_offspec_smooth"]
)

if self.output_options["export_offspec"] or self.output_options["export_offspec_smooth"]:
if progress is not None:
progress(20, "Computing off-specular reflectivity")
self.offspec(
raw=self.output_options["export_offspec"], binned=self.output_options["export_offspec_smooth"]
)
progress(60, "Computing GISANS")
if self.output_options["export_gisans"]:
# FIXME 66 - could be an AttributeError from self.gisans(). Catch it!
self.gisans(progress=progress)

if progress is not None:
progress(60, "Computing GISANS")
if self.output_options["export_gisans"]:
# FIXME 66 - could be an AttributeError from self.gisans(). Catch it!
self.gisans(progress=progress)
# restore current peak shown in the UI
self.data_manager.set_active_reduction_list_index(active_peak)

if self.output_options["email_send"]:
self.send_email()
Expand All @@ -112,6 +123,7 @@ def get_file_name(self, run_list=None, pol_state=None, data_type="dat", process_
if pol_state is not None:
base_name = base_name.replace("{state}", pol_state)
base_name = base_name.replace("{type}", data_type)
base_name = base_name.replace("{peak}", f"peak{self.data_manager.active_reduction_list_index}")
return os.path.join(self.output_options["output_directory"], base_name)

def write_quicknxs(self, output_data, output_file_base, xs=None):
Expand Down Expand Up @@ -152,7 +164,11 @@ def write_quicknxs(self, output_data, output_file_base, xs=None):

state_output_path = output_file_base.replace("{state}", pol_state)
quicknxs_io.write_reflectivity_header(
self.data_manager.reduction_list, self.data_manager.direct_beam_list, state_output_path, _pol_state
self.data_manager.peak_reduction_lists,
self.data_manager.active_reduction_list_index,
self.data_manager.direct_beam_list,
state_output_path,
_pol_state,
)
quicknxs_io.write_reflectivity_data(
state_output_path, output_data[pol_state], col_names, as_5col=five_cols
Expand Down
Loading

0 comments on commit 3a52a26

Please sign in to comment.