Skip to content

Commit

Permalink
Improve property validation
Browse files Browse the repository at this point in the history
Refs #11188
  • Loading branch information
DanNixon committed Feb 27, 2015
1 parent a84ca45 commit 3845f94
Showing 1 changed file with 37 additions and 15 deletions.
@@ -1,7 +1,8 @@
from mantid.simpleapi import *
from mantid.api import PythonAlgorithm, AlgorithmFactory, PropertyMode, StringMandatoryValidator,\
MatrixWorkspaceProperty, WorkspaceGroupProperty
from mantid.kernel import StringListValidator, Direction, logger
from mantid.api import PythonAlgorithm, AlgorithmFactory, PropertyMode, MatrixWorkspaceProperty, \
WorkspaceGroupProperty
from mantid.kernel import StringListValidator, StringMandatoryValidator, IntBoundedValidator, \
FloatBoundedValidator, Direction, logger
import math, numpy as np


Expand Down Expand Up @@ -39,47 +40,68 @@ def summary(self):
def PyInit(self):
self.declareProperty(MatrixWorkspaceProperty('SampleWorkspace', '',
direction=Direction.Input),
doc='Name for the input Sample workspace.')
doc='Name for the input sample workspace')

self.declareProperty(name='SampleChemicalFormula', defaultValue='',
validator=StringMandatoryValidator(),
doc='Sample chemical formula')
self.declareProperty(name='SampleNumberDensity', defaultValue=0.1,
doc='Sample number density')
validator=FloatBoundedValidator(0.0),
doc='Sample number density in atoms/Angstrom3')
self.declareProperty(name='SampleThickness', defaultValue=0.0,
doc='Sample thickness')
validator=FloatBoundedValidator(0.0),
doc='Sample thickness in cm')
self.declareProperty(name='SampleAngle', defaultValue=0.0,
doc='Sample angle')
doc='Sample angle in degrees')

self.declareProperty(MatrixWorkspaceProperty('CanWorkspace', '',
direction=Direction.Input,
optional=PropertyMode.Optional),
doc="Name for the input Can workspace.")
doc="Name for the input container workspace")

self.declareProperty(name='CanChemicalFormula', defaultValue='',
doc='Can chemical formula')
doc='Container chemical formula')
self.declareProperty(name='CanNumberDensity', defaultValue=0.1,
doc='Can number density')
validator=FloatBoundedValidator(0.0),
doc='Container number density in atoms/Angstrom3')

self.declareProperty(name='CanFrontThickness', defaultValue=0.0,
doc='Can thickness1 front')
validator=FloatBoundedValidator(0.0),
doc='Container front thickness in cm')
self.declareProperty(name='CanBackThickness', defaultValue=0.0,
doc='Can thickness2 back')
validator=FloatBoundedValidator(0.0),
doc='Container back thickness in cm')

self.declareProperty(name='CanScaleFactor', defaultValue=1.0,
doc='Scale factor to multiply can data')

self.declareProperty(name='NumberWavelengths', defaultValue=10,
validator=IntBoundedValidator(0),
doc='Number of wavelengths for calculation')
self.declareProperty(name='Emode', defaultValue='Elastic',
validator=StringListValidator(['Elastic','Indirect']),
validator=StringListValidator(['Elastic', 'Indirect']),
doc='Emode: Elastic or Indirect')
self.declareProperty(name='Efixed', defaultValue=0.0,
doc='Efixed - analyser energy')
doc='Analyser energy')

self.declareProperty(WorkspaceGroupProperty('OutputWorkspace', '',
direction=Direction.Output),
doc='The output corrections workspace group.')
doc='The output corrections workspace group')


def validateInputs(self):
issues = dict()

can_ws_name = self.getPropertyValue('CanWorkspace')
use_can = can_ws_name != ''

# Ensure that a can chemical formula is given when using a can workspace
if use_can:
can_chemical_formula = self.getPropertyValue('CanChemicalFormula')
if can_chemical_formula == '':
issues['CanChemicalFormula'] = 'Must provide a chemical foruma when providing a can workspace'

return issues


def PyExec(self):
Expand Down

0 comments on commit 3845f94

Please sign in to comment.