Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage orientation of detector #2001

Merged
merged 32 commits into from
Nov 23, 2023
Merged

Manage orientation of detector #2001

merged 32 commits into from
Nov 23, 2023

Conversation

kif
Copy link
Member

@kif kif commented Nov 21, 2023

This is likely to be a beefy one ...

  • create the detector orientation tag: value 0 to be used for "do not care" else value [1..8]
  • Use this tag when calculating the pixel center coordinate
  • Use this tag when calculating the pixel corner coordinate
  • Use this tag when calculating the x,y,z of a list of pixels (used while calibrating)
  • Save / restore this attribute into the Nexus detector file
  • Save / restore into the PONI-file
  • Save / restore into the config
  • Add some tests specific to orientation change
  • Ensure the Detector cache gets reset when changing the orientation (--> use a property)
  • Ensure the geometry cache gets reset when changing the orientation ( what is the best way of doing this ?)

close #1994

@kif kif added the work in progress Don't review label Nov 21, 2023
@kif kif requested review from loichuder and EdgarGF93 November 21, 2023 16:09
Rotate90 = 8

Orientation(0).__doc__ = "An orientation flag is not set."
Orientation(1).__doc__ = "Camera default. Origin at the top left of the image when looking at the sample."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So origin at top right when looking from the sample ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enum is the default one used in EXIF, for visible light cameras.

In pyFAI, the origin is at the bottom left when looking from the sample. Thus the orientation should be flipped-ud for the origin at the bottom and flipped-rl to change the direction of sight. This makes the default orientation used in pyFAI to 3 or Rotate180.

I just got the answer from Dectris that their detector have to be seen from the sample and not from the other side.

At this stage, orientation is just shipped around and used nowhere ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

When speaking about images, looking at the detector from the sample makes sense. Looking at the sample from the detector is a bit harder to figure out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. After thinking again about it this morning, this is indeed just a personal feeling.

@kif
Copy link
Member Author

kif commented Nov 23, 2023

I believe this PR is beefy enough -> ready for merge (once test pass)
Related issues are linked in the project

@kif kif added ready to merge Please review and removed work in progress Don't review labels Nov 23, 2023
@kif
Copy link
Member Author

kif commented Nov 23, 2023

Checked with Edgar that flipped image can be processed as expected. "just" declare an orientation different from "3"

src/pyFAI/detectors/_common.py Outdated Show resolved Hide resolved
src/pyFAI/detectors/_common.py Outdated Show resolved Hide resolved
src/pyFAI/detectors/_dectris.py Outdated Show resolved Hide resolved
src/pyFAI/detectors/_dectris.py Outdated Show resolved Hide resolved
@@ -640,4 +643,5 @@ def set_config(self, config):
raise err
self.set_pixel1(config.get("pixel1"))
self.set_pixel2(config.get("pixel2"))
self.orientation = Orientation(config.get("orientatio", 3))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.orientation = Orientation(config.get("orientatio", 3))
self.orientation = Orientation(config.get("orientation", 3))

src/pyFAI/detectors/orientation.py Outdated Show resolved Hide resolved
@@ -348,6 +361,8 @@ def test_corner_array(self):
for data, space in params:
with self.subTest(data=data, space=space):
geo = geometry.Geometry(**data)
print(data)
print(geo.detector.orientation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed, I guess.

src/pyFAI/test/test_detector.py Outdated Show resolved Hide resolved
src/pyFAI/test/test_detector.py Outdated Show resolved Hide resolved
src/pyFAI/test/test_detector.py Outdated Show resolved Hide resolved
@kif kif force-pushed the 1994_orientation branch from 7d9e966 to f68cc43 Compare November 23, 2023 12:42
@EdgarGF93
Copy link
Collaborator

EdgarGF93 commented Nov 23, 2023

It does fix the dioptas incompatibility.
I did the calibration with dioptas and pyFAI on the same .edf file, from a Pilatus1M.
As we said, the PONI and rotation values generated by pyFAI-calib2 and dioptas are different, therefore the result of AzimuthalIntegrator.integrate2d is wrong for the dioptas file. After resetting the azimuthal integrator instance and changing manually the orientation of the detector instance to '2', we get a good reshaping of the pattern (with the azimuthal axis inverted):

image

Orientation(0).__doc__ = "An orientation flag is not set."
Orientation(1).__doc__ = "Camera default. Origin at the top left of the image when looking at the sample."
Orientation(2).__doc__ = "Origin at the top left of the image when looking from the sample."
Orientation(3).__doc__ = "Native orientation of pyFAI. Origin at the bottom left when looking from the sample"
Copy link
Collaborator

@EdgarGF93 EdgarGF93 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me. If I understood, choosing the orientation 3 (native pyFAI) would be equal to 0 (default, non-defined) during the calculation of pixel coordinates?

Edit: Yes :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well spotted

src/pyFAI/detectors/_rayonix.py Outdated Show resolved Hide resolved
@kif kif merged commit 965f6d3 into silx-kit:main Nov 23, 2023
@t20100
Copy link
Member

t20100 commented Dec 11, 2023

attn @CPrescher, a "detector orientation tag" has been added to pyFAI to deal with image flip (not released yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Please review
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Poni file generated by Dioptas are incompatible with pyFAI ?
4 participants