-
Notifications
You must be signed in to change notification settings - Fork 0
fix: handle binned data in max res finder #274
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -25,7 +25,6 @@ def test_finds_maximum_resolution(): | |||
| events, | ||||
| sc.linspace('x', 0, 1, 2), | ||||
| sc.linspace('x', 0, 1, 2), | ||||
| sc.linspace('t', 0, 2, 2), | ||||
| ) | ||||
| assert len(x_be) == 11 | ||||
| assert len(y_be) == 11 | ||||
|
|
@@ -51,7 +50,6 @@ def test_finds_maximum_resolution_random(seed): | |||
| events, | ||||
| sc.linspace('x', 0, 1, 2), | ||||
| sc.linspace('y', 0, 1, 2), | ||||
| sc.linspace('t', 0, 2, 2), | ||||
| # Need enough tries to be sure we find the optimum | ||||
| max_tries=100, | ||||
| ) | ||||
|
|
@@ -70,3 +68,42 @@ def test_finds_maximum_resolution_random(seed): | |||
| .value | ||||
| == 0 | ||||
| ) | ||||
|
|
||||
|
|
||||
| def test_finds_maximum_resolution_binned_input(): | ||||
| np.random.seed(0) | ||||
| n = np.random.randint(1000, 100_000) | ||||
| events = sc.DataArray( | ||||
| sc.ones(dims=['events'], shape=(n,)), | ||||
| coords={ | ||||
| 'x': sc.array(dims=['events'], values=np.random.random(n)), | ||||
| 'y': sc.array(dims=['events'], values=np.random.random(n)), | ||||
| 't': sc.array(dims=['events'], values=np.random.random(n)), | ||||
| }, | ||||
| ) | ||||
| events = events.bin(x=100, y=100, t=500) | ||||
| del events.bins.coords['x'] | ||||
| del events.bins.coords['y'] | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it because they are usually dropped by reduction workflows?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's to make it look like typical detector event data in our workflows. Typically we don't have pixel positions on the event data. |
||||
| x_be, y_be = maximum_resolution_achievable( | ||||
| events, | ||||
| sc.linspace('x', 0, 1, 2), | ||||
| sc.linspace('y', 0, 1, 2), | ||||
| # Need enough tries to be sure we find the optimum | ||||
| max_tries=100, | ||||
| ) | ||||
|
|
||||
| events.bins.coords['x'] = sc.bins_like(events, sc.midpoints(events.coords['x'])) | ||||
| events.bins.coords['y'] = sc.bins_like(events, sc.midpoints(events.coords['y'])) | ||||
| events = events.bins.concat(['x', 'y']) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Here too. I think putting the event coordinate should be enough.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue here, if we bin again in |
||||
|
|
||||
| assert events.bin(x=x_be, y=y_be).bins.size().min().value > 0 | ||||
| assert ( | ||||
| events.bin( | ||||
| x=sc.linspace('x', 0, 1, len(x_be) + 1), | ||||
| y=sc.linspace('y', 0, 1, len(y_be) + 1), | ||||
| ) | ||||
| .bins.size() | ||||
| .min() | ||||
| .value | ||||
| == 0 | ||||
| ) | ||||
Uh oh!
There was an error while loading. Please reload this page.
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.
Why do we have to concatenate it? Is it faster if we do?
Uh oh!
There was an error while loading. Please reload this page.
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.
The problem is that if we don't concatenate the bins then when we bin it again with new bin-edges in x and y we might run out of memory because of scipp/scipp#3872.
Does that answer the question?
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.
Yes it does...!
So it'll be not necessary if the bug is fixed right...?
Neverthless, I'm okay with it. It shoudn't be blocked by the bug fix...
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.
Yes if the bug is fixed we should be fine without it.