-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re #6151 Add normalisation algo and stub for HFIR reduction
- Loading branch information
Showing
3 changed files
with
242 additions
and
8 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Code/Mantid/Framework/PythonAPI/PythonAlgorithms/WorkflowAlgorithms/HFIRSANSNormalise.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""*WIKI* | ||
Normalise the data to timer or a spectrum, typically a monitor, | ||
with in the workspace. By default the Normalisation is done with | ||
respect to the Instrument's incident monitor | ||
*WIKI*""" | ||
from mantid.api import * | ||
from mantid.kernel import * | ||
|
||
class HFIRSANSNormalise(PythonAlgorithm): | ||
|
||
def PyInit(self): | ||
self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "", | ||
direction = Direction.Input)) | ||
|
||
self.declareProperty("NormalisationType", "Monitor", | ||
StringListValidator(["Monitor", "Timer"]), | ||
doc="Type of Normalisation to use") | ||
|
||
self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "", | ||
direction = Direction.Output)) | ||
|
||
self.declareProperty("OutputMessage", "", direction=Direction.Output) | ||
|
||
def PyExec(self): | ||
input_ws = self.getPropertyValue("InputWorkspace") | ||
output_ws = self.getPropertyValue("OutputWorkspace") | ||
Normalisation = self.getPropertyValue("NormalisationType") | ||
|
||
# Get the monitor or timer | ||
ws = AnalysisDataService.retrieve(input_ws) | ||
norm_count = ws.getRun().getProperty(Normalisation.lower()).value | ||
print norm_count | ||
|
||
if Normalisation=="Monitor": | ||
factor = 1.0e8/norm_count | ||
else: | ||
factor = 1.0/norm_count | ||
|
||
alg = AlgorithmManager.create("Scale") | ||
alg.initialize() | ||
alg.setPropertyValue("InputWorkspace", input_ws) | ||
alg.setPropertyValue("OutputWorkspace", output_ws) | ||
alg.setProperty("Factor", factor) | ||
alg.setProperty("Operation", "Multiply") | ||
|
||
self.setPropertyValue("OutputWorkspace", output_ws) | ||
self.setProperty("OutputMessage", | ||
"Normalisation by %s: %6.2g" % (Normalisation, norm_count)) | ||
|
||
############################################################################################# | ||
|
||
registerAlgorithm(HFIRSANSNormalise) |
121 changes: 121 additions & 0 deletions
121
Code/Mantid/Framework/PythonAPI/PythonAlgorithms/WorkflowAlgorithms/HFIRSANSReduction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
"""*WIKI* | ||
*WIKI*""" | ||
from mantid.api import * | ||
from mantid.kernel import * | ||
|
||
class HFIRSANSReduction(PythonAlgorithm): | ||
|
||
def PyInit(self): | ||
self.declareProperty(FileProperty("Filename", "", | ||
action=FileAction.Load, extensions=['xml'])) | ||
self.declareProperty("ReductionProperties", "__sans_reduction_properties", | ||
validator=StringMandatoryValidator(), | ||
doc="Property manager name for the reduction") | ||
self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "", | ||
direction = Direction.Output), | ||
"Reduced workspace") | ||
self.declareProperty("OutputMessage", "", | ||
direction=Direction.Output, doc = "Output message") | ||
|
||
def PyExec(self): | ||
filename = self.getProperty("Filename").value | ||
output_ws = self.getPropertyValue("OutputWorkspace") | ||
property_manager_name = self.getProperty("ReductionProperties").value | ||
property_manager = PropertyManagerDataService.retrieve(property_manager_name) | ||
|
||
property_list = [p.name for p in property_manager.getProperties()] | ||
|
||
# Find the beam center | ||
self.find_beam_center(property_manager) | ||
|
||
# Load the sample data | ||
if "LoadAlgorithm" not in property_list: | ||
raise RuntimeError, "HFIR SANS reduction not set up properly: missing load algorithm" | ||
p=property_manager.getProperty("LoadAlgorithm") | ||
alg=Algorithm.fromString(p.valueAsStr) | ||
alg.setProperty("Filename", filename) | ||
alg.setProperty("OutputWorkspace", output_ws) | ||
alg.setProperty("ReductionProperties", property_manager_name) | ||
alg.execute() | ||
output_msg = "Loaded %s\n" % filename | ||
if alg.existsProperty("OutputMessage"): | ||
output_msg += alg.getProperty("OutputMessage").value | ||
|
||
# Perform the main corrections on the sample data | ||
output_msg += self.process_data_file(output_ws) | ||
|
||
# Sample data transmission correction | ||
|
||
# Process background data | ||
|
||
# Background transmission correction | ||
|
||
# Subtract background | ||
|
||
# Absolute scale correction | ||
|
||
# Compute I(q) | ||
|
||
# Compute I(qx,qy) | ||
|
||
# Save data | ||
|
||
|
||
self.setPropertyValue("OutputWorkspace", output_ws) | ||
self.setProperty("OutputMessage", output_msg) | ||
|
||
def find_beam_center(self, property_manager): | ||
pass | ||
|
||
def process_data_file(self, workspace): | ||
output_msg = "" | ||
property_manager_name = self.getProperty("ReductionProperties").value | ||
property_manager = PropertyManagerDataService.retrieve(property_manager_name) | ||
property_list = [p.name for p in property_manager.getProperties()] | ||
|
||
# Dark current subtraction | ||
if "DarkCurrentAlgorithm" in property_list: | ||
p=property_manager.getProperty("DarkCurrentAlgorithm") | ||
alg=Algorithm.fromString(p.valueAsStr) | ||
alg.setProperty("InputWorkspace", workspace) | ||
alg.setProperty("OutputWorkspace", workspace) | ||
if alg.existsProperty("ReductionProperties"): | ||
alg.setProperty("ReductionProperties", property_manager_name) | ||
alg.execute() | ||
if alg.existsProperty("OutputMessage"): | ||
output_msg += alg.getProperty("OutputMessage").value+'\n' | ||
|
||
# Normalize | ||
if "NormaliseAlgorithm" in property_list: | ||
p=property_manager.getProperty("NormaliseAlgorithm") | ||
alg=Algorithm.fromString(p.valueAsStr) | ||
alg.setProperty("InputWorkspace", workspace) | ||
alg.setProperty("OutputWorkspace", workspace) | ||
if alg.existsProperty("ReductionProperties"): | ||
alg.setProperty("ReductionProperties", property_manager_name) | ||
alg.execute() | ||
if alg.existsProperty("OutputMessage"): | ||
output_msg += alg.getProperty("OutputMessage").value+'\n' | ||
|
||
# Mask | ||
|
||
# Solid angle correction | ||
if "SANSSolidAngleCorrection" in property_list: | ||
p=property_manager.getProperty("SANSSolidAngleCorrection") | ||
alg=Algorithm.fromString(p.valueAsStr) | ||
alg.setProperty("InputWorkspace", workspace) | ||
alg.setProperty("OutputWorkspace", workspace) | ||
if alg.existsProperty("ReductionProperties"): | ||
alg.setProperty("ReductionProperties", property_manager_name) | ||
alg.execute() | ||
if alg.existsProperty("OutputMessage"): | ||
output_msg += alg.getProperty("OutputMessage").value+'\n' | ||
|
||
# Sensitivity correction | ||
return output_msg | ||
|
||
|
||
############################################################################################# | ||
|
||
registerAlgorithm(HFIRSANSReduction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters