def test_creation_with_constructor_and_list(self): """ Tests that a composite validator created with the constructor method """ validation = CompositeValidator( [FloatBoundedValidator(lower=5), FloatBoundedValidator(upper=10)]) self._do_validation_test(validation)
def test_creation_with_add_succeeds_correctly_in_algorithm(self): """ Tests that a composite validator created with the add method validates correctly """ validation = CompositeValidator() validation.add(FloatBoundedValidator(lower=5)) validation.add(FloatBoundedValidator(upper=10)) self._do_validation_test(validation)
def PyInit(self): ws_validator = CompositeValidator([WorkspaceUnitValidator('Wavelength'), InstrumentValidator()]) self.declareProperty(MatrixWorkspaceProperty('SampleWorkspace', '', direction=Direction.Input, validator=ws_validator), 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, validator=FloatBoundedValidator(0.0), doc='Sample number density in atoms/Angstrom3') self.declareProperty(name='SampleThickness', defaultValue=0.0, validator=FloatBoundedValidator(0.0), doc='Sample thickness in cm') self.declareProperty(name='SampleAngle', defaultValue=0.0, doc='Sample angle in degrees') self.declareProperty(MatrixWorkspaceProperty('CanWorkspace', '', direction=Direction.Input, optional=PropertyMode.Optional, validator=ws_validator), doc="Name for the input container workspace") self.declareProperty(name='CanChemicalFormula', defaultValue='', doc='Container chemical formula') self.declareProperty(name='CanNumberDensity', defaultValue=0.1, validator=FloatBoundedValidator(0.0), doc='Container number density in atoms/Angstrom3') self.declareProperty(name='CanFrontThickness', defaultValue=0.0, validator=FloatBoundedValidator(0.0), doc='Container front thickness in cm') self.declareProperty(name='CanBackThickness', defaultValue=0.0, validator=FloatBoundedValidator(0.0), doc='Container back thickness in cm') self.declareProperty(name='NumberWavelengths', defaultValue=10, validator=IntBoundedValidator(1), doc='Number of wavelengths for calculation') self.declareProperty(name='Interpolate', defaultValue=True, doc='Interpolate the correction workspaces to match the sample workspace') self.declareProperty(name='Emode', defaultValue='Elastic', validator=StringListValidator(['Elastic', 'Indirect']), doc='Emode: Elastic or Indirect') self.declareProperty(name='Efixed', defaultValue=1.0, doc='Analyser energy') self.declareProperty(WorkspaceGroupProperty('OutputWorkspace', '', direction=Direction.Output), doc='The output corrections workspace group')
def PyInit(self): ws_validator = CompositeValidator([WorkspaceUnitValidator('Wavelength'), InstrumentValidator()]) self.declareProperty(MatrixWorkspaceProperty('SampleWorkspace', '', direction=Direction.Input, validator=ws_validator), 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, validator=FloatBoundedValidator(0.0), doc='Sample number density in atoms/Angstrom3') self.declareProperty(name='SampleInnerRadius', defaultValue=0.05, doc='Sample inner radius') self.declareProperty(name='SampleOuterRadius', defaultValue=0.1, doc='Sample outer radius') self.declareProperty(MatrixWorkspaceProperty('CanWorkspace', '', direction=Direction.Input, optional=PropertyMode.Optional, validator=ws_validator), doc="Name for the input container workspace") self.declareProperty(name='CanChemicalFormula', defaultValue='', doc='Container chemical formula') self.declareProperty(name='CanNumberDensity', defaultValue=0.1, validator=FloatBoundedValidator(0.0), doc='Container number density in atoms/Angstrom3') self.declareProperty(name='CanOuterRadius', defaultValue=0.15, doc='Can outer radius') self.declareProperty(name='BeamHeight', defaultValue=3.0, doc='Height of the beam at the sample.') self.declareProperty(name='BeamWidth', defaultValue=2.0, doc='Width of the beam at the sample.') self.declareProperty(name='StepSize', defaultValue=0.002, doc='Step size for calculation') self.declareProperty(name='Interpolate', defaultValue=True, doc='Interpolate the correction workspaces to match the sample workspace') self.declareProperty(name='Emode', defaultValue='Elastic', validator=StringListValidator(['Elastic', 'Indirect']), doc='Emode: Elastic or Indirect') self.declareProperty(name='Efixed', defaultValue=1.0, doc='Analyser energy') self.declareProperty(WorkspaceGroupProperty('OutputWorkspace', '', direction=Direction.Output), doc='The output corrections workspace group')
def PyInit(self): validators = CompositeValidator() validators.add(HistogramValidator(True)) validators.add(CommonBinsValidator()) self.declareProperty( MatrixWorkspaceProperty(name='InputWorkspace', defaultValue='', direction=Direction.Input, validator=validators), doc= 'Input MatrixWorkspace containing the reduced inelastic neutron spectrum in (Q,E) or (2theta,E) space.' ) self.declareProperty(name='Temperature', defaultValue=300., validator=FloatBoundedValidator(lower=0), doc='Sample temperature in Kelvin.') self.declareProperty( name='MeanSquareDisplacement', defaultValue=0., validator=FloatBoundedValidator(lower=0), doc='Average mean square displacement in Angstrom^2.') self.declareProperty( name='QSumRange', defaultValue='0,Qmax', doc='Range in Q (in Angstroms^-1) to sum data over.') self.declareProperty( name='EnergyBinning', defaultValue='0,Emax/50,Emax*0.9', doc= 'Energy binning parameters [Emin, Emax] or [Emin, Estep, Emax] in meV.' ) self.declareProperty( name='Wavenumbers', defaultValue=False, doc='Should the output be in Wavenumbers (cm^-1)?') self.declareProperty( name='StatesPerEnergy', defaultValue=False, doc= 'Should the output be in states per unit energy rather than mb/sr/fu/energy?\n' + '(Only for pure elements, need to set the sample material information)' ) self.declareProperty(MatrixWorkspaceProperty( name='OutputWorkspace', defaultValue='', direction=Direction.Output), doc='Output workspace name.') self.declareProperty( name='TwoThetaSumRange', defaultValue='Twothetamin, Twothetamax', doc='Range in 2theta (in degrees) to sum data over.')
def PyInit(self): self.declareProperty(IPeaksWorkspaceProperty( 'Workspace', '', direction=Direction.InOut), doc='Peaks Workspace to be modified') self.declareProperty( "Wavelength", Property.EMPTY_DBL, validator=FloatBoundedValidator(0.0), doc= "Wavelength to set the workspace, will be the value set on workspace if not provided." ) self.declareProperty( "OverrideProperty", False, "If False then the value for InnerGoniometer and FlipX will be determiend from the workspace, " "it True then the properties will be used") condition = VisibleWhenProperty("OverrideProperty", PropertyCriterion.IsNotDefault) self.declareProperty( "InnerGoniometer", False, "Whether the goniometer to be calculated is the most inner (phi) or most outer (omega)" ) self.setPropertySettings("InnerGoniometer", condition) self.declareProperty( "FlipX", False, "Used when calculating goniometer angle if the q_lab x value should be negative, " "hence the detector of the other side (right) of the beam") self.setPropertySettings("FlipX", condition)
def PyInit(self): """ Declare properties """ self.declareProperty( MatrixWorkspaceProperty("VanadiumWorkspace", "", direction=Direction.Input, validator=InstrumentValidator()), "Input Vanadium workspace") self.declareProperty( ITableWorkspaceProperty("EPPTable", "", direction=Direction.Input), ("Input EPP table. May be produced by FindEPP " + "algorithm.")) self.declareProperty( MatrixWorkspaceProperty("OutputWorkspace", "", direction=Direction.Output), ("Name the workspace that will contain the " + "calibration coefficients")) self.declareProperty("Temperature", defaultValue=Property.EMPTY_DBL, validator=FloatBoundedValidator(lower=0.0), direction=Direction.Input, doc=("Temperature during the experiment (in " + "Kelvins) if the 'temperature' sample log " + "is missing or needs to be overriden.")) return
def PyInit(self): self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "", Direction.Input), "Workspace with focussed spectra") self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "", Direction.Output), "Workspace to contain the estimated background (one for each spectrum in the " "InputWorkspace)") self.declareProperty( name="NIterations", defaultValue=40, direction=Direction.Input, validator=IntBoundedValidator(lower=1), doc="Number of iterations of the smoothing procedure to perform. Too few iterations and the background will" " be enhanced in the peak regions. Too many iterations and the background will be unrealistically" " low and not catch the rising edge at low TOF/d-spacing (typical values are in range 20-100).") self.declareProperty( name="XWindow", defaultValue=1000.0, direction=Direction.Input, validator=FloatBoundedValidator(lower=0.0), doc="Extent of the convolution window in the x-axis for all spectra. A reasonable value is about 4-8 times" " the FWHM of a typical peak/feature to be suppressed (default is reasonable for TOF spectra). This is " "converted to an odd number of points using the median bin width of each spectra.") self.declareProperty('ApplyFilterSG', True, direction=Direction.Input, doc='Apply a Savitzky–Golay filter with a linear polynomial over the same XWindow before' ' the iterative smoothing procedure (recommended for noisy data)')
def PyInit(self): """ Declare properties """ self.declareProperty( WorkspaceProperty("Workspace", "", Direction.Input), "Workspace containing MR data") self.declareProperty("AngleOffset", 0., FloatBoundedValidator(lower=0.), "Angle offset (rad)") self.declareProperty( "UseSANGLE", False, doc= "If True, use SANGLE as the scattering angle. If False, use DANGLE." ) self.declareProperty( "SpecularPixel", 0., doc="Pixel position of the specular reflectivity [optional]") self.declareProperty("DirectPixelOverwrite", Property.EMPTY_DBL, doc="DIRPIX overwrite value") self.declareProperty("DAngle0Overwrite", Property.EMPTY_DBL, doc="DANGLE0 overwrite value (degrees)") self.declareProperty("Theta", 0., direction=Direction.Output, doc="Scattering angle theta (rad)") return
def PyInit(self): validator = StringArrayLengthValidator() validator.setLengthMin(1) # one group may be given self.declareProperty( StringArrayProperty(name="InputWorkspaces", direction=Direction.Input, validator=validator), doc="Comma separated list of workspaces or groups of workspaces.") self.declareProperty( StringArrayProperty(name="SampleLogs", direction=Direction.Input, validator=validator), doc="Comma separated list of sample logs to compare.") self.declareProperty("Tolerance", 1e-3, validator=FloatBoundedValidator(lower=1e-7, upper=1.0), doc="Tolerance for comparison of double values.") self.declareProperty( "Result", "A string that will be empty if all the logs match, " "otherwise will contain a comma separated list of not matching logs", Direction.Output) return
def PyInit(self): """ Declare properties """ val=FloatBoundedValidator() val.setBounds(3,100) #reasonable incident nergy range for HYSPEC self.declareProperty("IncidentEnergy",0.,val,"Incident energy (3 to 100 meV)") self.declareProperty("TibMin",0.,Direction.Output) self.declareProperty("TibMax",0.,Direction.Output) return
def test_composite_validator_with_or_relation(self): validation = CompositeValidator([FloatBoundedValidator(lower=5, upper=10), FloatBoundedValidator(lower=15, upper=20)], relation=CompositeRelation.OR) test_alg = self._create_test_algorithm(validation) prop = test_alg.getProperty("Input") self.assertNotEquals(prop.isValid, "") test_alg.setProperty("Input", 6.8) self.assertEqual(prop.isValid, "") test_alg.setProperty("Input", 17.3) self.assertEqual(prop.isValid, "") self.assertRaises(ValueError, test_alg.setProperty, "Input", 3.0) self.assertRaises(ValueError, test_alg.setProperty, "Input", 13.0) self.assertRaises(ValueError, test_alg.setProperty, "Input", 23.0)
def PyInit(self): """Initialize the input and output properties of the algorithm.""" positiveFloat = FloatBoundedValidator(lower=0., exclusive=True) self.declareProperty( MatrixWorkspaceProperty( Prop.INPUT_WS, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator('Wavelength')), doc='A reflectivity workspace in wavelength to be converted to Q.') self.declareProperty(MatrixWorkspaceProperty( Prop.OUTPUT_WS, defaultValue='', direction=Direction.Output), doc='The input workspace in momentum transfer.') self.declareProperty(Prop.SUBALG_LOGGING, defaultValue=SubalgLogging.OFF, validator=StringListValidator( [SubalgLogging.OFF, SubalgLogging.ON]), doc='Enable or disable child algorithm logging.') self.declareProperty( Prop.CLEANUP, defaultValue=common.WSCleanup.ON, validator=StringListValidator( [common.WSCleanup.ON, common.WSCleanup.OFF]), doc='Enable or disable intermediate workspace cleanup.') self.declareProperty( MatrixWorkspaceProperty( Prop.REFLECTED_WS, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator('Wavelength')), doc= 'A non-summed reflected beam workspace, needed for Q resolution calculation.' ) self.declareProperty( MatrixWorkspaceProperty( Prop.DIRECT_WS, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator('Wavelength')), doc= 'A non-summed direct beam workspace, needed for Q resolution calculation.' ) self.declareProperty( Prop.POLARIZED, defaultValue=False, doc= 'True if input workspace has been corrected for polarization efficiencies.' ) self.declareProperty( Prop.GROUPING_FRACTION, defaultValue=Property.EMPTY_DBL, validator=positiveFloat, doc= 'If set, group the output by steps of this fraction multiplied by Q resolution' )
def PyInit(self): self.declareProperty(MatrixWorkspaceProperty( "InputWorkspace", '', direction=Direction.Input), doc='The main input workspace.') self.declareProperty(MatrixWorkspaceProperty( "CalibrationWorkspace", '', optional=PropertyMode.Optional, direction=Direction.Input), doc='The calibration (vandiaum) workspace.') self.declareProperty(MatrixWorkspaceProperty( "BackgroundWorkspace", '', optional=PropertyMode.Optional, direction=Direction.Input), doc='The background workspace to be subtracted.') self.declareProperty( "BackgroundScale", 1.0, validator=FloatBoundedValidator(0.0), doc= "The background will be scaled by this number before being subtracted." ) self.declareProperty( MaskWorkspaceProperty("MaskWorkspace", '', optional=PropertyMode.Optional, direction=Direction.Input), doc='The mask from this workspace will be applied before reduction' ) self.copyProperties('ConvertSpectrumAxis', ['Target', 'EFixed']) self.copyProperties('ResampleX', ['XMin', 'XMax', 'NumberBins', 'LogBinning']) self.declareProperty('NormaliseBy', 'Monitor', StringListValidator(['None', 'Time', 'Monitor']), "Normalise to monitor or time. ") self.declareProperty( 'MaskAngle', Property.EMPTY_DBL, "Phi angle above which will be masked. See :ref:`MaskAngle <algm-MaskAngle>` for details." ) self.declareProperty(MatrixWorkspaceProperty( "OutputWorkspace", "", direction=Direction.Output), doc="Output Workspace")
def PyInit(self): self.declareProperty( WorkspaceProperty(name='InputWorkspace', defaultValue='', direction=Direction.Input), 'Workspace with peaks to be identified') self.declareProperty( ITableWorkspaceProperty(name='PeakGuessTable', defaultValue='peak_guess', direction=Direction.Input), 'Table containing the guess for the peak position') self.declareProperty('CentreTolerance', 1.0, doc='Tolerance value used in looking for peak centre', validator=FloatBoundedValidator(lower=0.0)) self.declareProperty('EstimatedPeakSigma', 3.0, doc='Estimate of the peak half width', validator=FloatBoundedValidator(lower=0.0)) self.declareProperty('MinPeakSigma', 0.1, doc='Minimum value for the standard deviation of a peak', validator=FloatBoundedValidator(lower=0.0)) self.declareProperty('MaxPeakSigma', 30.0, doc='Maximum value for the standard deviation of a peak', validator=FloatBoundedValidator(lower=0.0)) self.declareProperty('EstimateFitWindow', True, doc='If checked, algorithm attempts to calculate number of data points to use from' ' EstimatePeakSigma, if unchecked algorithm will use FitWindowSize argument') self.declareProperty('FitWindowSize', 5, doc='Number of data point used to fit peaks, minimum allowed value is 5, ' 'value must be an odd number ', validator=IntBoundedValidator(lower=5)) self.declareProperty('GeneralFitTolerance', 0.1, doc='Tolerance for the constraint in the general fit', validator=FloatBoundedValidator(lower=0.0)) self.declareProperty('RefitTolerance', 0.001, doc='Tolerance for the constraint in the refitting', validator=FloatBoundedValidator(lower=0.0)) # Output table self.declareProperty( ITableWorkspaceProperty(name='PeakProperties', defaultValue='peak_table', direction=Direction.Output), 'Table containing the properties of the peaks') self.declareProperty( ITableWorkspaceProperty(name='RefitPeakProperties', defaultValue='refit_peak_table', direction=Direction.Output), 'Table containing the properties of the peaks that had to be fitted twice as the first' 'time the error was unreasonably large') self.declareProperty( ITableWorkspaceProperty(name='FitCost', defaultValue='fit_cost', direction=Direction.Output), 'Table containing the value of both chi2 and poisson cost functions for the fit')