Skip to content

Add spatial_dims parameter to ROIFilter for dense data support#284

Merged
SimonHeybrock merged 3 commits intomainfrom
dense-detector-view-roi
Dec 1, 2025
Merged

Add spatial_dims parameter to ROIFilter for dense data support#284
SimonHeybrock merged 3 commits intomainfrom
dense-detector-view-roi

Conversation

@SimonHeybrock
Copy link
Member

Summary

  • ROIFilter now accepts an explicit spatial_dims parameter to control which dimensions get flattened when applying the filter
  • This enables support for dense data arrays like (time, x, y) where the time dimension should be preserved while only the spatial dimensions are flattened
  • RollingDetectorView.make_roi_filter() now passes detector_number.dims as spatial_dims

For projections where indices represent a subset of the detector (e.g., a z=0 slice), spatial_dims should be set to the full detector dimensions rather than being inferred from indices.dims.

Test plan

  • New tests verify dense data (time, x, y) preserves time dimension
  • Existing tests updated to explicitly pass spatial_dims for projection cases

🤖 Generated with Claude Code

ROIFilter now accepts an explicit spatial_dims parameter to control which
dimensions get flattened when applying the filter. This enables support for
dense data arrays like (time, x, y) where the time dimension should be
preserved while only the spatial dimensions are flattened.

For projections where indices represent a subset of the detector (e.g., a
z=0 slice), spatial_dims should be set to the full detector dimensions.
RollingDetectorView.make_roi_filter() now passes detector_number.dims.

Prompt: We need to look into support dense data arrays instead of event-data
in RollingDetectorView and ROIFilter. Let us talk about the latter first.
Do you think the current approach can be tweaked slightly, or is it too
inefficient? Our dense data would be something like (time,x,y) where the
selection is in the (x,y), detector_number labelling pixels there.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-project-automation github-project-automation bot moved this to In progress in Development Board Nov 27, 2025
@SimonHeybrock SimonHeybrock moved this from In progress to Selected in Development Board Nov 27, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

*,
selection: sc.Variable,
norm: float = 1.0,
spatial_dims: tuple[str, ...] | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

Can 'spatial_dims' be confusing?
Say you have a 3d cube of pixels, and you do a 2d xy projection, but then the roi is supposed to show the profile along z. All 3 dims xyz are spatial.

In addition, in the docstring, you explain

For dense data like (time, x, y), pass ('x', 'y') to preserve time.

Is it then not easier for users to reverse the logic and call the argument dims_to_keep or dims_to_preserve?

Copy link
Member Author

Choose a reason for hiding this comment

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

We usually just pass spatial_dims=detector_number.dims so the reverse does not feel simpler. And to you first question: As the docstring you explains you in fact need to pass all the spatial dims, not just those left after a projection/slicing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean the docstring in ROIFilter:

        spatial_dims:
            Dimensions of the detector that should be flattened when applying the
            filter. If None, defaults to indices.dims. For projections where indices
            represent a subset of the detector, this should be set to the full
            detector dimensions.

Copy link
Member

@nvaytet nvaytet Nov 28, 2025

Choose a reason for hiding this comment

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

I didn't really get why reversing the logic is difficult, but I also don't really mind that much.
Do as you prefer, it was just a suggestion.

@SimonHeybrock SimonHeybrock merged commit 71f8524 into main Dec 1, 2025
4 checks passed
@SimonHeybrock SimonHeybrock deleted the dense-detector-view-roi branch December 1, 2025 02:35
@github-project-automation github-project-automation bot moved this from Selected to Done in Development Board Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants