Skip to content

Commit

Permalink
manual group compatible with new align and focus
Browse files Browse the repository at this point in the history
  • Loading branch information
y8z committed Sep 30, 2024
1 parent b03c5ce commit 06703d8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,6 @@ conda_build/

# vscode settings
total_scattering/.vscode
.linenoteplus
settings.json
.vscode/
42 changes: 30 additions & 12 deletions total_scattering/file_handling/load.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from mantid import mtd
from mantid.simpleapi import \
AlignAndFocusPowderFromFiles, \
ApplyDiffCal, \
ConvertUnits, \
DeleteWorkspace, \
Expand All @@ -10,6 +9,7 @@
Load, \
LoadDetectorsGroupingFile, \
LoadDiffCal, \
MaskBins, \
MaskDetectors, \
MultipleScatteringCorrection, \
NormaliseByCurrent, \
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 14 additions & 9 deletions total_scattering/reduction/total_scattering_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 06703d8

Please sign in to comment.