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

Add ROIFilter #173

Merged
merged 18 commits into from
Feb 7, 2025
Merged

Add ROIFilter #173

merged 18 commits into from
Feb 7, 2025

Conversation

SimonHeybrock
Copy link
Member

This will be used by Beamlime to make time-of-arrival histograms of counts within an ROI. Currently this only supports axis-aligned rectangle selections.

counts = data.bins.size().to(dtype='int32', copy=False)
counts.unit = 'counts'
self._add_counts(counts)

def add_counts(self, data: Sequence[int]) -> None:
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 will not be used by Beamlime anymore, keeping it for backwards compatibility.

size = _noise_size
position = sc.empty(sizes={'position': size}, unit='m', dtype=sc.DType.vector3)
position.values = np.random.default_rng().normal(0, sigma.value, size=(size, 3))
position.values = np.random.default_rng(seed=1234).normal(
Copy link
Member

Choose a reason for hiding this comment

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

Is this to turn the centers of the pixel positions into small gaussian clouds of points?
I was thinking maybe it should be random.uniform instead to avoid spill-over from one pixel over to the next?

But maybe using a normal distribution is better as it makes the clouds spherical, and they then look the same from any line-of-sight? Using uniform also suggests that the pixels are square in shape, but this is not really true for tubes...

Is the sigma approximately equal to half the width of the pixel?

Copy link
Member Author

@SimonHeybrock SimonHeybrock Feb 7, 2025

Choose a reason for hiding this comment

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

The gaussian option is just a simple alternative to something that uses the pixel shape, see the cylinder case (used for Loki tubes) which is uniform within the pixel. We may eventually have something similar for other shapes, I think.

Sigma is a parameter than can be set in a config file in Beamlime.

indices will be returned concatenated into a dense array.
"""
out_dim = 'index'
for dim, (low, high) in intervals.items():
Copy link
Member

Choose a reason for hiding this comment

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

At some point, we may be hooking this up to a graphical interface where a user will draw a rectangle by hand.
In some plotting libraries (e.g. MPL), when you request the bounds of a rectangle, the order of the bounds depends on how the user drew the rectangle.

If they started from the left and dragged towards the right, you get [left, right] as the bounds.
They they started from the right, you get [right, left] instead.
The same goes fro top/bottom.

We could end up in a situation where some of the tuples contain 2 values but the second one is lower than the first. The slicing below would then select nothing.

I recommend we add something like low, high = sorted(low, high) to make sure that does not happen further down the line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, done, please have another look.

@SimonHeybrock SimonHeybrock merged commit 23df4f6 into main Feb 7, 2025
4 checks passed
@SimonHeybrock SimonHeybrock deleted the roi branch February 7, 2025 12:07
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.

2 participants