-
Notifications
You must be signed in to change notification settings - Fork 52
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
dials.image_viewer
: add option to display in the "best fit" frame
#1716
Conversation
dagewa
commented
May 19, 2021
- This should be moved so that it is done once per detector, not every time an image is displayed
- It should also be made optional with a checkbox to control
- This should be moved so that it is done once per detector, not every time an image is displayed - It should also be made optional with a checkbox to control
Also, need to check if this breaks the beam centre and other overlays |
Checking now |
Looking good! |
2 theta > 90° though
|
Looking at that one now |
OK, beam centre nonsense is baked in everywhere which causes massive failures if the two-theta angle is > 90 - because there is no beam centre However this current state is a long way along the road to fixing. But the rest of the road is a rocky and pothole strewn mudbath, so may be hard going. |
I re-ran my rotation tests from previous attempts to fix this. Here are the commands again:
Then use dials.image_viewer on each of the .expt files in turn to see what happens. On both master and this project_2d branch, both single and multi panel images appear rotated correctly. 👍 |
Also, calculate only when this setting is toggled, not every time an image is displayed. Slightly nasty approach by assigning to an attribute of the detector, but avoids modifying get_flex_image_multipanel signature.
I completed additional work as per the first comment. It might be a bit messy still. For instance, I tried setting the default to The whole image may shift between the two modes. This is a minor annoyance I don't have time to look at. Finally, as @graeme-winter points out, there are still issues at high angle, which are not due to the best-frame projection but due to problems calculating beam centre. |
dials.image_viewer
: add option to display in the "best fit" frame
Codecov Report
@@ Coverage Diff @@
## main #1716 +/- ##
==========================================
+ Coverage 66.65% 71.62% +4.96%
==========================================
Files 615 867 +252
Lines 68872 90876 +22004
Branches 9572 11314 +1742
==========================================
+ Hits 45905 65087 +19182
- Misses 21042 23769 +2727
- Partials 1925 2020 +95 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I don't have the 2theta tests. On my rotation tests things look good.
@dagewa taking a quick look at the default |
Some confusion in the code...
will set it as a string value however
later on assigns as the index of the selection. I do not think that this feature is unique to this new option. |
Fortunately this is never actually read anyway 🙄 |
Yes, I admit to getting confused by this while copy-and-pasting, but I could not resolve in the time frame. I would welcome anyone with a better idea of what is going on in the image viewer code to tidy up, but I fear starting down that route might end up like an episode of Hoarder Homes. |
Am looking |
The issue is that the attribute dials/util/image_viewer/slip_viewer/frame.py Line 497 in a8050e2
however this is only called after the image is generated here: dials/util/image_viewer/slip_viewer/frame.py Lines 423 to 431 in a8050e2
Unfortunately the method can't be called before this line, as it appears to depend on attributes defined as part of generating the image... |
The reason it can't be called before the image is created, is because this PR explicitly adds an attribute to |
Right, so what happens is we call |
So... if we want this to work the only sane option is to evaluate it as part of the image loading. That seems a long way from ideal. |
I hold the opinion that though this change set is not perfect, the image viewer is a lot better with the changes in than out -> am minded to suggest we merge in it's current form and add a new issue about the annoying behaviour. I welcome other perspectives. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
command_line/image_viewer.py
Outdated
@@ -32,6 +32,8 @@ | |||
.type = int | |||
color_scheme = *grayscale rainbow heatmap invert | |||
.type = choice | |||
project_onto = *lab image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably I would prefer projection
than project_onto
newsfragments/1716.feature
Outdated
@@ -0,0 +1 @@ | |||
``dials.image_viewer``: Add an option to display in a best-fit "image" coordinate frame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth @ndevenish poking at this a little to get some kind of "snapped to grid" idea in there. I have no inspiration otherwise would do myself. Worth making this readable by the general reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, should also now say that the option is the new default
@@ -524,70 +524,7 @@ def get_key(self, file_name_or_data): | |||
return super().get_key(file_name_or_data) | |||
|
|||
def update_settings(self, layout=True): | |||
# XXX The zoom level from the settings panel are not taken into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rjgildea improving his -ve line count, approve!
This aliasing did completely confuse me while I was trying to change the default, so appreciate it being removed.
That's a couple of haunted trees felled anyway.
# Calculate 2D origin, fast and slow vectors for detector projected onto | ||
# a best fit frame. FIXME this should be done once for the detector, not | ||
# here for every image we want to display! | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EAFP is OK, but wonder if this is a little harder to read than just a "hasattr" or even setting the attribute to None
when the object is created (which would involve a little more exploration but helps to leave breadcrumbs for a longer term improvement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh the FIXME
comment is out of date too btw. It came from the first commit where project_2d
was called every time this function run rather than checking the detector for pre-calculated results. I did do this in a rush yesterday...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
panels
is a misnomer here, AFAICT. It is actually a Detector
object. We could assign this attribute when the experiments are first loaded in, to ensure it is there whenever it matters.
An alternative is what I suggested at the bottom of cctbx/dxtbx#224 (comment), which is that the project_2d
function gets moved to the Detector
object itself. Then any detector can tell a viewer how to lay out its panels in 2D. This would have the advantage of providing a method that could be overridden in special cases, like that of the P12M, avoiding the special case code here in the image viewer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment was aimed at the try/except AttributeError
pattern, but agree on moving it to Detector as proposed. Could be worth considering if we can do sooner rather than later 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, but actually it would probably have to be in the Format
, because I don't think a Detector
knows what detector it is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
until then:
projected_axes = getattr(panels, "projected_2d", None)
replaces the 4 lines
# Calculate 2D origin, fast and slow vectors for detector projected onto | ||
# a best fit frame. FIXME this should be done once for the detector, not | ||
# here for every image we want to display! | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
until then:
projected_axes = getattr(panels, "projected_2d", None)
replaces the 4 lines
if not hasattr(detector, "projected_2d"): | ||
detector.projected_2d = project_2d(detector) | ||
elif detector.projected_2d is None: | ||
detector.projected_2d = project_2d(detector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not hasattr(detector, "projected_2d"): | |
detector.projected_2d = project_2d(detector) | |
elif detector.projected_2d is None: | |
detector.projected_2d = project_2d(detector) | |
if not getattr(detector, "projected_2d", None): | |
detector.projected_2d = project_2d(detector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ this is kinda what I was getting at 🙂
I appreciate I am not always clear though
get_flex_image_multipanel is also used by export_bitmaps where the detector will not have been furnished with 2d projection (but maybe it should be)
Following the latest change set @dagewa something is looking good - imported / integrated multi-two-theta offset scan with overlay of reflections: bonus points - for reasons that are opaque no longer crashes for two theta > 90° 🤔 🤷♂️ 👍 |
I am rather puzzled by the fact that the fix fixes more than I thought it fixed 🤔 |