Skip to content

Commit

Permalink
Add refactored algorithm Refs #11859
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed May 27, 2015
1 parent ac0262a commit 102ca4a
Show file tree
Hide file tree
Showing 2 changed files with 584 additions and 15 deletions.
@@ -1,10 +1,14 @@
#pylint: disable=no-init,too-many-locals,too-many-instance-attributes

from mantid.simpleapi import *
from mantid.api import PythonAlgorithm, AlgorithmFactory, PropertyMode, MatrixWorkspaceProperty, \
WorkspaceGroupProperty, InstrumentValidator, WorkspaceUnitValidator
from mantid.kernel import StringListValidator, StringMandatoryValidator, IntBoundedValidator, \
FloatBoundedValidator, Direction, logger, CompositeValidator
from mantid.api import (PythonAlgorithm, AlgorithmFactory, PropertyMode, MatrixWorkspaceProperty,
WorkspaceGroupProperty, InstrumentValidator, WorkspaceUnitValidator)
from mantid.kernel import (StringListValidator, StringMandatoryValidator,
FloatBoundedValidator, Direction, logger, CompositeValidator)
from mantid import config
import math, os.path, numpy as np

import math
import numpy as np


class CylinderPaalmanPingsCorrection(PythonAlgorithm):
Expand All @@ -24,15 +28,23 @@ class CylinderPaalmanPingsCorrection(PythonAlgorithm):
_emode = None
_efixed = 0.0
_output_ws_name = None
_use_can = None
_beam_height = None
_beam_width = None
_interpolate = None
_angles = None
_waves = None
_elastic = None

#------------------------------------------------------------------------------

def category(self):
return "Workflow\\MIDAS;PythonAlgorithms;CorrectionFunctions\\AbsorptionCorrections"


def summary(self):
return "Calculates absorption corrections for a cylindrical or annular sample using Paalman & Pings format."

#------------------------------------------------------------------------------

def PyInit(self):
ws_validator = CompositeValidator([WorkspaceUnitValidator('Wavelength'), InstrumentValidator()])
Expand Down Expand Up @@ -88,6 +100,7 @@ def PyInit(self):
direction=Direction.Output),
doc='The output corrections workspace group')

#------------------------------------------------------------------------------

def PyExec(self):

Expand Down Expand Up @@ -211,6 +224,7 @@ def PyExec(self):
GroupWorkspaces(InputWorkspaces=','.join(workspaces), OutputWorkspace=self._output_ws_name)
self.setPropertyValue('OutputWorkspace', self._output_ws_name)

#------------------------------------------------------------------------------

def validateInputs(self):
self._setup()
Expand All @@ -229,6 +243,7 @@ def validateInputs(self):

return issues

#------------------------------------------------------------------------------

def _setup(self):
"""
Expand Down Expand Up @@ -264,6 +279,7 @@ def _setup(self):

self._output_ws_name = self.getPropertyValue('OutputWorkspace')

#------------------------------------------------------------------------------

def _get_angles(self):
"""
Expand All @@ -280,6 +296,7 @@ def _get_angles(self):
two_theta = detector.getTwoTheta(sample_pos, beam_pos) * 180.0 / math.pi # calc angle
self._angles.append(two_theta)

#------------------------------------------------------------------------------

def _wave_range(self):
wave_range = '__WaveRange'
Expand All @@ -302,6 +319,7 @@ def _wave_range(self):
logger.information('Elastic lambda %f' % self._elastic)
DeleteWorkspace(wave_range)

#------------------------------------------------------------------------------

def _interpolate_corrections(self, workspaces):
"""
Expand All @@ -311,12 +329,13 @@ def _interpolate_corrections(self, workspaces):
@param workspaces List of correction workspaces to interpolate
"""

for ws in workspaces:
for wrksp in workspaces:
SplineInterpolation(WorkspaceToMatch=self._sample_ws_name,
WorkspaceToInterpolate=ws,
OutputWorkspace=ws,
WorkspaceToInterpolate=wrksp,
OutputWorkspace=wrksp,
OutputWorkspaceDeriv='')

#------------------------------------------------------------------------------

def _copy_detector_table(self, workspaces):
"""
Expand All @@ -327,22 +346,23 @@ def _copy_detector_table(self, workspaces):

instrument = mtd[self._sample_ws_name].getInstrument().getName()

for ws in workspaces:
LoadInstrument(Workspace=ws,
for wrksp in workspaces:
LoadInstrument(Workspace=wrksp,
InstrumentName=instrument)

CopyDetectorMapping(WorkspaceToMatch=self._sample_ws_name,
WorkspaceToRemap=ws,
WorkspaceToRemap=wrksp,
IndexBySpectrumNumber=True)

#------------------------------------------------------------------------------

def _add_sample_logs(self, ws, sample_logs):
def _add_sample_logs(self, wrksp, sample_logs):
"""
Add a dictionary of logs to a workspace.
The type of the log is inferred by the type of the value passed to the log.
@param ws - workspace to add logs too.
@param wrksp - workspace to add logs too.
@param sample_logs - dictionary of logs to append to the workspace.
"""

Expand All @@ -354,8 +374,9 @@ def _add_sample_logs(self, ws, sample_logs):
else:
log_type = 'String'

AddSampleLog(Workspace=ws, LogName=key, LogType=log_type, LogText=str(value))
AddSampleLog(Workspace=wrksp, LogName=key, LogType=log_type, LogText=str(value))

#------------------------------------------------------------------------------

# Register algorithm with Mantid
AlgorithmFactory.subscribe(CylinderPaalmanPingsCorrection)

0 comments on commit 102ca4a

Please sign in to comment.