Skip to content

Generalise flat bank viewer - #871

Open
jl-wynen wants to merge 7 commits into
mainfrom
general-flat-bank-viewer
Open

jl-wynen wants to merge 7 commits into
mainfrom
general-flat-bank-viewer

Conversation

@jl-wynen

@jl-wynen jl-wynen commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

This PR generalises the FlatVOxelViewer if DREAM and moves the implementation into ESSreduce.

I changed how the dimension selector works to allow users some control over which dimensions are shown on which axis. And I also added support for slicing dims so we can get slicer plots at the same time.
This was mostly written by Claude. I tested the widget with data fro dream and bifrost.

I removed the interactive elements. Now you have to specify which dims go on which axis when constructing the viewer.

@jl-wynen
jl-wynen requested a review from nvaytet November 12, 2026 14:58
@github-actions github-actions Bot added essdiffraction Issues for essdiffraction. essreduce Issues for essreduce. essspectroscopy Issues for essspectroscopy. labels Nov 12, 2026
@jl-wynen
jl-wynen force-pushed the general-flat-bank-viewer branch from 6f95980 to a4bd5d7 Compare November 12, 2026 15:21
@g5t

g5t commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Does channel * length have the same sense as pixel number? E.g., can I multiply arc * tube by 900 and add it to channel * length to get the pixel number?
If so, then this could be a great starting point for a mpltoolbox interface to visualize/update a mask too (I guess that is already planned and/or implemented).

@jl-wynen

Copy link
Copy Markdown
Member Author

Does channel * length have the same sense as pixel number? E.g., can I multiply arc * tube by 900 and add it to channel * length to get the pixel number? If so, then this could be a great starting point for a mpltoolbox interface to visualize/update a mask too (I guess that is already planned and/or implemented).

This tool allows you to reorder the plot dims any way you like. But yes, in the example above, the order corresponds to the detector number.

We have not planned to add masking tools to this. But that could be an option in the future.

@jokasimr

Copy link
Copy Markdown
Contributor

Automated review found two issues:

Dream diagnostics assumes input has sumo and sector dimensions

import scipp as sc
from ess.dream.diagnostics import FlatVoxelViewer

dims = ("module", "segment", "counter", "wire", "strip")
mantle = sc.DataArray(
    sc.ones(sizes=dict.fromkeys(dims, 2), unit="counts"),
    coords={dim: sc.arange(dim, 2, unit=None) for dim in dims},
)

FlatVoxelViewer({"mantle": mantle})
# ValueError: Dims ['sumo', 'sector'] are not in the data.

This input worked before the PR.

Bifrost diagnostics assume input has .dims

import scipp as sc
from ess.bifrost.diagnostics import FlatDetectorViewer

bank = sc.DataArray(
    sc.ones(
        sizes={"arc": 2, "channel": 3, "tube": 4, "length": 5},
        unit="counts",
    )
)

FlatDetectorViewer({"bank": bank})
# AttributeError: 'dict' object has no attribute 'dims'

@jokasimr

jokasimr commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Does primary define what dimension has the largest "stride" the figure axis?

If there is 3 detector dimensions per axis, specifying the first dimension is insufficient to determine the order, how does it work in that case?

@jokasimr

Copy link
Copy Markdown
Contributor

I think the interface looks quite noisy and complicated. I have a suggestion for a simpler interface that uses ipywidgets TagInputs widget to let the user order the dimensions that make each axis.

Screenshot From 2026-11-19 12-39-25

Also added support for reversing the directions of the axes because that is something often requested.

@jl-wynen

Copy link
Copy Markdown
Member Author

I considered using tag inputs but rejected that idea. It would require a lot of syncing between the widgets because you have to ensure that all dims are always represented exactly once. Plus, it requires typing the dim names and the input field is often invisible. Can you share your code so we can compare?

@jokasimr

Copy link
Copy Markdown
Contributor

I considered using tag inputs but rejected that idea. It would require a lot of syncing between the widgets because you have to ensure that all dims are always represented exactly once. Plus, it requires typing the dim names and the input field is often invisible. Can you share your code so we can compare?

I've pushed the changes here: #891

I've not reviewed the code. The idea was just to sketch the implementation of the alternative interface.

@nvaytet

nvaytet commented Nov 19, 2026

Copy link
Copy Markdown
Member

@g5t another tool here: #834 is about masking (as well as displaying banks).
Would this fit your needs or is the flattened view required for Bifrost?

@nvaytet

nvaytet commented Nov 19, 2026

Copy link
Copy Markdown
Member

@jl-wynen I think this looks difficult to use.
As @jokasimr pointed out, I think the interface is a bit cluttered, but more importantly, after switching a few dimensions, I doubt many people would understand what is still being plotted?

I would vote for maybe making a few simpler tools/plots rather than one that does everything?
I think the plot in livedata looks more useful.

Screenshot_20261119_225026

I know you can achieve the same plot here (without the red lines), but I think the layout being static (i.e. not being able to switch the dims) is an advantage there?
We could also think about using the DetectorExplorer from #834 where instead of having 45 subplots, we could make 5 (one for every arc) or 9 (one for every channel), and then have a slider for the remaining dim?

Then you get the masking for free ;-)

@nvaytet

nvaytet commented Nov 19, 2026

Copy link
Copy Markdown
Member

I tried it and it works out of the box

Screenshot_20261119_231251

But I don't know if it's any more useful.

@jl-wynen

Copy link
Copy Markdown
Member Author

This works for BIFROST. But how would you handle DREAM with 5+ dimensions? Is it possible to control which dims are shown in what way?

We can make it static, we wouldn't lose much if we leave the constructor arguments to customise the dims.

@jl-wynen
jl-wynen force-pushed the general-flat-bank-viewer branch from 6b2f26e to 61d2695 Compare November 20, 2026 13:37

@nvaytet nvaytet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested manually on dream data.
Looks good.

)
figure_box.children = [slicer]

selector = ipw.ToggleButtons(options=list(data))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we put the plots for the different banks inside tabs? Also make slicers inside each tab, and then we don't need to re-create slicers as we switch banks?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did it this way to make the plots lazily for two reasons:

  • It should be faster to get the first plot
  • If a plot fails, the others are still shown. (Happens for DREAM if you don't sum over tof because there are 7 dims and flatten can't handle that.) But I could also catch exceptions for each tab separately and show an error message.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why can't flatten handle that case? Is it something to do with the limit of 6 dimensions in Scipp arrays?

@nvaytet nvaytet Nov 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it works fine, and the argument for

It should be faster to get the first plot

is a good one.

I think for a later addition, we could have the thing we talked about when you have separators enabled, and you click in one region, it would just zoom in on that section of the data. If we add autoscale=False in the default args, it should work fine.
But this can be added in a follow-up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why can't flatten handle that case? Is it something to do with the limit of 6 dimensions in Scipp arrays?

yes

@nvaytet

nvaytet commented Nov 23, 2026

Copy link
Copy Markdown
Member

There seems to be a mismatch between the numbers displayed in the hover cursor info and the tick labels on the axes.
Here I'm hovering over the first module: it is labeled as module 1 on the axes, but the cursor says module 0.

Screenshot_20261123_100633

@jl-wynen

Copy link
Copy Markdown
Member Author

Fixed

@nvaytet

nvaytet commented Nov 23, 2026

Copy link
Copy Markdown
Member

Still 2 failing tests after the last update.

@jl-wynen
jl-wynen force-pushed the general-flat-bank-viewer branch from 8b82a9c to d9896ec Compare November 23, 2026 15:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

essdiffraction Issues for essdiffraction. essreduce Issues for essreduce. essspectroscopy Issues for essspectroscopy.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants