def PyInit(self): self.declareProperty( MatrixWorkspaceProperty( "InputWorkspace", "", direction=Direction.Input, validator=WorkspaceUnitValidator("Wavelength") ), doc="Flood weighting measurement", ) self.declareProperty( MatrixWorkspaceProperty( "TransmissionWorkspace", "", direction=Direction.Input, optional=PropertyMode.Optional, validator=WorkspaceUnitValidator("Wavelength"), ), doc="Flood weighting measurement", ) validator = FloatArrayBoundedValidator() validator.setLower(0.0) self.declareProperty( FloatArrayProperty("Bands", [], direction=Direction.Input, validator=validator), doc="Wavelength bands to use. Single pair min to max.", ) self.declareProperty( MatrixWorkspaceProperty("OutputWorkspace", "", direction=Direction.Output), doc="Normalized flood weighting measurement", ) self.declareProperty( "SolidAngleCorrection", True, direction=Direction.Input, doc="Perform final solid angle correction" )
def PyInit(self): self.declareProperty(MatrixWorkspaceProperty( 'InputWorkspace', '', direction=Direction.Input, validator=WorkspaceUnitValidator("Wavelength")), doc='Flood weighting measurement') self.declareProperty(MatrixWorkspaceProperty( 'TransmissionWorkspace', '', direction=Direction.Input, optional=PropertyMode.Optional, validator=WorkspaceUnitValidator("Wavelength")), doc='Flood weighting measurement') validator = FloatArrayBoundedValidator(lower=0.) self.declareProperty( FloatArrayProperty('Bands', [], direction=Direction.Input, validator=validator), doc='Wavelength bands to use. Single pair min to max.') self.declareProperty(MatrixWorkspaceProperty( 'OutputWorkspace', '', direction=Direction.Output), doc='Normalized flood weighting measurement') self.declareProperty("SolidAngleCorrection", True, direction=Direction.Input, doc="Perform final solid angle correction")
def invalid_init(self, input_case): if input_case == "String List": self.declareAttribute("StringAtt", "error", StringListValidator(["filename", "test"])) elif input_case == "Float Bounded": self.declareAttribute("FloatAtt", 10.0, FloatBoundedValidator(0.0, 5.0)) elif input_case == "Array Bounded": self.declareAttribute("ListAtt", [1.0, 2.0, 3.0, 10.0], FloatArrayBoundedValidator(0.0, 5.0)) elif input_case == "String Contains": self.declareAttribute("StringContainsAtt", "error", StringContainsValidator(["Contains"]))
def test_exclusive_constructor(self): validator = FloatArrayBoundedValidator(lower=-1., upper=3., exclusive=True) self.assertEquals(validator.lower(), -1.) self.assertEquals(validator.upper(), 3.) self.assertTrue(validator.isLowerExclusive()) self.assertTrue(validator.isUpperExclusive())
def test_empty_constructor_gives_no_lower_upper_bound_set(self): validator = FloatArrayBoundedValidator() self.assertFalse(validator.hasLower()) self.assertFalse(validator.hasUpper())
def PyInit(self): """Initialize the input and output properties of the algorithm.""" nonnegativeInts = IntArrayBoundedValidator() nonnegativeInts.setLower(0) maxTwoNonnegativeInts = CompositeValidator() maxTwoNonnegativeInts.add(IntArrayLengthValidator(lenmin=0, lenmax=2)) maxTwoNonnegativeInts.add(nonnegativeInts) nonnegativeFloatArray = FloatArrayBoundedValidator() nonnegativeFloatArray.setLower(0.) stringArrayValidator = StringArrayLengthValidator() stringArrayValidator.setLengthMin(1) #======================== Main Properties ======================== self.declareProperty( PropertyNames.POLARIZATION_OPTION, 'NonPolarized', StringListValidator(['NonPolarized', 'Polarized']), 'Indicate whether measurements are polarized') is_polarized = EnabledWhenProperty(PropertyNames.POLARIZATION_OPTION, PropertyCriterion.IsEqualTo, 'Polarized') is_not_polarized = EnabledWhenProperty( PropertyNames.POLARIZATION_OPTION, PropertyCriterion.IsEqualTo, 'NonPolarized') polarized = 'Inputs for polarized measurements' self.declareProperty(MultipleFileProperty( PropertyNames.RB, action=FileAction.OptionalLoad, extensions=['nxs']), doc='A list of reflected run numbers/files.') self.setPropertySettings(PropertyNames.RB, is_not_polarized) self.declareProperty( MultipleFileProperty(PropertyNames.RB00, action=FileAction.OptionalLoad, extensions=['nxs']), doc='A list of reflected run numbers/files for 00.') self.setPropertySettings(PropertyNames.RB00, is_polarized) self.setPropertyGroup(PropertyNames.RB00, polarized) self.declareProperty( MultipleFileProperty(PropertyNames.RB01, action=FileAction.OptionalLoad, extensions=['nxs']), doc='A list of reflected run numbers/files for 01.') self.setPropertySettings(PropertyNames.RB01, is_polarized) self.setPropertyGroup(PropertyNames.RB01, polarized) self.declareProperty( MultipleFileProperty(PropertyNames.RB10, action=FileAction.OptionalLoad, extensions=['nxs']), doc='A list of reflected run numbers/files for 10.') self.setPropertySettings(PropertyNames.RB10, is_polarized) self.setPropertyGroup(PropertyNames.RB10, polarized) self.declareProperty( MultipleFileProperty(PropertyNames.RB11, action=FileAction.OptionalLoad, extensions=['nxs']), doc='A list of reflected run numbers/files for 11.') self.setPropertySettings(PropertyNames.RB11, is_polarized) self.setPropertyGroup(PropertyNames.RB11, polarized) self.declareProperty( FileProperty(PropertyNames.EFFICIENCY_FILE, defaultValue='', action=FileAction.OptionalLoad), doc='A file containing the polarization efficiency factors.') self.setPropertySettings(PropertyNames.EFFICIENCY_FILE, is_polarized) self.setPropertyGroup(PropertyNames.EFFICIENCY_FILE, polarized) self.declareProperty(MultipleFileProperty(PropertyNames.DB, action=FileAction.Load, extensions=['nxs']), doc='A list of direct run numbers/files.') self.declareProperty(WorkspaceGroupProperty( Prop.OUTPUT_WS, defaultValue='', direction=Direction.Output), doc='The output workspace group.') self.declareProperty( PropertyNames.BKG_METHOD_DIRECT, defaultValue=BkgMethod.CONSTANT, validator=StringListValidator( [BkgMethod.CONSTANT, BkgMethod.LINEAR, BkgMethod.OFF]), doc='Flat background calculation method for background subtraction.' ) self.declareProperty( PropertyNames.BKG_METHOD, defaultValue=BkgMethod.CONSTANT, validator=StringListValidator( [BkgMethod.CONSTANT, BkgMethod.LINEAR, BkgMethod.OFF]), doc='Flat background calculation method for background subtraction.' ) self.copyProperties('ReflectometryILLPreprocess', [ Prop.SUBALG_LOGGING, Prop.CLEANUP, Prop.WATER_REFERENCE, Prop.SLIT_NORM, Prop.FLUX_NORM_METHOD ]) self.declareProperty(PropertyNames.SCALE_FACTOR, defaultValue=1.0, doc='Scale factor.') self.declareProperty( PropertyNames.USE_MANUAL_SCALE_FACTORS, defaultValue=False, doc='Choose to apply manual scale factors for stitching.') self.declareProperty( FloatArrayProperty(PropertyNames.MANUAL_SCALE_FACTORS, values=[]), doc= 'A list of manual scale factors for stitching (number of anlge configurations minus 1)' ) self.setPropertySettings( PropertyNames.MANUAL_SCALE_FACTORS, EnabledWhenProperty(PropertyNames.USE_MANUAL_SCALE_FACTORS, PropertyCriterion.IsNotDefault)) self.declareProperty( PropertyNames.CACHE_DIRECT_BEAM, defaultValue=False, doc= 'Cache the processed direct beam in ADS for ready use with further reflected beams;' 'saves important execution time, however assumes that the direct beam processing ' 'configuration must be invariant for different reflected beams.') # ======================== Common Properties ======================== commonProp = 'Preprocessing common properties: provide a list or a single value' self.declareProperty(StringArrayProperty( PropertyNames.ANGLE_OPTION, values=[PropertyNames.DAN], validator=stringArrayValidator, direction=Direction.Input, ), doc='Angle option used for detector positioning') self.declareProperty(FloatArrayProperty(PropertyNames.THETA, values=[-1.]), doc='A user-defined angle theta in degree') self.declareProperty(StringArrayProperty( PropertyNames.SUM_TYPE, values=[PropertyNames.INCOHERENT], validator=stringArrayValidator, direction=Direction.Input, ), doc='Type of summation to perform') self.declareProperty(FloatArrayProperty( PropertyNames.WAVELENGTH_LOWER, values=[0.], validator=nonnegativeFloatArray), doc='The lower wavelength bound (Angstrom)') self.declareProperty(FloatArrayProperty( PropertyNames.WAVELENGTH_UPPER, values=[35.], validator=nonnegativeFloatArray), doc='The upper wavelength bound (Angstrom)') self.declareProperty( FloatArrayProperty( PropertyNames.GROUPING_FRACTION, values=[0.5], validator=nonnegativeFloatArray, ), doc= 'If set, group the output by steps of this fraction multiplied by Q resolution' ) self.setPropertyGroup(PropertyNames.ANGLE_OPTION, commonProp) self.setPropertyGroup(PropertyNames.THETA, commonProp) self.setPropertyGroup(PropertyNames.SUM_TYPE, commonProp) self.setPropertyGroup(PropertyNames.WAVELENGTH_LOWER, commonProp) self.setPropertyGroup(PropertyNames.WAVELENGTH_UPPER, commonProp) self.setPropertyGroup(PropertyNames.GROUPING_FRACTION, commonProp) # ======================== Direct Run Properties ======================== preProcessDirect = 'Preprocessing for direct runs: provide a list or a single value' self.declareProperty( IntArrayProperty(PropertyNames.LOW_FRG_HALF_WIDTH_DIRECT, values=[0], validator=nonnegativeInts), doc= 'Number of foreground pixels at lower angles from the centre pixel.' ) self.setPropertyGroup(PropertyNames.LOW_FRG_HALF_WIDTH_DIRECT, preProcessDirect) self.declareProperty( IntArrayProperty( PropertyNames.LOW_BKG_OFFSET_DIRECT, values=[7], validator=nonnegativeInts, ), doc= 'Distance of flat background region towards smaller detector angles from the ' + 'foreground centre, in pixels') self.setPropertyGroup(PropertyNames.LOW_BKG_OFFSET_DIRECT, preProcessDirect) self.declareProperty( IntArrayProperty( PropertyNames.LOW_BKG_WIDTH_DIRECT, values=[5], validator=nonnegativeInts, ), doc= 'Width of flat background region towards smaller detector angles from the ' + 'foreground centre, in pixels') self.setPropertyGroup(PropertyNames.LOW_BKG_WIDTH_DIRECT, preProcessDirect) self.declareProperty( IntArrayProperty(PropertyNames.HIGH_FRG_HALF_WIDTH_DIRECT, values=[0], validator=nonnegativeInts), doc= 'Number of foreground pixels at higher angles from the centre pixel.' ) self.setPropertyGroup(PropertyNames.HIGH_FRG_HALF_WIDTH_DIRECT, preProcessDirect) self.declareProperty( IntArrayProperty( PropertyNames.HIGH_BKG_OFFSET_DIRECT, values=[7], validator=nonnegativeInts, ), doc= 'Distance of flat background region towards larger detector angles from the ' + 'foreground centre, in pixels') self.setPropertyGroup(PropertyNames.HIGH_BKG_OFFSET_DIRECT, preProcessDirect) self.declareProperty( IntArrayProperty( PropertyNames.HIGH_BKG_WIDTH_DIRECT, values=[5], validator=nonnegativeInts, ), doc= 'Width of flat background region towards larger detector angles from the ' + 'foreground centre, in pixels') self.setPropertyGroup(PropertyNames.HIGH_BKG_WIDTH_DIRECT, preProcessDirect) self.declareProperty(IntArrayProperty( PropertyNames.START_WS_INDEX_DIRECT, values=[0], validator=nonnegativeInts, ), doc='Start histogram index used for peak fitting') self.setPropertyGroup(PropertyNames.START_WS_INDEX_DIRECT, preProcessDirect) self.declareProperty(IntArrayProperty( PropertyNames.END_WS_INDEX_DIRECT, values=[255], validator=nonnegativeInts, ), doc='Last histogram index used for peak fitting') self.setPropertyGroup(PropertyNames.END_WS_INDEX_DIRECT, preProcessDirect) self.declareProperty( PropertyNames.XMIN_DIRECT, defaultValue=-1., doc='Minimum x value (unit wavelength) used for peak fitting.') self.setPropertyGroup(PropertyNames.XMIN_DIRECT, preProcessDirect) self.declareProperty( PropertyNames.XMAX_DIRECT, defaultValue=-1., doc='Maximum x value (unit wavelength) used for peak fitting.') self.setPropertyGroup(PropertyNames.XMAX_DIRECT, preProcessDirect) # ======================== Preprocessing For Reflected Runs ======================== preProcessReflected = 'Preprocessing for reflected runs: provide a list or a single value' self.declareProperty( IntArrayProperty( PropertyNames.LOW_FRG_HALF_WIDTH, values=[0], validator=nonnegativeInts, ), doc= 'Number of foreground pixels at lower angles from the centre pixel.' ) self.setPropertyGroup(PropertyNames.LOW_FRG_HALF_WIDTH, preProcessReflected) self.declareProperty( IntArrayProperty( PropertyNames.LOW_BKG_OFFSET, values=[7], validator=nonnegativeInts, ), doc= 'Distance of flat background region towards smaller detector angles from the ' + 'foreground centre, in pixels.') self.setPropertyGroup(PropertyNames.LOW_BKG_OFFSET, preProcessReflected) self.declareProperty( IntArrayProperty( PropertyNames.LOW_BKG_WIDTH, values=[5], validator=nonnegativeInts, ), doc= 'Width of flat background region towards smaller detector angles from the ' + 'foreground centre, in pixels') self.setPropertyGroup(PropertyNames.LOW_BKG_WIDTH, preProcessReflected) self.declareProperty( IntArrayProperty( PropertyNames.HIGH_FRG_HALF_WIDTH, values=[0], validator=nonnegativeInts, ), doc= 'Number of foreground pixels at higher angles from the centre pixel.' ) self.setPropertyGroup(PropertyNames.HIGH_FRG_HALF_WIDTH, preProcessReflected) self.declareProperty( IntArrayProperty( PropertyNames.HIGH_BKG_OFFSET, values=[7], validator=nonnegativeInts, ), doc= 'Distance of flat background region towards larger detector angles from the ' + 'foreground centre, in pixels') self.setPropertyGroup(PropertyNames.HIGH_BKG_OFFSET, preProcessReflected) self.declareProperty( IntArrayProperty( PropertyNames.HIGH_BKG_WIDTH, values=[5], validator=nonnegativeInts, ), doc= 'Width of flat background region towards larger detector angles from the ' + 'foreground centre, in pixels.') self.setPropertyGroup(PropertyNames.HIGH_BKG_WIDTH, preProcessReflected) self.declareProperty(IntArrayProperty( PropertyNames.START_WS_INDEX, values=[0], validator=nonnegativeInts, ), doc='Start histogram index used for peak fitting') self.setPropertyGroup(PropertyNames.START_WS_INDEX, preProcessReflected) self.declareProperty(IntArrayProperty( PropertyNames.END_WS_INDEX, values=[255], validator=nonnegativeInts, ), doc='Last histogram index used for peak fitting') self.setPropertyGroup(PropertyNames.END_WS_INDEX, preProcessReflected) self.declareProperty( FloatArrayProperty(PropertyNames.XMIN, values=[-1.]), doc='Minimum x value (unit wavelength) used for peak fitting') self.setPropertyGroup(PropertyNames.XMIN, preProcessReflected) self.declareProperty( FloatArrayProperty(PropertyNames.XMAX, values=[-1.]), doc='Maximum x value (unit wavelength) used for peak fitting') self.setPropertyGroup(PropertyNames.XMAX, preProcessReflected)
def PyInit(self): self.declareProperty( IMDHistoWorkspaceProperty("InputWorkspace", "", optional=PropertyMode.Mandatory, direction=Direction.Input), "Input Workspace with HKL dimensions centered on zero.") self.declareProperty( WorkspaceProperty("IntermediateWorkspace", "", optional=PropertyMode.Optional, direction=Direction.Output), "The resulting workspace after reflection removal and filters applied. What is the input of the FFT." ) self.declareProperty( WorkspaceProperty("OutputWorkspace", "", optional=PropertyMode.Mandatory, direction=Direction.Output), "Output Workspace") self.declareProperty("RemoveReflections", True, "Remove HKL reflections") condition = EnabledWhenProperty("RemoveReflections", PropertyCriterion.IsDefault) self.declareProperty("Shape", "sphere", doc="Shape to cut out reflections", validator=StringListValidator(['sphere', 'cube'])) self.setPropertySettings("Shape", condition) val_min_zero = FloatArrayBoundedValidator() val_min_zero.setLower(0.) self.declareProperty( FloatArrayProperty("Size", [0.2], validator=val_min_zero), "Width of cube/diameter of sphere used to remove reflections, in (HKL) (one or three values)" ) self.setPropertySettings("Size", condition) self.declareProperty( "SpaceGroup", "", doc= "Space group for reflection removal, either full name or number. If empty all HKL's will be removed." ) self.setPropertySettings("SpaceGroup", condition) self.declareProperty( "CropSphere", False, "Limit min/max q values. Can help with edge effects.") condition = EnabledWhenProperty("CropSphere", PropertyCriterion.IsNotDefault) self.declareProperty( FloatArrayProperty("SphereMin", [Property.EMPTY_DBL], validator=val_min_zero), "HKL values below which will be removed (one or three values)") self.setPropertySettings("SphereMin", condition) self.declareProperty( FloatArrayProperty("SphereMax", [Property.EMPTY_DBL], validator=val_min_zero), "HKL values above which will be removed (one or three values)") self.setPropertySettings("SphereMax", condition) self.declareProperty("FillValue", Property.EMPTY_DBL, "Value to replace with outside sphere") self.setPropertySettings("FillValue", condition) self.declareProperty( "Convolution", True, "Apply convolution to fill in removed reflections") condition = EnabledWhenProperty("Convolution", PropertyCriterion.IsDefault) self.declareProperty("ConvolutionWidth", 2.0, validator=FloatBoundedValidator(0.), doc="Width of gaussian convolution in pixels") self.setPropertySettings("ConvolutionWidth", condition) self.declareProperty("Deconvolution", False, "Apply deconvolution after fourier transform") self.setPropertySettings("Deconvolution", condition) # Reflections self.setPropertyGroup("RemoveReflections", "Reflection Removal") self.setPropertyGroup("Shape", "Reflection Removal") self.setPropertyGroup("Size", "Reflection Removal") self.setPropertyGroup("SpaceGroup", "Reflection Removal") # Sphere self.setPropertyGroup("CropSphere", "Cropping to a sphere") self.setPropertyGroup("SphereMin", "Cropping to a sphere") self.setPropertyGroup("SphereMax", "Cropping to a sphere") self.setPropertyGroup("FillValue", "Cropping to a sphere") # Convolution self.setPropertyGroup("Convolution", "Convolution") self.setPropertyGroup("ConvolutionWidth", "Convolution") self.setPropertyGroup("Deconvolution", "Convolution")
def PyInit(self): """Initialize the input and output properties of the algorithm.""" threeNonnegativeInts = CompositeValidator() threeNonnegativeInts.add(IntArrayLengthValidator(3)) nonnegativeInts = IntArrayBoundedValidator() nonnegativeInts.setLower(0) threeNonnegativeInts.add(nonnegativeInts) nonnegativeFloatArray = FloatArrayBoundedValidator() nonnegativeFloatArray.setLower(0.) inWavelength = WorkspaceUnitValidator('Wavelength') self.declareProperty( MatrixWorkspaceProperty( Prop.INPUT_WS, defaultValue='', direction=Direction.Input, validator=inWavelength), doc='A reflected beam workspace (units wavelength).') self.declareProperty( MatrixWorkspaceProperty( Prop.OUTPUT_WS, defaultValue='', direction=Direction.Output), doc='The summed foreground workspace.') 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( Prop.SUM_TYPE, defaultValue=SumType.IN_LAMBDA, validator=StringListValidator([SumType.IN_LAMBDA, SumType.IN_Q]), doc='Type of summation to perform.') self.declareProperty( MatrixWorkspaceProperty( Prop.DIRECT_FOREGROUND_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional, validator=inWavelength), doc='Summed direct beam workspace (units wavelength).') self.declareProperty( IntArrayProperty( Prop.FOREGROUND_INDICES, values=[Property.EMPTY_INT, Property.EMPTY_INT, Property.EMPTY_INT], validator=threeNonnegativeInts), doc='A three element array of foreground start, centre and end workspace indices.') self.declareProperty( MatrixWorkspaceProperty( Prop.DIRECT_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional, validator=inWavelength), doc='The (not summed) direct beam workspace (units wavelength).') self.declareProperty( FloatArrayProperty( Prop.WAVELENGTH_RANGE, values=[0.], validator=nonnegativeFloatArray), doc='The wavelength bounds.')
def test_clear_members_remove_bounds(self): lower = 7.0 upper = 10.0 validator = FloatArrayBoundedValidator(lower, upper) self.assertTrue(validator.hasLower()) self.assertTrue(validator.hasUpper()) self.assertEquals(validator.lower(), lower) self.assertEquals(validator.upper(), upper) validator.clearLower() self.assertFalse(validator.hasLower()) self.assertTrue(validator.hasUpper()) validator.clearUpper() self.assertFalse(validator.hasLower()) self.assertFalse(validator.hasUpper())
def PyInit(self): """Initialize the input and output properties of the algorithm.""" threeNonnegativeInts = CompositeValidator() threeNonnegativeInts.add(IntArrayLengthValidator(3)) nonnegativeInts = IntArrayBoundedValidator(lower=0) threeNonnegativeInts.add(nonnegativeInts) nonnegativeFloatArray = FloatArrayBoundedValidator(lower=0.) inWavelength = WorkspaceUnitValidator('Wavelength') self.declareProperty( MatrixWorkspaceProperty( Prop.INPUT_WS, defaultValue='', direction=Direction.Input, validator=inWavelength), doc='A reflected beam workspace (units wavelength).') self.declareProperty( MatrixWorkspaceProperty( Prop.OUTPUT_WS, defaultValue='', direction=Direction.Output), doc='The summed foreground workspace.') 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=utils.Cleanup.ON, validator=StringListValidator([utils.Cleanup.ON, utils.Cleanup.OFF]), doc='Enable or disable intermediate workspace cleanup.') self.declareProperty( Prop.SUM_TYPE, defaultValue=SumType.IN_LAMBDA, validator=StringListValidator([SumType.IN_LAMBDA, SumType.IN_Q]), doc='Type of summation to perform.') self.declareProperty( MatrixWorkspaceProperty( Prop.DIRECT_FOREGROUND_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional, validator=inWavelength), doc='Summed direct beam workspace (units wavelength).') self.declareProperty( IntArrayProperty( Prop.FOREGROUND_INDICES, values=[Property.EMPTY_INT, Property.EMPTY_INT, Property.EMPTY_INT], validator=threeNonnegativeInts), doc='A three element array of foreground start, centre and end workspace indices.') self.declareProperty( MatrixWorkspaceProperty( Prop.DIRECT_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional, validator=inWavelength), doc='The (not summed) direct beam workspace (units wavelength).') self.declareProperty( FloatArrayProperty( Prop.WAVELENGTH_RANGE, values=[0.], validator=nonnegativeFloatArray), doc='The wavelength bounds.')
def PyInit(self): validator = FloatArrayBoundedValidator(lower, upper) self.declareProperty(FloatArrayProperty("Input", validator))
def PyInit(self): """Initialize the input and output properties of the algorithm.""" nonnegativeInt = IntBoundedValidator(lower=0) nonnegativeIntArray = IntArrayBoundedValidator() nonnegativeIntArray.setLower(0) nonnegativeFloatArray = FloatArrayBoundedValidator() nonnegativeFloatArray.setLower(0.) twoNonnegativeFloats = CompositeValidator() twoNonnegativeFloats.add(FloatArrayLengthValidator(length=2)) twoNonnegativeFloats.add(nonnegativeFloatArray) maxTwoNonnegativeInts = CompositeValidator() maxTwoNonnegativeInts.add(IntArrayLengthValidator(lenmin=0, lenmax=2)) maxTwoNonnegativeInts.add(nonnegativeIntArray) self.declareProperty(MultipleFileProperty(Prop.RUN, action=FileAction.OptionalLoad, extensions=['nxs']), doc='A list of input run numbers/files.') self.declareProperty(MatrixWorkspaceProperty(Prop.INPUT_WS, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator('TOF'), optional=PropertyMode.Optional), doc='An input workspace (units TOF) if no Run is specified.') self.declareProperty(ITableWorkspaceProperty(Prop.BEAM_POS_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional), doc='A beam position table corresponding to InputWorkspace.') self.declareProperty(Prop.BEAM_ANGLE, defaultValue=Property.EMPTY_DBL, doc='A user-defined beam angle (unit degrees).') self.declareProperty(name=Prop.BEAM_CENTRE, defaultValue=Property.EMPTY_DBL, doc='A workspace index corresponding to the beam centre.') self.declareProperty(MatrixWorkspaceProperty(Prop.OUTPUT_WS, defaultValue='', direction=Direction.Output), doc='The preprocessed output workspace (unit wavelength), single histogram.') 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(ITableWorkspaceProperty(Prop.DIRECT_BEAM_POS_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional), doc='A beam position table from a direct beam measurement.') self.declareProperty(MatrixWorkspaceProperty(Prop.WATER_REFERENCE, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator("TOF"), optional=PropertyMode.Optional), doc='A (water) calibration workspace (unit TOF).') self.declareProperty(Prop.SLIT_NORM, defaultValue=SlitNorm.OFF, validator=StringListValidator([SlitNorm.OFF, SlitNorm.ON]), doc='Enable or disable slit normalisation.') self.declareProperty(Prop.FLUX_NORM_METHOD, defaultValue=FluxNormMethod.TIME, validator=StringListValidator([FluxNormMethod.TIME, FluxNormMethod.MONITOR, FluxNormMethod.OFF]), doc='Neutron flux normalisation method.') self.declareProperty(IntArrayProperty(Prop.FOREGROUND_HALF_WIDTH, validator=maxTwoNonnegativeInts), doc='Number of foreground pixels at lower and higher angles from the centre pixel.') self.declareProperty(Prop.BKG_METHOD, defaultValue=BkgMethod.CONSTANT, validator=StringListValidator([BkgMethod.CONSTANT, BkgMethod.LINEAR, BkgMethod.OFF]), doc='Flat background calculation method for background subtraction.') self.declareProperty(Prop.LOW_BKG_OFFSET, defaultValue=7, validator=nonnegativeInt, doc='Distance of flat background region towards smaller detector angles from the foreground centre, ' + 'in pixels.') self.declareProperty(Prop.LOW_BKG_WIDTH, defaultValue=5, validator=nonnegativeInt, doc='Width of flat background region towards smaller detector angles from the foreground centre, in pixels.') self.declareProperty(Prop.HIGH_BKG_OFFSET, defaultValue=7, validator=nonnegativeInt, doc='Distance of flat background region towards larger detector angles from the foreground centre, in pixels.') self.declareProperty(Prop.HIGH_BKG_WIDTH, defaultValue=5, validator=nonnegativeInt, doc='Width of flat background region towards larger detector angles from the foreground centre, in pixels.') self.declareProperty(ITableWorkspaceProperty(Prop.OUTPUT_BEAM_POS_WS, defaultValue='', direction=Direction.Output, optional=PropertyMode.Optional), doc='Output the beam position table.')
def test_set_members_alter_bounds(self): validator = FloatArrayBoundedValidator() self.assertFalse(validator.hasLower()) self.assertFalse(validator.hasUpper()) lower = 5.6 validator.setLower(lower) self.assertTrue(validator.hasLower()) self.assertEquals(validator.lower(), lower) self.assertFalse(validator.hasUpper()) upper = 10.6 validator.setUpper(upper) self.assertTrue(validator.hasLower()) self.assertTrue(validator.hasUpper()) self.assertEquals(validator.upper(), upper)
def test_exclusive_constructor(self): validator = FloatArrayBoundedValidator(lower=-1., upper=3., exclusive=True) self.assertEquals(validator.lower(), -1.) self.assertEquals(validator.upper(), 3.) self.assertTrue(validator.isLowerExclusive()) self.assertTrue(validator.isUpperExclusive())
def PyInit(self): """Initialize the input and output properties of the algorithm.""" threeNonnegativeInts = CompositeValidator() threeNonnegativeInts.add(IntArrayLengthValidator(3)) nonnegativeInts = IntArrayBoundedValidator() nonnegativeInts.setLower(0) threeNonnegativeInts.add(nonnegativeInts) nonnegativeFloatArray = FloatArrayBoundedValidator() nonnegativeFloatArray.setLower(0.) self.declareProperty( MatrixWorkspaceProperty( Prop.INPUT_WS, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator('Wavelength')), doc='An input workspace (units wavelength) to be integrated.') self.declareProperty( MatrixWorkspaceProperty(Prop.OUTPUT_WS, defaultValue='', direction=Direction.Output), doc='The integrated foreground divided by the summed direct beam.') 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(Prop.SUM_TYPE, defaultValue=SumType.IN_LAMBDA, validator=StringListValidator( [SumType.IN_LAMBDA, SumType.IN_Q]), doc='Type of summation to perform.') self.declareProperty( Prop.FLAT_SAMPLE, defaultValue=Sample.FLAT, validator=StringListValidator([Sample.FLAT, Sample.BENT]), doc= 'For SumInQ option, determines if the summation should be done for a flat or bent sample.' ) self.declareProperty( MatrixWorkspaceProperty( Prop.DIRECT_FOREGROUND_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional, validator=WorkspaceUnitValidator('Wavelength')), doc= 'Summed direct beam workspace if output in reflectivity is required.' ) self.declareProperty( IntArrayProperty(Prop.FOREGROUND_INDICES, values=[ Property.EMPTY_INT, Property.EMPTY_INT, Property.EMPTY_INT ], validator=threeNonnegativeInts), doc= 'A three element array of foreground start, centre and end workspace indices.' ) self.declareProperty(FloatArrayProperty( Prop.WAVELENGTH_RANGE, values=[0.], validator=nonnegativeFloatArray), doc='The wavelength bounds when summing in Q.')
def PyInit(self): """Initialize the input and output properties of the algorithm.""" nonnegativeInt = IntBoundedValidator(lower=0) nonnegativeIntArray = IntArrayBoundedValidator() nonnegativeIntArray.setLower(0) nonnegativeFloatArray = FloatArrayBoundedValidator() nonnegativeFloatArray.setLower(0.) twoNonnegativeFloats = CompositeValidator() twoNonnegativeFloats.add(FloatArrayLengthValidator(length=2)) twoNonnegativeFloats.add(nonnegativeFloatArray) maxTwoNonnegativeInts = CompositeValidator() maxTwoNonnegativeInts.add(IntArrayLengthValidator(lenmin=0, lenmax=2)) maxTwoNonnegativeInts.add(nonnegativeIntArray) self.declareProperty(MultipleFileProperty( Prop.RUN, action=FileAction.OptionalLoad, extensions=['nxs']), doc='A list of input run numbers/files.') self.declareProperty( MatrixWorkspaceProperty(Prop.INPUT_WS, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator('TOF'), optional=PropertyMode.Optional), doc='An input workspace (units TOF) if no Run is specified.') self.declareProperty( ITableWorkspaceProperty(Prop.BEAM_POS_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional), doc='A beam position table corresponding to InputWorkspace.') self.declareProperty(Prop.BEAM_ANGLE, defaultValue=Property.EMPTY_DBL, doc='A user-defined beam angle (unit degrees).') self.declareProperty( name=Prop.BEAM_CENTRE, defaultValue=Property.EMPTY_DBL, doc='A workspace index corresponding to the beam centre.') self.declareProperty( MatrixWorkspaceProperty(Prop.OUTPUT_WS, defaultValue='', direction=Direction.Output), doc= 'The preprocessed output workspace (unit wavelength), single histogram.' ) 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( ITableWorkspaceProperty(Prop.DIRECT_BEAM_POS_WS, defaultValue='', direction=Direction.Input, optional=PropertyMode.Optional), doc='A beam position table from a direct beam measurement.') self.declareProperty(MatrixWorkspaceProperty( Prop.WATER_REFERENCE, defaultValue='', direction=Direction.Input, validator=WorkspaceUnitValidator("TOF"), optional=PropertyMode.Optional), doc='A (water) calibration workspace (unit TOF).') self.declareProperty(Prop.SLIT_NORM, defaultValue=SlitNorm.OFF, validator=StringListValidator( [SlitNorm.OFF, SlitNorm.ON]), doc='Enable or disable slit normalisation.') self.declareProperty(Prop.FLUX_NORM_METHOD, defaultValue=FluxNormMethod.TIME, validator=StringListValidator([ FluxNormMethod.TIME, FluxNormMethod.MONITOR, FluxNormMethod.OFF ]), doc='Neutron flux normalisation method.') self.declareProperty( IntArrayProperty(Prop.FOREGROUND_HALF_WIDTH, validator=maxTwoNonnegativeInts), doc= 'Number of foreground pixels at lower and higher angles from the centre pixel.' ) self.declareProperty( Prop.BKG_METHOD, defaultValue=BkgMethod.CONSTANT, validator=StringListValidator( [BkgMethod.CONSTANT, BkgMethod.LINEAR, BkgMethod.OFF]), doc='Flat background calculation method for background subtraction.' ) self.declareProperty( Prop.LOW_BKG_OFFSET, defaultValue=7, validator=nonnegativeInt, doc= 'Distance of flat background region towards smaller detector angles from the foreground centre, ' + 'in pixels.') self.declareProperty( Prop.LOW_BKG_WIDTH, defaultValue=5, validator=nonnegativeInt, doc= 'Width of flat background region towards smaller detector angles from the foreground centre, in pixels.' ) self.declareProperty( Prop.HIGH_BKG_OFFSET, defaultValue=7, validator=nonnegativeInt, doc= 'Distance of flat background region towards larger detector angles from the foreground centre, in pixels.' ) self.declareProperty( Prop.HIGH_BKG_WIDTH, defaultValue=5, validator=nonnegativeInt, doc= 'Width of flat background region towards larger detector angles from the foreground centre, in pixels.' ) self.declareProperty(ITableWorkspaceProperty( Prop.OUTPUT_BEAM_POS_WS, defaultValue='', direction=Direction.Output, optional=PropertyMode.Optional), doc='Output the beam position table.')
def PyInit(self): self.declareProperty(IMDHistoWorkspaceProperty("InputWorkspace", "", optional=PropertyMode.Mandatory, direction=Direction.Input), "Input Workspace with HKL dimensions centered on zero.") self.declareProperty(WorkspaceProperty("IntermediateWorkspace", "", optional=PropertyMode.Optional, direction=Direction.Output), "The resulting workspace after reflection removal and filters applied. What is the input of the FFT.") self.declareProperty(WorkspaceProperty("OutputWorkspace", "", optional=PropertyMode.Mandatory, direction=Direction.Output), "Output Workspace") self.declareProperty("RemoveReflections", True, "Remove HKL reflections") condition = EnabledWhenProperty("RemoveReflections", PropertyCriterion.IsDefault) self.declareProperty("Shape", "sphere", doc="Shape to cut out reflections", validator=StringListValidator(['sphere', 'cube'])) self.setPropertySettings("Shape", condition) val_min_zero = FloatArrayBoundedValidator() val_min_zero.setLower(0.) self.declareProperty(FloatArrayProperty("Size", [0.2], validator=val_min_zero), "Width of cube/diameter of sphere used to remove reflections, in (HKL) (one or three values)") self.setPropertySettings("Size", condition) self.declareProperty("SpaceGroup", "", doc="Space group for reflection removal, either full name or number. If empty all HKL's will be removed.") self.setPropertySettings("SpaceGroup", condition) self.declareProperty("CropSphere", False, "Limit min/max q values. Can help with edge effects.") condition = EnabledWhenProperty("CropSphere", PropertyCriterion.IsNotDefault) self.declareProperty(FloatArrayProperty("SphereMin", [Property.EMPTY_DBL], validator=val_min_zero), "HKL values below which will be removed (one or three values)") self.setPropertySettings("SphereMin", condition) self.declareProperty(FloatArrayProperty("SphereMax", [Property.EMPTY_DBL], validator=val_min_zero), "HKL values above which will be removed (one or three values)") self.setPropertySettings("SphereMax", condition) self.declareProperty("FillValue", Property.EMPTY_DBL, "Value to replace with outside sphere") self.setPropertySettings("FillValue", condition) self.declareProperty("Convolution", True, "Apply convolution to fill in removed reflections") condition = EnabledWhenProperty("Convolution", PropertyCriterion.IsDefault) self.declareProperty("ConvolutionWidth", 2.0, validator=FloatBoundedValidator(0.), doc="Width of gaussian convolution in pixels") self.setPropertySettings("ConvolutionWidth", condition) self.declareProperty("Deconvolution", False, "Apply deconvolution after fourier transform") self.setPropertySettings("Deconvolution", condition) # Reflections self.setPropertyGroup("RemoveReflections","Reflection Removal") self.setPropertyGroup("Shape","Reflection Removal") self.setPropertyGroup("Size","Reflection Removal") self.setPropertyGroup("SpaceGroup","Reflection Removal") # Sphere self.setPropertyGroup("CropSphere","Cropping to a sphere") self.setPropertyGroup("SphereMin","Cropping to a sphere") self.setPropertyGroup("SphereMax","Cropping to a sphere") self.setPropertyGroup("FillValue","Cropping to a sphere") # Convolution self.setPropertyGroup("Convolution","Convolution") self.setPropertyGroup("ConvolutionWidth","Convolution") self.setPropertyGroup("Deconvolution","Convolution")
def test_clear_members_remove_bounds(self): lower = 7.0 upper = 10.0 validator = FloatArrayBoundedValidator(lower, upper) self.assertTrue(validator.hasLower()) self.assertTrue(validator.hasUpper()) self.assertEquals(validator.lower(), lower) self.assertEquals(validator.upper(), upper) validator.clearLower() self.assertFalse(validator.hasLower()) self.assertTrue(validator.hasUpper()) validator.clearUpper() self.assertFalse(validator.hasLower()) self.assertFalse(validator.hasUpper())
def test_empty_constructor_gives_no_lower_upper_bound_set(self): validator = FloatArrayBoundedValidator() self.assertFalse(validator.hasLower()) self.assertFalse(validator.hasUpper())
def PyInit(self): self.declareProperty( IMDHistoWorkspaceProperty("InputWorkspace", "", optional=PropertyMode.Mandatory, direction=Direction.Input), "Input Workspace with HKL dimensions centered on zero.") self.declareProperty( WorkspaceProperty("IntermediateWorkspace", "", optional=PropertyMode.Optional, direction=Direction.Output), "The resulting workspace after reflection removal and filters applied. What is the input of the FFT." ) self.declareProperty( WorkspaceProperty("OutputWorkspace", "", optional=PropertyMode.Mandatory, direction=Direction.Output), "Output Workspace") self.declareProperty( "Method", 'KAREN', StringListValidator(['None', 'Punch and fill', 'KAREN']), "Bragg peak removal method") self.declareProperty( "WindowFunction", 'Blackman', StringListValidator( ['None', 'Gaussian', 'Blackman', 'Tukey', 'Kaiser']), "Apply a window function to the data") self.declareProperty( "WindowParameter", defaultValue=0.5, validator=FloatBoundedValidator(0.), doc= "Parameter for window function, depends on window type, see algorithm docs" ) # Punch and fill condition = EnabledWhenProperty("Method", PropertyCriterion.IsEqualTo, 'Punch and fill') self.declareProperty("Shape", "sphere", doc="Shape to punch out reflections", validator=StringListValidator(['sphere', 'cube'])) self.setPropertySettings("Shape", condition) val_min_zero = FloatArrayBoundedValidator(lower=0.) self.declareProperty( FloatArrayProperty("Size", [0.2], validator=val_min_zero), "Width of cube/diameter of sphere used to remove reflections, in (HKL) (one or three values)" ) self.setPropertySettings("Size", condition) self.declareProperty( "SpaceGroup", "", doc= "Space group for reflection removal, either full name or number. If empty all HKL's will be removed." ) self.setPropertySettings("SpaceGroup", condition) self.declareProperty( "Convolution", True, "Apply convolution to fill in removed reflections") self.setPropertySettings("Convolution", condition) self.declareProperty("ConvolutionWidth", 2.0, validator=FloatBoundedValidator(0.), doc="Width of gaussian convolution in pixels") self.setPropertySettings("ConvolutionWidth", condition) self.declareProperty( "CropSphere", False, "Limit min/max q values. Can help with edge effects.") condition = EnabledWhenProperty("CropSphere", PropertyCriterion.IsNotDefault) self.declareProperty( FloatArrayProperty("SphereMin", [Property.EMPTY_DBL], validator=val_min_zero), "HKL values below which will be removed (one or three values)") self.setPropertySettings("SphereMin", condition) self.declareProperty( FloatArrayProperty("SphereMax", [Property.EMPTY_DBL], validator=val_min_zero), "HKL values above which will be removed (one or three values)") self.setPropertySettings("SphereMax", condition) self.declareProperty("FillValue", Property.EMPTY_DBL, "Value to replace with outside sphere") self.setPropertySettings("FillValue", condition) # KAREN self.declareProperty("KARENWidth", 7, "Size of filter window") # Reflections self.setPropertyGroup("Shape", "Punch and fill") self.setPropertyGroup("Size", "Punch and fill") self.setPropertyGroup("SpaceGroup", "Punch and fill") # Sphere self.setPropertyGroup("CropSphere", "Cropping to a sphere") self.setPropertyGroup("SphereMin", "Cropping to a sphere") self.setPropertyGroup("SphereMax", "Cropping to a sphere") self.setPropertyGroup("FillValue", "Cropping to a sphere") # Convolution self.setPropertyGroup("Convolution", "Convolution") self.setPropertyGroup("ConvolutionWidth", "Convolution")
def test_set_members_alter_bounds(self): validator = FloatArrayBoundedValidator() self.assertFalse(validator.hasLower()) self.assertFalse(validator.hasUpper()) lower = 5.6 validator.setLower(lower) self.assertTrue(validator.hasLower()) self.assertEquals(validator.lower(), lower) self.assertFalse(validator.hasUpper()) upper = 10.6 validator.setUpper(upper) self.assertTrue(validator.hasLower()) self.assertTrue(validator.hasUpper()) self.assertEquals(validator.upper(), upper)