Skip to content

[ESSREDUCE] fix: add binned timestamp coords to monitor - #883

Open
jokasimr wants to merge 4 commits into
mainfrom
fix-750
Open

jokasimr wants to merge 4 commits into
mainfrom
fix-750

Conversation

@jokasimr

Copy link
Copy Markdown
Contributor

Fixes #750

@jokasimr
jokasimr requested a review from nvaytet November 17, 2026 12:09
@github-actions github-actions Bot added the essreduce Issues for essreduce. label Nov 17, 2026
@github-actions github-actions Bot changed the title fix: add binned timestamp coords to monitor [ESSREDUCE] fix: add binned timestamp coords to monitor Nov 17, 2026
pulse_index=inputs["pulse_index"],
pulse_period=inputs["pulse_period"],
)
del inputs

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.

Instead of manual memory management, can you extract inputs = ...; wavs = ... into a separate function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is that really easier? That del is just a small optimization

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.

It's more about clarity. Local variables with a small scope are usually easier to understand than large scopes with variables appearing and disappearing. Plus, there seem to be multiple distinct operations in this function if you can discard part of the data early.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've split it into separate functions now.

.bins.constituents["data"]
.to(unit=etz_unit, copy=False)
)
da.coords["event_time_zero"]

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 thought the suggested fix in the related issue was about copying the event_time_zero on every event; something that is done when loading the detector events but not the monitor events?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you're right about that. We can do it like that, but it would increase memory usage unnecessarily in cases that don't need event_time_zero (no wavelength computation, no pulse stride etc).

@nvaytet nvaytet Nov 19, 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 guess your thinking was that the monitor does not have logical dimensions so we can just keep it binned in event_time_zero.
And that is true that we save some memory this way.

However, I think it would make things easier to use if the data from detectors and monitors looked the same? Users wouldn't have to think too hard about whether it's detector or monitor data, and do different operations accordingly.

It would also be easier to write generic code (just like the changes in this PR would not have been needed).

That said, many monitors will record in histogram mode and will look different anyway. So maybe it does not matter too much? But for instruments who plan to often switch between event and histogram mode, it might be nice with only 2 forms of data to deal with instead of 3?

Finally, I think there are one or two monitors that do have more than one pixel?

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'd be very careful about doing this for every monitor. Event monitors can get massive, so compute/memory impact can be substantial. I thought doing it conditionally only of there is a pulse stride > 1 was a good approach.

Monitors with pixels: Yes, at Loki for example, but iirc that is to judge beam profile and would not need to be handled per pixel in a reduction workflow. But I am probably wrong.

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 thought doing it conditionally only of there is a pulse stride > 1 was a good approach.

So you wanted to go with the current implementation or copy the event_time_zero on the events if pulse stride > 1?
I don't mind ether way, was just curious.

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.

You mean event_time_zero vs pulse_index? Note sure, my point was about doing it only when actually needed.

But maybe what you say is right after all: We might not needed event_time_zero now, but we might as soon as we need to implement more filtering etc.?

@nvaytet nvaytet Nov 19, 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 didn't think immediately about event filtering... but I guess you are right.
When you are filtering based on time, you often need to filter events based on where they were along the beam path at a given time.
This implies that it would be wavelength-dependent, and you then most probably need a time per event?
Or can you still do that without putting a time zero on every event?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we later decide to add event_time_zero to monitor events, possibly conditional on it being required by the workflow, that will also work. This PR just makes sure it works also in case you didn't add event_time_zero to the events. I think that is reasonable.

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

essreduce Issues for essreduce.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

essreduce: event monitors cannot be converted to wavelength when pulse skipping

4 participants