forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCalculateFlux.py
60 lines (48 loc) · 2.81 KB
/
CalculateFlux.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.api import PythonAlgorithm, MatrixWorkspaceProperty, WorkspaceUnitValidator, HistogramValidator, InstrumentValidator
from mantid.simpleapi import *
from mantid.kernel import Direction, FloatBoundedValidator, CompositeValidator
import numpy as np
class CalculateFlux(PythonAlgorithm):
def category(self):
return 'CorrectionFunctions\\NormalisationCorrections'
def summary(self):
return 'Calculates the incident beam flux as a function of wavelength using a direct beam SANS data.'
def name(self):
return 'CalculateFlux'
def PyInit(self):
validator = CompositeValidator()
validator.add(WorkspaceUnitValidator('Wavelength'))
validator.add(HistogramValidator())
validator.add(InstrumentValidator())
self.declareProperty(MatrixWorkspaceProperty('InputWorkspace', defaultValue='',
validator = validator,
direction = Direction.Input),
doc='The input workspace in wavelength')
self.declareProperty('BeamRadius', 0.1, FloatBoundedValidator(lower=0.), 'The radius of the beam [m]')
self.declareProperty(MatrixWorkspaceProperty('OutputWorkspace',
defaultValue='',
direction = Direction.Output),
doc='The output workspace')
def PyExec(self):
input_ws = self.getProperty('InputWorkspace').value
wavelengths = input_ws.extractX().flatten()
min_wavelength = np.min(wavelengths)
max_wavelength = np.max(wavelengths)
blocksize = input_ws.blocksize()
width = (max_wavelength-min_wavelength) / blocksize
params = [min_wavelength, width, max_wavelength]
rebinned = Rebin(InputWorkspace=input_ws, StoreInADS=False, Params=params)
radius = self.getProperty('BeamRadius').value
shapeXML = '<infinite-cylinder id="flux"><centre x="0.0" y="0.0" z="0.0"/><axis x="0.0" y="0.0" z="1.0"/>' \
'<radius val="{0}"/></infinite-cylinder>'.format(radius)
det_list = FindDetectorsInShape(Workspace=rebinned, ShapeXML=shapeXML)
output_ws = GroupDetectors(InputWorkspace=rebinned, DetectorList=det_list,
OutputWorkspace=self.getPropertyValue('OutputWorkspace'))
self.setProperty('OutputWorkspace', output_ws)
AlgorithmFactory.subscribe(CalculateFlux)