From 06703d8787ab24b12ce2b678b2e6749c8c679ff1 Mon Sep 17 00:00:00 2001 From: y8z Date: Sun, 29 Sep 2024 23:51:49 -0400 Subject: [PATCH] manual group compatible with new align and focus --- .gitignore | 3 ++ total_scattering/file_handling/load.py | 42 +++++++++++++------ .../reduction/total_scattering_reduction.py | 23 ++++++---- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 9287014..fa3112d 100644 --- a/.gitignore +++ b/.gitignore @@ -216,3 +216,6 @@ conda_build/ # vscode settings total_scattering/.vscode +.linenoteplus +settings.json +.vscode/ diff --git a/total_scattering/file_handling/load.py b/total_scattering/file_handling/load.py index 14ebe3d..e3d89ae 100644 --- a/total_scattering/file_handling/load.py +++ b/total_scattering/file_handling/load.py @@ -1,7 +1,6 @@ import logging from mantid import mtd from mantid.simpleapi import \ - AlignAndFocusPowderFromFiles, \ ApplyDiffCal, \ ConvertUnits, \ DeleteWorkspace, \ @@ -10,6 +9,7 @@ Load, \ LoadDetectorsGroupingFile, \ LoadDiffCal, \ + MaskBins, \ MaskDetectors, \ MultipleScatteringCorrection, \ NormaliseByCurrent, \ @@ -18,15 +18,13 @@ PropertyManagerDataService, \ SetSample, \ Rebin, \ - RebinToWorkspace, \ CreateGroupingWorkspace, \ SaveDetectorsGrouping, \ GroupDetectors, \ LoadNexus, \ SaveNexusProcessed, \ CloneWorkspace, \ - Plus, \ - MaskDetectors + Plus from mantid.utils import absorptioncorrutils from sklearn.cluster import KMeans import numpy as np @@ -209,8 +207,7 @@ def load(ws_name, input_files, group_wksp, input_files.split(",")[run_i], align_and_focus_args["CalFilename"], params, - group_wksp_in=proc_group_in, - pres_events=align_and_focus_args["PreserveEvents"] + group_wksp_in=proc_group_in ) Rebin( InputWorkspace=wksp_tmp, @@ -253,9 +250,6 @@ def load(ws_name, input_files, group_wksp, OutputWorkspace=ws_name, AllowDifferentNumberSpectra=True) - DeleteWorkspace(Workspace=absorption_wksp) - DeleteWorkspace(Workspace="absorption_wksp_rb") - DiffractionFocussing( InputWorkspace=ws_name + "_tmp", OutputWorkspace=ws_name, @@ -304,8 +298,7 @@ def load(ws_name, input_files, group_wksp, input_files.split(",")[run_i], align_and_focus_args["CalFilename"], params, - group_wksp_in=group_wksp, - pres_events=align_and_focus_args["PreserveEvents"] + group_wksp_in=group_wksp ) Rebin(InputWorkspace=wksp_tmp, OutputWorkspace="wksp_tmp_qrb", @@ -395,12 +388,37 @@ def align_focus_mts(out_wksp, cal_file_name, tof_bin_params, group_wksp_in=None, - pres_events=True): + res_filter_axis=None, + res_filter_min=None, + res_filter_max=None): """The MantidTotalScattering internal version of the align and focus algorithm. Simple enough but does the job just as what it should do. """ wksp_proc = Load(file_name) + if res_filter_axis is not None: + ConvertUnits( + InputWorkspace="wksp_proc", + OutputWorkspace="wksp_proc", + Target=res_filter_axis + ) + + for i, xmin in enumerate(res_filter_min): + xmax = res_filter_max[i] + MaskBins( + InputWorkspace=wksp_proc, + OutputWorkspace=wksp_proc, + Axis=res_filter_axis, + Min=xmin, + Max=xmax + ) + + ConvertUnits( + InputWorkspace="wksp_proc", + OutputWorkspace="wksp_proc", + Target="TOF" + ) + LoadDiffCal( InstrumentName=instr_name, Filename=cal_file_name, diff --git a/total_scattering/reduction/total_scattering_reduction.py b/total_scattering/reduction/total_scattering_reduction.py index 8e0bef5..7a46b43 100644 --- a/total_scattering/reduction/total_scattering_reduction.py +++ b/total_scattering/reduction/total_scattering_reduction.py @@ -1908,7 +1908,7 @@ def TotalScatteringReduction(config: dict = None): OutputWorkspace=sam_corrected) - def out_bragg(form, out_wksp): + def out_bragg(form, out_wksp, manual_grouping=False): """Internal for Bragg pattern output. For the moment, we decided to output both the normalized and unnormalized version of the Bragg pattern and thus we need to call this part twice. @@ -2006,12 +2006,13 @@ def out_bragg(form, out_wksp): Params=tof_binning ) - CropWorkspaceRagged( - InputWorkspace="bo_dummy", - OutputWorkspace="bo_dummy", - Xmin=tmin_limit, - Xmax=tmax_limit - ) + if not manual_grouping: + CropWorkspaceRagged( + InputWorkspace="bo_dummy", + OutputWorkspace="bo_dummy", + Xmin=tmin_limit, + Xmax=tmax_limit + ) if form == "norm": gsas_folder = "GSAS" @@ -2050,7 +2051,7 @@ def out_bragg(form, out_wksp): # which will actually be performed later in STEP-7. ################################################################# if not auto_red: - out_bragg("unnorm", sam_corrected) + out_bragg("unnorm", sam_corrected, manual_grouping=manual_grouping) ################################################################# # STEP 5: Divide by number of atoms in sample @@ -2353,7 +2354,11 @@ def out_bragg(form, out_wksp): if auto_red: return mtd[sam_corrected_norm] - out_bragg("norm", sam_corrected_norm_bragg) + out_bragg( + "norm", + sam_corrected_norm_bragg, + manual_grouping=manual_grouping + ) if final_message: log.warning(final_message)