-
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 #2009 from kif/2003_orientation
2003 orientation
- Loading branch information
Showing
16 changed files
with
396 additions
and
115 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
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
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 |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "24/11/2023" | ||
__date__ = "07/12/2023" | ||
__status__ = "stable" | ||
|
||
import logging | ||
|
@@ -572,14 +572,14 @@ def setFit2D(self, **kwarg): | |
elif kw == "splineFile": | ||
self.set_splineFile(kwarg[kw]) | ||
|
||
def _calc_pixel_index_from_orientation(self, plus_one=False): | ||
def _calc_pixel_index_from_orientation(self, center=True): | ||
"""Calculate the pixel index when considering the different orientations""" | ||
if plus_one: # used with corners | ||
m1 = self.shape[0] + 1 | ||
m2 = self.shape[1] + 1 | ||
else: #used with centers | ||
if center: | ||
m1 = self.shape[0] | ||
m2 = self.shape[1] | ||
else: #corner | ||
m1 = self.shape[0] + 1 | ||
m2 = self.shape[1] + 1 | ||
|
||
if self.orientation in (0,3): | ||
r1 = numpy.arange(m1, dtype="float32") | ||
|
@@ -597,6 +597,30 @@ def _calc_pixel_index_from_orientation(self, plus_one=False): | |
raise RuntimeError(f"Unsuported orientation: {self.orientation.name} ({self.orientation.value})") | ||
return r1, r2 | ||
|
||
def _reorder_indexes_from_orientation(self, d1, d2, center=True): | ||
"""Helper function to recalculate the index of pixels considering orientation | ||
# Not +=: do not mangle in place arrays""" | ||
if self.orientation in (0,3): | ||
return d1, d2 | ||
if center: | ||
shape1 = self.shape[0] - 1 | ||
shape2 = self.shape[1] - 1 | ||
else: #corner | ||
shape1 = self.shape[0] | ||
shape2 = self.shape[1] | ||
|
||
if self.orientation==1: | ||
d1 = shape1 - d1 | ||
d2 = shape2 - d2 | ||
elif self.orientation==2: | ||
d1 = shape1 - d1 | ||
elif self.orientation == 4: | ||
d2 = shape2 - d2 | ||
else: | ||
raise RuntimeError(f"Unsuported orientation: {self.orientation.name} ({self.orientation.value})") | ||
return d1, d2 | ||
|
||
|
||
def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=True): | ||
""" | ||
Calculate the position of each pixel center in cartesian coordinate | ||
|
@@ -620,28 +644,24 @@ def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=Tru | |
""" | ||
if self.shape: | ||
if (d1 is None) or (d2 is None): | ||
r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
d1 = expand2d(r1, self.shape[1], False) | ||
d2 = expand2d(r2, self.shape[0], True) | ||
r1, r2 = self._calc_pixel_index_from_orientation(center) | ||
delta = 0 if center else 1 | ||
d1 = expand2d(r1, self.shape[1] + delta, False) | ||
d2 = expand2d(r2, self.shape[0] + delta, True) | ||
else: | ||
if self.orientation in (0,3): | ||
pass | ||
elif self.orientation==1: | ||
d1 = self.shape[0] - 1 - d1 | ||
d2 = self.shape[1] - 1 - d2 | ||
elif self.orientation==2: | ||
d1 = self.shape[0] - 1 - d1 | ||
elif self.orientation == 4: | ||
d2 = self.shape[1] - 1 - d2 | ||
else: | ||
raise RuntimeError(f"Unsuported orientation: {self.orientation.name} ({self.orientation.value})") | ||
|
||
d1, d2 = self._reorder_indexes_from_orientation(d1, d2, center) | ||
elif "ndim" in dir(d1): | ||
if d1.ndim == 2: | ||
self.shape = d1.shape | ||
if center: | ||
self.shape = d1.shape | ||
else: #corner | ||
self.shape = tuple(i-1 for i in d1.shape) | ||
elif "ndim" in dir(d2): | ||
if d2.ndim == 2: | ||
self.shape = d2.shape | ||
if center: | ||
self.shape = d2.shape | ||
else: #corner | ||
self.shape = tuple(i-1 for i in d2.shape) | ||
|
||
if center: | ||
# avoid += It modifies in place then segfaults | ||
|
@@ -736,7 +756,7 @@ def get_pixel_corners(self, correct_binning=False): | |
if self._pixel_corners is None: | ||
with self._sem: | ||
if self._pixel_corners is None: | ||
r1, r2 = self._calc_pixel_index_from_orientation(True) | ||
r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
# like numpy.ogrid | ||
d1 = expand2d(r1, self.shape[1] + 1, False) | ||
d2 = expand2d(r2, self.shape[0] + 1, True) | ||
|
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__ = "23/11/2023" | ||
__date__ = "07/12/2023" | ||
__status__ = "production" | ||
|
||
import os | ||
|
@@ -130,21 +130,12 @@ def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=Tru | |
""" | ||
if self.shape: | ||
if (d1 is None) or (d2 is None): | ||
r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
d1 = expand2d(r1, self.shape[1], False) | ||
d2 = expand2d(r2, self.shape[0], True) | ||
r1, r2 = self._calc_pixel_index_from_orientation(center) | ||
delta = 0 if center else 1 | ||
d1 = expand2d(r1, self.shape[1] + delta, False) | ||
d2 = expand2d(r2, self.shape[0] + delta, True) | ||
else: | ||
if self.orientation in (0,3): | ||
pass | ||
elif self.orientation == 1: | ||
d1 = self.shape[0] - 1 - d1 | ||
d2 = self.shape[1] - 1 - d2 | ||
elif self.orientation == 2: | ||
d1 = self.shape[0] - 1 - d1 | ||
elif self.orientation == 4: | ||
d2 = self.shape[1] - 1 - d2 | ||
else: | ||
raise RuntimeError(f"Unsuported orientation: {self.orientation.name} ({self.orientation.value})") | ||
d1, d2 = self._reorder_indexes_from_orientation(d1, d2, center) | ||
|
||
if self.offset1 is None or self.offset2 is None: | ||
delta1 = delta2 = 0. | ||
|
@@ -535,21 +526,12 @@ def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=Tru | |
""" | ||
if self.shape: | ||
if ((d1 is None) or (d2 is None)): | ||
r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
d1 = expand2d(r1, self.shape[1], False) | ||
d2 = expand2d(r2, self.shape[0], True) | ||
r1, r2 = self._calc_pixel_index_from_orientation(center) | ||
delta = 0 if center else 1 | ||
d1 = expand2d(r1, self.shape[1] + delta, False) | ||
d2 = expand2d(r2, self.shape[0] + delta, True) | ||
else: | ||
if self.orientation in (0,3): | ||
pass | ||
elif self.orientation==1: | ||
d1 = self.shape[0] - 1 - d1 | ||
d2 = self.shape[1] - 1 - d2 | ||
elif self.orientation==2: | ||
d1 = self.shape[0] - 1 - d1 | ||
elif self.orientation == 4: | ||
d2 = self.shape[1] - 1 - d2 | ||
else: | ||
raise RuntimeError(f"Unsuported orientation: {self.orientation.name} ({self.orientation.value})") | ||
d1, d2 = self._reorder_indexes_from_orientation(d1, d2, center) | ||
|
||
if (self.offset1 is None) or (self.offset2 is None): | ||
delta1 = delta2 = 0. | ||
|
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__ = "23/11/2023" | ||
__date__ = "07/12/2023" | ||
__status__ = "production" | ||
|
||
import functools | ||
|
@@ -213,6 +213,7 @@ def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=Tru | |
p1 = numpy.outer(d1, numpy.ones(self.shape[1])) | ||
p2 = numpy.outer(numpy.ones(self.shape[0]), d2) | ||
else: | ||
d1, d2 = self._reorder_indexes_from_orientation(d1, d2, center) | ||
if center: | ||
# Not +=: do not mangle in place arrays | ||
d1 = d1 + 0.5 | ||
|
@@ -389,9 +390,10 @@ def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=Tru | |
""" | ||
if self.shape: | ||
if (d1 is None) or (d2 is None): | ||
r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
d1 = mathutil.expand2d(r1, self.shape[1], False) | ||
d2 = mathutil.expand2d(r2, self.shape[0], True) | ||
r1, r2 = self._calc_pixel_index_from_orientation(center) | ||
delta = 0 if center else 1 | ||
d1 = mathutil.expand2d(r1, self.shape[1] + delta, False) | ||
d2 = mathutil.expand2d(r2, self.shape[0] + delta, True) | ||
corners = self.get_pixel_corners() | ||
if center: | ||
# note += would make an increment in place which is bad (segfault !) | ||
|
@@ -617,9 +619,10 @@ def get_pixel_corners(self, correct_binning=False): | |
# TODO !!! | ||
def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=True): | ||
if (d1 is None) or d2 is None: | ||
r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
d1 = mathutil.expand2d(r1, self.MAX_SHAPE[1], False) | ||
d2 = mathutil.expand2d(r2, self.MAX_SHAPE[0], True) | ||
r1, r2 = self._calc_pixel_index_from_orientation(center) | ||
delta = 0 if center else 1 | ||
d1 = mathutil.expand2d(r1, self.MAX_SHAPE[1] + delta, False) | ||
d2 = mathutil.expand2d(r2, self.MAX_SHAPE[0] + delta, True) | ||
corners = self.get_pixel_corners() | ||
if center: | ||
# avoid += It modifies in place and segfaults | ||
|
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 |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
__contact__ = "[email protected]" | ||
__license__ = "MIT" | ||
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "23/11/2023" | ||
__date__ = "07/12/2023" | ||
__status__ = "production" | ||
|
||
|
||
|
@@ -178,10 +178,13 @@ def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=Tru | |
d1 and d2 must have the same shape, returned array will have | ||
the same shape. | ||
""" | ||
if (d1 is None) or d2 is None: | ||
r1, r2 = self._calc_pixel_index_from_orientation(False) | ||
d1 = mathutil.expand2d(r1, self.shape[1], False) | ||
d2 = mathutil.expand2d(r2, self.shape[0], True) | ||
if (d1 is None) or (d2 is None): | ||
r1, r2 = self._calc_pixel_index_from_orientation(center) | ||
delta = 0 if center else 1 | ||
d1 = mathutil.expand2d(r1, self.shape[1] + delta, False) | ||
d2 = mathutil.expand2d(r2, self.shape[0] + delta, True) | ||
else: | ||
d1, d2 = self._reorder_indexes_from_orientation(d1, d2, center) | ||
corners = self.get_pixel_corners() | ||
if center: | ||
# avoid += It modifies in place and segfaults | ||
|
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__ = "2021 European Synchrotron Radiation Facility, Grenoble, France" | ||
__date__ = "21/11/2023" | ||
__date__ = "07/12/2023" | ||
__status__ = "production" | ||
|
||
import numpy | ||
|
@@ -188,6 +188,7 @@ def calc_cartesian_positions(self, d1=None, d2=None, center=True, use_cython=Tru | |
p1 = numpy.outer(d1, numpy.ones(self.shape[1])) | ||
p2 = numpy.outer(numpy.ones(self.shape[0]), d2) | ||
else: | ||
d1, d2 = self._reorder_indexes_from_orientation(d1, d2, center) | ||
if center: | ||
# Not +=: do not mangle in place arrays | ||
d1 = d1 + 0.5 | ||
|
Oops, something went wrong.