Skip to content

Commit

Permalink
Merge pull request #498 from kif/polarization_id02
Browse files Browse the repository at this point in the history
Polarization id02
  • Loading branch information
vallsv authored Nov 30, 2016
2 parents 842ad60 + 62937b1 commit 63271f6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
7 changes: 6 additions & 1 deletion pyFAI/azimuthalIntegrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,10 @@ def integrate1d(self, data, npt, filename=None,
:type dummy: float
:param delta_dummy: precision for dummy value
:type delta_dummy: float
:param polarization_factor: polarization factor between -1 (vertical) and +1 (horizontal). 0 for circular polarization or random, None for no correction
:param polarization_factor: polarization factor between -1 (vertical) and +1 (horizontal).
0 for circular polarization or random,
None for no correction,
True for using the former correction
:type polarization_factor: float
:param dark: dark noise image
:type dark: ndarray
Expand Down Expand Up @@ -2222,6 +2225,8 @@ def integrate1d(self, data, npt, filename=None,

if polarization_factor is None:
polarization = None
elif polarization_factor is True:
polarization = self._polarization
else:
polarization = self.polarization(shape, float(polarization_factor))

Expand Down
12 changes: 6 additions & 6 deletions pyFAI/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,12 +1495,12 @@ def polarization(self, shape=None, factor=None, axis_offset=0):
tth = self.twoThetaArray(shape)
chi = self.chiArray(shape) + axis_offset
with self._sem:
cos2_tth = numpy.cos(tth) ** 2
self._polarization = ((1 + cos2_tth - factor * numpy.cos(2 * chi) * (1 - cos2_tth)) / 2.0) # .astype(numpy.float32)
self._polarization_factor = factor
self._polarization_axis_offset = axis_offset
self._polarization_crc = crc32(self._polarization)
return self._polarization
cos2_tth = numpy.cos(tth) ** 2
self._polarization = ((1 + cos2_tth - factor * numpy.cos(2 * chi) * (1 - cos2_tth)) / 2.0) # .astype(numpy.float32)
self._polarization_factor = factor
self._polarization_axis_offset = axis_offset
self._polarization_crc = crc32(self._polarization)
return self._polarization

def calc_transmission(self, t0, shape=None):
"""
Expand Down
15 changes: 8 additions & 7 deletions pyFAI/test/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

"Test suite for worker"

from __future__ import absolute_import, division, print_function

__doc__ = "test suite for worker"
__author__ = "Valentin Valls"
__contact__ = "[email protected]"
__license__ = "MIT"
Expand Down Expand Up @@ -107,7 +108,7 @@ def test_process_1d(self):
worker.dummy = "b"
worker.delta_dummy = "c"
worker.method = "d"
worker.polarization = "e"
worker.polarization_factor = "e"
worker.correct_solid_angle = "f"
worker.nbpt_rad = "g"
worker.nbpt_azim = 1
Expand All @@ -122,7 +123,7 @@ def test_process_1d(self):
self.assertEquals(ai_args["dummy"], worker.dummy)
self.assertEquals(ai_args["delta_dummy"], worker.delta_dummy)
self.assertEquals(ai_args["method"], worker.method)
self.assertEquals(ai_args["polarization_factor"], worker.polarization)
self.assertEquals(ai_args["polarization_factor"], worker.polarization_factor)
self.assertEquals(ai_args["safe"], True)
self.assertEquals(ai_args["data"], data)
self.assertEquals(ai_args["correctSolidAngle"], worker.correct_solid_angle)
Expand All @@ -143,7 +144,7 @@ def test_process_2d(self):
worker.dummy = "b"
worker.delta_dummy = "c"
worker.method = "d"
worker.polarization = "e"
worker.polarization_factor = "e"
worker.correct_solid_angle = "f"
worker.nbpt_rad = "g"
worker.nbpt_azim = 2
Expand All @@ -158,7 +159,7 @@ def test_process_2d(self):
self.assertEquals(ai_args["dummy"], worker.dummy)
self.assertEquals(ai_args["delta_dummy"], worker.delta_dummy)
self.assertEquals(ai_args["method"], worker.method)
self.assertEquals(ai_args["polarization_factor"], worker.polarization)
self.assertEquals(ai_args["polarization_factor"], worker.polarization_factor)
self.assertEquals(ai_args["safe"], True)
self.assertEquals(ai_args["data"], data)
self.assertEquals(ai_args["correctSolidAngle"], worker.correct_solid_angle)
Expand All @@ -179,7 +180,7 @@ def test_1d_writer(self):
worker.dummy = "b"
worker.delta_dummy = "c"
worker.method = "d"
worker.polarization = "e"
worker.polarization_factor = "e"
worker.correct_solid_angle = "f"
worker.nbpt_rad = "g"
worker.nbpt_azim = 1
Expand All @@ -201,7 +202,7 @@ def test_2d_writer(self):
worker.dummy = "b"
worker.delta_dummy = "c"
worker.method = "d"
worker.polarization = "e"
worker.polarization_factor = "e"
worker.correct_solid_angle = "f"
worker.nbpt_rad = "g"
worker.nbpt_azim = 1
Expand Down
26 changes: 18 additions & 8 deletions pyFAI/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(self, azimuthalIntegrator=None,
self._normalization_factor = None # Value of the monitor: divides the intensity by this value for normalization
self.nbpt_azim, self.nbpt_rad = shapeOut
self._unit = units.to_unit(unit)
self.polarization = None
self.polarization_factor = None
self.dummy = dummy
self.delta_dummy = delta_dummy
self.correct_solid_angle = True
Expand Down Expand Up @@ -234,7 +234,7 @@ def __repr__(self):
"Number of points in azimuthal direction: %s" % self.nbpt_azim,
"Unit in radial dimension: %s" % self.unit,
"Correct for solid angle: %s" % self.correct_solid_angle,
"Polarization factor: %s" % self.polarization,
"Polarization factor: %s" % self.polarization_factor,
"Dark current image: %s" % self.dark_current_image,
"Flat field image: %s" % self.flat_field_image,
"Mask image: %s" % self.mask_image,
Expand Down Expand Up @@ -285,7 +285,7 @@ def process(self, data, normalization_factor=1.0, writer=None):
"dummy": self.dummy,
"delta_dummy": self.delta_dummy,
"method": self.method,
"polarization_factor": self.polarization,
"polarization_factor": self.polarization_factor,
# "filename": None,
"safe": self.is_safe,
"data": data,
Expand Down Expand Up @@ -444,9 +444,9 @@ def setJsonConfig(self, jsonconfig):
self.unit = units.to_unit(config.get("unit", units.TTH_DEG))
self.do_poisson = config.get("do_poisson")
if config.get("do_polarization"):
self.polarization = config.get("polarization")
self.polarization_factor = config.get("polarization_factor")
else:
self.polarization = None
self.polarization_factor = None
logger.info(self.ai.__repr__())
self.reset()
# For now we do not calculate the LUT as the size of the input image is unknown
Expand Down Expand Up @@ -481,7 +481,7 @@ def get_config(self):
config[key] = self.ai.__getattribute__(key)
except:
pass
for key in ["nbpt_azim", "nbpt_rad", "polarization", "dummy", "delta_dummy",
for key in ["nbpt_azim", "nbpt_rad", "polarization_factor", "dummy", "delta_dummy",
"correct_solid_angle", "dark_current_image", "flat_field_image",
"mask_image", "do_poisson", "shape", "method"]:
try:
Expand Down Expand Up @@ -560,7 +560,12 @@ class PixelwiseWorker(object):
"""
def __init__(self, dark=None, flat=None, solidangle=None, polarization=None,
mask=None, dummy=None, delta_dummy=None, device=None):
"""
"""Constructor of the worker
:param dark: array
:param flat: array
:param solidangle: solid-angle array
:param polarization: numpy array with 2D polarization corrections
:param device: Used to influance OpenCL behavour: can be "cpu", "GPU", "Acc" or even an OpenCL context
"""
self.ctx = None
Expand Down Expand Up @@ -645,8 +650,13 @@ class DistortionWorker(object):
"""
def __init__(self, detector=None, dark=None, flat=None, solidangle=None, polarization=None,
mask=None, dummy=None, delta_dummy=None, device=None):
"""
"""Constructor of the worker
:param dark: array
:param flat: array
:param solidangle: solid-angle array
:param polarization: numpy array with 2D polarization corrections
:param device: Used to influance OpenCL behavour: can be "cpu", "GPU", "Acc" or even an OpenCL context
"""

self.ctx = None
Expand Down

0 comments on commit 63271f6

Please sign in to comment.