Skip to content

Commit

Permalink
Re #6151 Add I(qx,qy) to API2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Dec 18, 2012
1 parent 3859900 commit 90911e2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def PyInit(self):
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("OutputWorkspace", "",
doc="Reduced workspace")
self.declareProperty("OutputMessage", "",
direction=Direction.Output, doc = "Output message")

Expand Down Expand Up @@ -95,7 +94,7 @@ def _load_data(filename, output_ws):
def PyExec(self):
filename = self.getProperty("Filename").value
output_ws = self.getPropertyValue("OutputWorkspace")
output_ws = '__'+output_ws+'_reduced'
#output_ws = '__'+output_ws+'_reduced'
property_manager_name = self.getProperty("ReductionProperties").value
property_manager = PropertyManagerDataService.retrieve(property_manager_name)

Expand Down Expand Up @@ -230,19 +229,32 @@ def PyExec(self):

# Compute I(qx,qy)
iqxy_output = None
if "IQXYAlgorithm" in property_list:
iq_output_name = self.getPropertyValue("OutputWorkspace")
iqxy_output = iq_output_name+'_Iqxy'
p=property_manager.getProperty("IQXYAlgorithm")
alg=Algorithm.fromString(p.valueAsStr)
alg.setProperty("InputWorkspace", output_ws)
alg.setProperty("OutputWorkspace", iq_output_name)
if alg.existsProperty("ReductionProperties"):
alg.setProperty("ReductionProperties", property_manager_name)
alg.execute()
if alg.existsProperty("OutputMessage"):
output_msg += alg.getProperty("OutputMessage").value

# Verify output directory and save data
if "OutputDirectory" in property_list:
output_dir = property_manager.getProperty("OutputDirectory").value
if len(output_dir)==0:
output_dir = os.path.dirname(filename)
if os.path.isdir(output_dir):
output_msg += self._save_output(iq_output, iqxy_output,
output_dir, property_manager)
Logger.get("HFIRSANSReduction").notice("Output saved in %s" % output_dir)
elif len(output_dir)>0:
msg = "Output directory doesn't exist: %s\n" % output_dir
Logger.get("HFIRSANSReduction").error(msg)
Logger.get("HFIRSANSReduction").error(msg)

ws = AnalysisDataService.retrieve(output_ws)
self.setProperty("OutputWorkspace", ws)
self.setProperty("OutputMessage", output_msg)

def process_data_file(self, workspace):
Expand Down Expand Up @@ -376,7 +388,13 @@ def _save_output(self, iq_output, iqxy_output, output_dir, property_manager):
if iqxy_output is not None:
if AnalysisDataService.doesExist(iqxy_output):
filename = os.path.join(output_dir, iqxy_output+'.dat')
api.SaveNISTDAT(InputWorkspace=iqxy_output, Filename=filename)
alg = AlgorithmManager.create("SaveNISTDAT")
alg.initialize()
alg.setChild(True)
alg.setProperty("Filename", filename)
alg.setProperty("InputWorkspace", iqxy_output)
alg.execute()
#api.SaveNISTDAT(InputWorkspace=iqxy_output, Filename=filename)
output_msg += "I(Qx,Qy) saved in %s\n" % (filename)
else:
Logger.get("HFIRSANSReduction").error("No I(Qx,Qy) output found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ void SetupHFIRReduction::init()
"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.");

declareProperty("Do2DReduction", true);
declareProperty("IQ2DNumberOfBins", 100, positiveInt,
"Number of I(qx,qy) bins.");

setPropertyGroup("DoAzimuthalAverage", iq1d_grp);
setPropertyGroup("IQBinning", iq1d_grp);
setPropertyGroup("IQNumberOfBins", iq1d_grp);
Expand Down Expand Up @@ -702,7 +707,18 @@ void SetupHFIRReduction::exec()

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

// 2D reduction
const bool do2DReduction = getProperty("Do2DReduction");
if (do2DReduction)
{
const std::string n_bins = getPropertyValue("IQ2DNumberOfBins");
IAlgorithm_sptr iqAlg = createSubAlgorithm("EQSANSQ2D");
iqAlg->setPropertyValue("NumberOfBins", n_bins);
algProp = new AlgorithmProperty("IQXYAlgorithm");
algProp->setValue(iqAlg->toString());
reductionManager->declareProperty(algProp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ def DirectBeamCenter(datafile):
find_data(datafile, instrument=ReductionSingleton().get_instrument())
ReductionSingleton().reduction_properties["BeamCenterMethod"]="DirectBeam"
ReductionSingleton().reduction_properties["BeamCenterFile"]=datafile
ReductionSingleton().reduction_properties["BeamCenterPersistent"]=True

def ScatteringBeamCenter(datafile, beam_radius=3.0):
find_data(datafile, instrument=ReductionSingleton().get_instrument())
ReductionSingleton().reduction_properties["BeamCenterMethod"]="Scattering"
ReductionSingleton().reduction_properties["BeamRadius"]=beam_radius
ReductionSingleton().reduction_properties["BeamCenterFile"]=datafile
ReductionSingleton().reduction_properties["BeamCenterPersistent"]=True

def SetBeamCenter(x,y):
ReductionSingleton().reduction_properties["BeamCenterMethod"]="Value"
Expand Down Expand Up @@ -89,14 +87,16 @@ def SensitivityScatteringBeamCenter(datafile, beam_radius=3.0):
ReductionSingleton().reduction_properties["SensitivityBeamCenterFile"]=datafile

def NoSensitivityCorrection():
ReductionSingleton().reduction_properties["SensitivityFile"] = None
if ReductionSingleton().reduction_properties.has_key("SensitivityFile"):
del ReductionSingleton().reduction_properties["SensitivityFile"]

def DarkCurrent(datafile):
datafile = find_data(datafile, instrument=ReductionSingleton().get_instrument())
ReductionSingleton().reduction_properties["DarkCurrentFile"] = datafile

def NoDarkCurrent():
ReductionSingleton().reduction_properties["DarkCurrentFile"] = None
if ReductionSingleton().reduction_properties.has_key("DarkCurrentFile"):
del ReductionSingleton().reduction_properties["DarkCurrentFile"]

def SolidAngle(detector_tubes=False):
ReductionSingleton().reduction_properties["SolidAngleCorrection"]=True
Expand Down Expand Up @@ -276,24 +276,25 @@ def SetWavelength(wavelength, spread):

def ResetWavelength():
""" Resets the wavelength to the data file default """
ReductionSingleton().reduction_properties["Wavelength"] = None
ReductionSingleton().reduction_properties["WavelengthSpread"] = None
if ReductionSingleton().reduction_properties.has_key("Wavelength"):
del ReductionSingleton().reduction_properties["Wavelength"]
if ReductionSingleton().reduction_properties.has_key("WavelengthSpread"):
del ReductionSingleton().reduction_properties["WavelengthSpread"]

def SaveIq(output_dir='', process=''):
ReductionSingleton().reduction_properties["OutputDirectory"] = output_dir
ReductionSingleton().reduction_properties["ProcessInfo"] = process

def NoSaveIq():
if ReductionSingleton().reduction_properties.has_key("OutputDirectory"):
del ReductionSingleton().reduction_properties["OutputDirectory"]
if ReductionSingleton().reduction_properties.has_key("OutputDirectory"):
del ReductionSingleton().reduction_properties["OutputDirectory"]

def IQxQy(nbins=100):
print "I(QxQy)"
#ReductionSingleton().set_IQxQy(mantidsimple.EQSANSQ2D, InputWorkspace=None,
# NumberOfBins=nbins)
ReductionSingleton().reduction_properties["Do2DReduction"] = True
ReductionSingleton().reduction_properties["IQ2DNumberOfBins"] = nbins

def NoIQxQy(nbins=100):
ReductionSingleton().set_IQxQy(None)
def NoIQxQy():
ReductionSingleton().reduction_properties["Do2DReduction"] = False

def Mask(nx_low=0, nx_high=0, ny_low=0, ny_high=0):
ReductionSingleton().reduction_properties["MaskedEdges"] = [nx_low, nx_high,
Expand Down

0 comments on commit 90911e2

Please sign in to comment.