Skip to content

Adds our own CoM callback #106

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

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

Adds our own CoM callback #106

wants to merge 9 commits into from

Conversation

jackbdoughty
Copy link
Contributor

@jackbdoughty jackbdoughty commented Feb 10, 2025

We could not use Bluesky's centre of mass callback as it was not suited for the way we would want to use it, so this is our implementation for one.

To test:

  • Make sure that all tests pass.
  • Run the following scans and check that you get sensible CoMs for each. (Send me a message if you need to know how to set up to scan blocks against eachother / create fake data):
    • A scan with non constant point spacing.
    • A scan where some of the values are negative / have a background.
    • The "there-and-back" scan so x points would be like: -2 -1 0 1 2 1 0 -1 -2. (Non continuous points)

@jackbdoughty jackbdoughty mentioned this pull request Feb 10, 2025
1 task


@make_class_safe(logger=logger) # pyright: ignore (pyright doesn't understand this decorator)
class PeakStats(_DefaultPeakStats):
Copy link
Contributor

Choose a reason for hiding this comment

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

we should use this in our standard callbacks class - if this ticket is merged before #104 i will add it in, if not i think this PR should

@jackbdoughty
Copy link
Contributor Author

#108 Will fix the above errors

Copy link
Contributor

@Tom-Willemsen Tom-Willemsen left a comment

Choose a reason for hiding this comment

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

I'm going to push some stuff to a trapeze branch and we should probably chat tomorrow... I found some extra-fun edge cases that I hadn't previously considered...

e.g. this case:

def test_tricky_non_constant_spacing():
    ps.start({})

    ps.event({"data": {"x": 0, "y": 1}})
    ps.event({"data": {"x": 0.1, "y": 1}})
    ps.event({"data": {"x": 4, "y": 1}})
    ps.event({"data": {"x": 5, "y": 0}})
    ps.event({"data": {"x": 6, "y": 1}})
    ps.event({"data": {"x": 10, "y": 1}})

    ps.stop({})

    assert ps["com"] == 5.0



@make_class_safe(logger=logger) # pyright: ignore (pyright doesn't understand this decorator)
class PeakStats(_DefaultPeakStats):
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I know I've gone back and forth on this, but I'm not fully convinced it's a good idea to subclass _DefaultPeakStats here actually - the upstream one has __slots__ defined and some other potential traps.

Maybe here it is better to just make a standalone callback... subclassing CollectThenCompute or similar.

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

Successfully merging this pull request may close these issues.

3 participants