-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2032 from kif/1957_pixel_corners
Register the number of pixel corners
- Loading branch information
Showing
7 changed files
with
80 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# Project: Azimuthal integration | ||
# https://github.com/silx-kit/pyFAI | ||
# | ||
# Copyright (C) 2014-2022 European Synchrotron Radiation Facility, Grenoble, France | ||
# Copyright (C) 2014-2024 European Synchrotron Radiation Facility, Grenoble, France | ||
# | ||
# Principal author: Jérôme Kieffer ([email protected]) | ||
# | ||
|
@@ -34,7 +34,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "21/03/2022" | ||
__date__ = "12/01/2024" | ||
__status__ = "stable" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# Project: Fast Azimuthal integration | ||
# https://github.com/silx-kit/pyFAI | ||
# | ||
# Copyright (C) 2017-2018 European Synchrotron Radiation Facility, Grenoble, France | ||
# Copyright (C) 2017-2024 European Synchrotron Radiation Facility, Grenoble, France | ||
# | ||
# Principal author: Jérôme Kieffer ([email protected]) | ||
# | ||
|
@@ -37,7 +37,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "22/11/2023" | ||
__date__ = "12/01/2024" | ||
__status__ = "production" | ||
|
||
from ._common import Detector, Orientation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "12/12/2023" | ||
__date__ = "12/01/2024" | ||
__status__ = "stable" | ||
|
||
import logging | ||
|
@@ -100,14 +100,15 @@ class Detector(metaclass=DetectorMeta): | |
Generic class representing a 2D detector | ||
""" | ||
MANUFACTURER = None | ||
|
||
CORNERS = 4 | ||
force_pixel = False # Used to specify pixel size should be defined by the class itself. | ||
aliases = [] # list of alternative names | ||
registry = {} # list of detectors ... | ||
uniform_pixel = True # tells all pixels have the same size | ||
IS_FLAT = True # this detector is flat | ||
IS_CONTIGUOUS = True # No gaps: all pixels are adjacents, speeds-up calculation | ||
API_VERSION = "1.0" | ||
API_VERSION = "1.1" | ||
# 1.1: support for CORNER attribute | ||
|
||
HAVE_TAPER = False | ||
"""If true a spline file is mandatory to correct the geometry""" | ||
|
@@ -756,6 +757,7 @@ def get_pixel_corners(self, correct_binning=False): | |
if self._pixel_corners is None: | ||
with self._sem: | ||
if self._pixel_corners is None: | ||
assert self.CORNERS == 4, "overwrite this method when hexagonal !" | ||
# r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
# like numpy.ogrid | ||
# d1 = expand2d(r1, self.shape[1] + 1, False) | ||
|
@@ -790,6 +792,7 @@ def _rebin_pixel_corners(self): | |
r1 = self._pixel_corners.shape[1] // self.shape[1] | ||
if r0 == 0 or r1 == 0: | ||
raise RuntimeError("Cannot unbin an image ") | ||
assert self.CORNERS==4, "not valid with hexagonal pixels" | ||
pixel_corners = numpy.zeros((self.shape[0], self.shape[1], 4, 3), dtype=numpy.float32) | ||
pixel_corners[:,:, 0,:] = self._pixel_corners[::r0,::r1, 0,:] | ||
pixel_corners[:,:, 1,:] = self._pixel_corners[r0 - 1::r0,::r1, 1,:] | ||
|
@@ -815,7 +818,7 @@ def set_pixel_corners(self, ary): | |
# Validation for the array | ||
assert ary.ndim == 4 | ||
assert ary.shape[3] == 3 # 3 coordinates in Z Y X | ||
assert ary.shape[2] >= 3 # at least 3 corners per pixel | ||
assert ary.shape[2] == self.CORNERS # at least 3 corners per pixel | ||
|
||
z = ary[..., 0] | ||
is_flat = (z.max() == z.min() == 0.0) | ||
|
@@ -845,6 +848,7 @@ def save(self, filename): | |
det_grp["API_VERSION"] = numpy.string_(self.API_VERSION) | ||
det_grp["IS_FLAT"] = self.IS_FLAT | ||
det_grp["IS_CONTIGUOUS"] = self.IS_CONTIGUOUS | ||
det_grp["CORNERS"] = self.CORNERS | ||
if self.dummy is not None: | ||
det_grp["dummy"] = self.dummy | ||
if self.delta_dummy is not None: | ||
|
@@ -1208,6 +1212,7 @@ class NexusDetector(Detector): | |
"aliases", | ||
"IS_FLAT", | ||
"IS_CONTIGUOUS", | ||
"CORNERS" | ||
"force_pixel", | ||
"_filename", | ||
"uniform_pixel") + Detector._UNMUTABLE_ATTRS + Detector._MUTABLE_ATTRS | ||
|
@@ -1239,6 +1244,11 @@ def load(self, filename): | |
raise RuntimeError("No detector definition in this file %s" % filename) | ||
name = posixpath.split(det_grp.name)[-1] | ||
self.aliases = [name.replace("_", " "), det_grp.name] | ||
if "API_VERSION" in det_grp: | ||
self.API_VERSION = det_grp["API_VERSION"][()].decode() | ||
api = [int(i) for i in self.API_VERSION.split(".")] | ||
if api>=[1,1] and "CORNERS" in det_grp: | ||
self.CORNERS = det_grp["CORNERS"][()] | ||
if "IS_FLAT" in det_grp: | ||
self.IS_FLAT = det_grp["IS_FLAT"][()] | ||
if "IS_CONTIGUOUS" in det_grp: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "21/11/2023" | ||
__date__ = "12/01/2024" | ||
__status__ = "production" | ||
|
||
|
||
|
@@ -57,17 +57,18 @@ class HexDetector(Detector): | |
uniform_pixel = False # ensures we use the array of position ! | ||
IS_CONTIGUOUS = False | ||
IS_FLAT = True | ||
CORNERS = 6 | ||
|
||
@staticmethod | ||
def build_pixel_coordinates(shape, pitch=1): | ||
@classmethod | ||
def build_pixel_coordinates(cls, shape, pitch=1): | ||
"""Build the 4D array with pixel coordinates for a detector composed of hexagonal-pixels | ||
:param shape: 2-tuple with size of the detector in number of pixels (y, x) | ||
:param pitch: the distance between two pixels | ||
:return: array with pixel coordinates | ||
""" | ||
assert len(shape) == 2 | ||
ary = numpy.zeros(shape+(6, 3), dtype=numpy.float32) | ||
ary = numpy.zeros(shape + (cls.CORNERS, 3), dtype=numpy.float32) | ||
sqrt3 = sqrt(3.0) | ||
h = 0.5*sqrt3 | ||
r = numpy.linspace(0, 2, 7, endpoint=True)[:-1] - 0.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT+" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "12/12/2023" | ||
__date__ = "12/01/2024" | ||
|
||
import os | ||
import shutil | ||
|
@@ -210,12 +210,12 @@ def test_nexus_detector(self): | |
if err2 > 1e-6: | ||
logger.error("%s precision on pixel position 1 is better than 1µm, got %e", det_name, err2) | ||
|
||
self.assertTrue(err1 < 1e-6, "%s precision on pixel position 1 is better than 1µm, got %e" % (det_name, err1)) | ||
self.assertTrue(err2 < 1e-6, "%s precision on pixel position 2 is better than 1µm, got %e" % (det_name, err2)) | ||
self.assertLess(err1, 1e-6, f"{det_name} precision on pixel position 1 is better than 1µm, got {err1:e}") | ||
self.assertLess(err2, 1e-6, f"{det_name} precision on pixel position 2 is better than 1µm, got {err1:e}") | ||
if not det.IS_FLAT: | ||
err = abs(r[2] - o[2]).max() | ||
self.assertTrue(err < 1e-6, "%s precision on pixel position 3 is better than 1µm, got %e" % (det_name, err)) | ||
|
||
self.assertEqual(det.CORNERS, new_det.CORNERS, "Number of pixel corner is consistent") | ||
# check Pilatus with displacement maps | ||
# check spline | ||
# check SPD displacement | ||
|
@@ -353,6 +353,8 @@ def test_displacements(self): | |
|
||
def test_hexagonal_detector(self): | ||
pix = detector_factory("Pixirad1") | ||
self.assertEqual(pix.CORNERS, 6, "detector has 6 corners") | ||
|
||
wl = 1e-10 | ||
from ..calibrant import ALL_CALIBRANTS | ||
from ..azimuthalIntegrator import AzimuthalIntegrator | ||
|