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

Rename multiplier to frames_per_event and move to first dim of shape #726

Open
wants to merge 68 commits into
base: main
Choose a base branch
from

Conversation

thomashopkins32
Copy link
Contributor

@thomashopkins32 thomashopkins32 commented Jan 8, 2025

This PR does the following:

  • Renames multiplier -> frames_per_event
  • Add the frames_per_event as the first dimension of DataKey.shape
  • Ensure that the index provided by DetectorWriter.get_indices_written() and DetectorWriter.observe_indices_written() is divided by frames_per_event so that it actually captures the correct amount of exposures in each index (except for PandA which explicitly says it only has 1 "frame" per event)
  • Add unit tests showing that describe() works as intended
  • Add unit tests showing that stream resources are actually batches of exposures
  • Re-order self._writer.open() and self._writer.get_indices_written(). The writer needs to be opened in order to get the indices written. Otherwise, it has no idea what frames_per_event to use when returning the index last written.

I could not actually add tests using bluesky plans and inspecting the data afterword because TriggerInfo is hardcoded in StandardDetector. I think it is a separate issue that should be raised since it would enhance the scope of this PR. I will open an issue for this soon and mention it below.

Otherwise, I have a few open questions regarding my understanding of ophyd-async as well as the implementation which I will also leave as review comments. Please see below.

Closes #576

jwlodek and others added 30 commits September 4, 2024 13:16
Copy link
Contributor Author

@thomashopkins32 thomashopkins32 left a comment

Choose a reason for hiding this comment

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

Question about shapes when frames_per_event is 1: do we want to always "squeeze" the shape?
I.e. there are a couple of options:

  • For 2d arrays:
    • [1, h, w] -> [h, w] when frames_per_event = 1
    • [frames_per_event, h, w] when frames_per_event > 1
  • For scalar values:
    • [1,] -> [] when frames_per_event = 1
    • [frames_per_event,] when frames_per_event > 1

Currently, it is set up such that if the result would be a single scalar value, the shape would be replaced with []. Otherwise, the shape always contains the extra dim.

src/ophyd_async/epics/adcore/_core_writer.py Outdated Show resolved Hide resolved
src/ophyd_async/epics/adcore/_core_writer.py Outdated Show resolved Hide resolved
src/ophyd_async/epics/adcore/_core_writer.py Outdated Show resolved Hide resolved
Copy link
Member

@jwlodek jwlodek left a comment

Choose a reason for hiding this comment

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

I think this is close, just a few minor notes. We should try setting this up in the lab and running a test w/ collecting data from different devices w/ different frames_per_event to make sure it behaves as expected (and also to maybe work out the needed changes to the consolidators).

@@ -21,7 +21,7 @@
Triggerable,
WritesStreamAssets,
)
from event_model import DataKey
from event_model import DataKey # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the # type: ignore here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get the following mypy issue. It looks like event-model does not have a py.typed marker.

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does pyright also complain? If it needs a py.typed then please could you make an event-model PR to add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pyright does not seem to complain, event-model is missing a py.typed marker so I can add it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/ophyd_async/core/_hdf_dataset.py Outdated Show resolved Hide resolved
src/ophyd_async/epics/adcore/_core_writer.py Outdated Show resolved Hide resolved
src/ophyd_async/epics/adcore/_core_writer.py Outdated Show resolved Hide resolved
tests/core/test_flyer.py Outdated Show resolved Hide resolved
src/ophyd_async/epics/adcore/_core_writer.py Outdated Show resolved Hide resolved
tests/epics/adaravis/test_aravis.py Outdated Show resolved Hide resolved
@jwlodek
Copy link
Member

jwlodek commented Jan 13, 2025

Question about shapes when frames_per_event is 1: do we want to always "squeeze" the shape? I.e. there are a couple of options:

* For 2d arrays:
  
  * `[1, h, w]` -> `[h, w]` when `frames_per_event = 1`
  * `[frames_per_event, h, w]` when `frames_per_event > 1`

* For scalar values:
  
  * `[1,]` -> `[]` when `frames_per_event = 1`
  * `[frames_per_event,]` when `frames_per_event > 1`

Currently, it is set up such that if the result would be a single scalar value, the shape would be replaced with []. Otherwise, the shape always contains the extra dim.

I think I'd be in favor of avoiding such squeezing, because then we'd need a separate parameter to let us know if it had been squeezed or not. Say we have a frames_per_event of 1 w/ a dataset that's 10 x 10. If we squeeze we get [10, 10] as the shape, but there's no way of telling if this is actually a 1D dataset of size 10 w/ 10 frames per event.

@thomashopkins32
Copy link
Contributor Author

@jwlodek so the current squeezing behavior for the shape is

  • For 2d arrays:
    • [frames_per_event, h, w] (even if frames_per_event is 1)
  • For scalar values:
    • [1,] -> [] when frames_per_event = 1
    • [frames_per_event,] when frames_per_event > 1

The final change I would make based on your comment would be to remove the squeezing on scalar values from [1,] -> [].

@thomashopkins32
Copy link
Contributor Author

Should be ready to review once more. The new shape behavior is such that the frames_per_event is always the first dimension of shape. If the len(shape) > 1, then the dtype is an array, otherwise, its a number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove multiplier from resource docs, add it instead as an extra first dimension in descriptor shape
3 participants