Skip to content

Commit

Permalink
Re #6151 Ensure backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Nov 26, 2012
1 parent be24626 commit a5daeaf
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class HFIRSANSReduction(PythonAlgorithm):

def PyInit(self):
#TODO: allow for multiple files to be summed
#TODO: allow for input workspace instead of file
self.declareProperty(FileProperty("Filename", "",
action=FileAction.Load, extensions=['xml']))
self.declareProperty("ReductionProperties", "__sans_reduction_properties",
Expand All @@ -25,9 +27,17 @@ def PyExec(self):
property_manager = PropertyManagerDataService.retrieve(property_manager_name)

property_list = [p.name for p in property_manager.getProperties()]


output_msg = ""
# Find the beam center
self.find_beam_center(property_manager)
if "SANSBeamFinderAlgorithm" in property_list:
p=property_manager.getProperty("SANSBeamFinderAlgorithm")
alg=Algorithm.fromString(p.valueAsStr)
if alg.existsProperty("ReductionProperties"):
alg.setProperty("ReductionProperties", property_manager_name)
alg.execute()
if alg.existsProperty("OutputMessage"):
output_msg += alg.getProperty("OutputMessage").value+'\n'

# Load the sample data
if "LoadAlgorithm" not in property_list:
Expand All @@ -38,7 +48,7 @@ def PyExec(self):
alg.setProperty("OutputWorkspace", output_ws)
alg.setProperty("ReductionProperties", property_manager_name)
alg.execute()
output_msg = "Loaded %s\n" % filename
output_msg += "Loaded %s\n" % filename
if alg.existsProperty("OutputMessage"):
output_msg += alg.getProperty("OutputMessage").value

Expand All @@ -48,6 +58,18 @@ def PyExec(self):
# Sample data transmission correction

# Process background data
if "BackgroundFiles" in property_list:
background = property_manager.getProperty("LoadAlgorithm").valueAsStr
background_ws = "__background_%s" % output_ws
p=property_manager.getProperty("LoadAlgorithm")
alg=Algorithm.fromString(p.valueAsStr)
alg.setProperty("Filename", background)
alg.setProperty("OutputWorkspace", background_ws)
alg.setProperty("ReductionProperties", property_manager_name)
alg.execute()
output_msg += "Loaded background %s\n" % background
if alg.existsProperty("OutputMessage"):
output_msg += alg.getProperty("OutputMessage").value

# Background transmission correction

Expand All @@ -56,7 +78,20 @@ def PyExec(self):
# Absolute scale correction

# Compute I(q)

print "----------------------\n\n\n\n"
print property_list
if "IQAlgorithm" in property_list:
print "TEST"
iq_output = output_ws+'_Iq'
p=property_manager.getProperty("IQAlgorithm")
alg=Algorithm.fromString(p.valueAsStr)
alg.setProperty("InputWorkspace", output_ws)
alg.setProperty("OutputWorkspace", iq_output)
alg.setProperty("ReductionProperties", property_manager_name)
alg.execute()
if alg.existsProperty("OutputMessage"):
output_msg += alg.getProperty("OutputMessage").value

# Compute I(qx,qy)

# Save data
Expand All @@ -65,9 +100,6 @@ def PyExec(self):
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
Expand Down Expand Up @@ -113,6 +145,17 @@ def process_data_file(self, workspace):
output_msg += alg.getProperty("OutputMessage").value+'\n'

# Sensitivity correction
if "SensitivityAlgorithm" in property_list:
p=property_manager.getProperty("SensitivityAlgorithm")
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'

return output_msg


Expand Down
151 changes: 150 additions & 1 deletion Code/Mantid/Framework/WorkflowAlgorithms/src/SetupHFIRReduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ See [http://www.mantidproject.org/Reduction_for_HFIR_SANS SANS Reduction] docume
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/ListValidator.h"
#include "MantidAPI/FileProperty.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/RebinParamsValidator.h"
#include <boost/algorithm/string/predicate.hpp>
namespace Mantid
{
Expand Down Expand Up @@ -60,14 +62,34 @@ void SetupHFIRReduction::init()
setPropertyGroup("Wavelength", load_grp);
setPropertyGroup("WavelengthSpread", load_grp);

declareProperty("BackgroundFiles", "", "Background data files");

// Beam center
std::string center_grp = "Beam Center";
declareProperty("FindBeamCenter", false, "If True, the beam center will be calculated");

// Option 1: Set beam center by hand
declareProperty("BeamCenterX", EMPTY_DBL(), "Position of the beam center, in pixel");
declareProperty("BeamCenterY", EMPTY_DBL(), "Position of the beam center, in pixel");

// Option 2: Find it (expose properties from FindCenterOfMass)
declareProperty(new API::FileProperty("BeamCenterFile", "", API::FileProperty::OptionalLoad, ".xml"),
"The name of the input data file to load");
//declareProperty("Tolerance", EMPTY_DBL(), "Tolerance on the center of mass position between each iteration [m]. Default: 0.00125");
auto positiveDouble = boost::make_shared<BoundedValidator<double> >();
positiveDouble->setLower(0);
declareProperty("UseDirectBeamMethod", true, "If true, the direct beam method will be used");
declareProperty("BeamRadius", EMPTY_DBL(),
"Radius of the beam area used the exclude the beam when calculating "
"the center of mass of the scattering pattern [pixels]. Default=3.0");

setPropertyGroup("FindBeamCenter", center_grp);
setPropertyGroup("BeamCenterX", center_grp);
setPropertyGroup("BeamCenterY", center_grp);
setPropertyGroup("BeamCenterFile", center_grp);
//setPropertyGroup("Tolerance", center_grp);
setPropertyGroup("UseDirectBeamMethod", center_grp);
setPropertyGroup("BeamRadius", center_grp);

// Normalisation
std::vector<std::string> incidentBeamNormOptions;
Expand All @@ -82,6 +104,54 @@ void SetupHFIRReduction::init()
declareProperty(new API::FileProperty("DarkCurrentFile", "", API::FileProperty::OptionalLoad, ".xml"),
"The name of the input data file to load as dark current.");

// Sensitivity
std::string eff_grp = "Sensitivity";
declareProperty(new API::FileProperty("SensitivityFile", "", API::FileProperty::OptionalLoad, ".xml"),
"Flood field or sensitivity file.");
declareProperty("MinEfficiency", EMPTY_DBL(), positiveDouble,
"Minimum efficiency for a pixel to be considered (default: no minimum).");
declareProperty("MaxEfficiency", EMPTY_DBL(), positiveDouble,
"Maximum efficiency for a pixel to be considered (default: no maximum).");
declareProperty("UseDefaultDC", true, "If true, the dark current subtracted from the sample data will also be subtracted from the flood field.");
declareProperty(new API::FileProperty("SensitivityDarkCurrentFile", "", API::FileProperty::OptionalLoad, ".xml"),
"The name of the input file to load as dark current.");
declareProperty("SensitivityBeamCenterX", EMPTY_DBL(), "Position of the beam center for the sensitivity data, in pixel");
declareProperty("SensitivityBeamCenterY", EMPTY_DBL(), "Position of the beam center for the sensitivity data, in pixel");
declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputSensitivityWorkspace","", Direction::Output, PropertyMode::Optional));

setPropertyGroup("SensitivityFile", eff_grp);
setPropertyGroup("MinEfficiency", eff_grp);
setPropertyGroup("MaxEfficiency", eff_grp);
setPropertyGroup("UseDefaultDC", eff_grp);
setPropertyGroup("SensitivityDarkCurrentFile", eff_grp);
setPropertyGroup("SensitivityBeamCenterX", eff_grp);
setPropertyGroup("SensitivityBeamCenterY", eff_grp);
setPropertyGroup("OutputSensitivityWorkspace", eff_grp);

// I(Q) calculation
std::string iq1d_grp = "I(q) calculation";
declareProperty("DoAzimuthalAverage", true);
declareProperty(new ArrayProperty<double>("IQBinning", boost::make_shared<RebinParamsValidator>(true)));

auto positiveInt = boost::make_shared<BoundedValidator<int> >();
positiveInt->setLower(0);
declareProperty("IQNumberOfBins", 100, positiveInt,
"Number of I(q) bins when binning is not specified.");
declareProperty("IQLogBinning", false,
"I(q) log binning when binning is not specified.");

declareProperty("NumberOfSubpixels", 1, positiveInt,
"Number of sub-pixels used for each detector pixel in each direction."
"The total number of sub-pixels will be NPixelDivision*NPixelDivision.");
declareProperty("ErrorWeighting", false,
"Choose whether each pixel contribution will be weighted by 1/error^2.");
setPropertyGroup("DoAzimuthalAverage", iq1d_grp);
setPropertyGroup("IQBinning", iq1d_grp);
setPropertyGroup("IQNumberOfBins", iq1d_grp);
setPropertyGroup("IQLogBinning", iq1d_grp);
setPropertyGroup("NumberOfSubpixels", iq1d_grp);
setPropertyGroup("ErrorWeighting", iq1d_grp);

declareProperty("OutputMessage","",Direction::Output);
declareProperty("ReductionProperties","__sans_reduction_properties", Direction::Input);
}
Expand Down Expand Up @@ -123,7 +193,29 @@ void SetupHFIRReduction::exec()
const double beamCenterX = getProperty("BeamCenterX");
const double beamCenterY = getProperty("BeamCenterY");
const bool calcBeamCenter = getProperty("FindBeamCenter");
if (!calcBeamCenter)
if (calcBeamCenter)
{
const std::string beamCenterFile = getProperty("BeamCenterFile");
if (beamCenterFile.size()>0)
{
const bool useDirectBeamMethod = getProperty("UseDirectBeamMethod");
const double beamRadius = getProperty("BeamRadius");

IAlgorithm_sptr ctrAlg = createSubAlgorithm("SANSBeamFinder");
ctrAlg->setProperty("Filename", beamCenterFile);
ctrAlg->setProperty("UseDirectBeamMethod", useDirectBeamMethod);
if (!isEmpty(beamRadius)) ctrAlg->setProperty("BeamRadius", beamRadius);
ctrAlg->setPropertyValue("ReductionProperties", reductionManagerName);

algProp = new AlgorithmProperty("SANSBeamFinderAlgorithm");
algProp->setValue(ctrAlg->toString());
reductionManager->declareProperty(algProp);
} else {
g_log.error() << "ERROR: Beam center determination was required"
" but no file was provided" << std::endl;
}

} else if (!isEmpty(beamCenterX) && !isEmpty(beamCenterY))
{
reductionManager->declareProperty(new PropertyWithValue<double>("LatestBeamCenterX", beamCenterX) );
reductionManager->declareProperty(new PropertyWithValue<double>("LatestBeamCenterY", beamCenterY) );
Expand Down Expand Up @@ -171,6 +263,63 @@ void SetupHFIRReduction::exec()
reductionManager->declareProperty(algProp);
}

// Sensitivity correction
const std::string sensitivityFile = getPropertyValue("SensitivityFile");
if (sensitivityFile.size() > 0)
{
const bool useSampleDC = getProperty("UseDefaultDC");
const std::string sensitivityDarkCurrentFile = getPropertyValue("SensitivityDarkCurrentFile");
const std::string outputSensitivityWS = getPropertyValue("OutputSensitivityWorkspace");
const double minEff = getProperty("MinEfficiency");
const double maxEff = getProperty("MaxEfficiency");
const double sensitivityBeamCenterX = getProperty("SensitivityBeamCenterX");
const double sensitivityBeamCenterY = getProperty("SensitivityBeamCenterY");

IAlgorithm_sptr effAlg = createSubAlgorithm("SANSSensitivityCorrection");
effAlg->setProperty("Filename", sensitivityFile);
effAlg->setProperty("UseSampleDC", useSampleDC);
effAlg->setProperty("DarkCurrentFile", sensitivityDarkCurrentFile);
effAlg->setProperty("MinEfficiency", minEff);
effAlg->setProperty("MaxEfficiency", maxEff);
if (!isEmpty(sensitivityBeamCenterX)) effAlg->setProperty("BeamCenterX", sensitivityBeamCenterX);
if (!isEmpty(sensitivityBeamCenterY)) effAlg->setProperty("BeamCenterY", sensitivityBeamCenterY);
effAlg->setProperty("OutputSensitivityWorkspace", outputSensitivityWS);
effAlg->setPropertyValue("ReductionProperties", reductionManagerName);

algProp = new AlgorithmProperty("SensitivityAlgorithm");
algProp->setValue(effAlg->toString());
reductionManager->declareProperty(algProp);
}

// Background
const std::string backgroundFile = getProperty("BackgroundFiles");
if (backgroundFile.size() > 0)
reductionManager->declareProperty(new PropertyWithValue<std::string>("BackgroundFiles", backgroundFile) );

// Azimuthal averaging
const bool doAveraging = getProperty("DoAzimuthalAverage");
if (doAveraging)
{
const std::string binning = getPropertyValue("IQBinning");
const std::string n_bins = getPropertyValue("IQNumberOfBins");
const bool log_binning = getProperty("IQLogBinning");
const std::string n_subpix = getPropertyValue("NumberOfSubpixels");
const bool err_weighting = getProperty("ErrorWeighting");

IAlgorithm_sptr iqAlg = createSubAlgorithm("SANSAzimuthalAverage1D");
iqAlg->setPropertyValue("Binning", binning);
iqAlg->setPropertyValue("NumberOfBins", n_bins);
iqAlg->setProperty("LogBinning", log_binning);
iqAlg->setPropertyValue("NumberOfSubpixels", n_subpix);
iqAlg->setProperty("ErrorWeighting", err_weighting);
iqAlg->setPropertyValue("ReductionProperties", reductionManagerName);

algProp = new AlgorithmProperty("IQAlgorithm");
algProp->setValue(iqAlg->toString());
g_log.information() << iqAlg->toString() << std::endl;
reductionManager->declareProperty(algProp);
}

setPropertyValue("OutputMessage", "HFIR reduction options set");
}

Expand Down

0 comments on commit a5daeaf

Please sign in to comment.