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

[BUG] burst_def bug #334

Closed
wants to merge 2 commits into from
Closed

[BUG] burst_def bug #334

wants to merge 2 commits into from

Conversation

ryanhammonds
Copy link
Member

The docstring of sim_bursty_oscillation says a 1d array can be passed to the burst_def kwarg. Passing a 1d array leads to an error here, since burst_def=='prob' returns an array:

if burst_def == 'prob' and burst_param not in burst_params:

This PR restructures the function with appropriate conditionals to fix. If 1d arrays aren't meant to be supported, then we'd just need to update the docstring.

@TomDonoghue
Copy link
Member

Hey @ryanhammonds I merged this to main to get the tests running, and the tests are failing.

Based on looking through what's failing is things like this:

sig = sim_bursty_oscillation(n_seconds=10, fs=500, freq=5, enter_burst= 0.2, leave_burst=0.8)

There's a bit of sloppiness here (I think this comes from the old API) since the 'enter_burst' and 'leave_burst' parameters should arguably be packaged into a 'burst_params' input dict (which would work), but this is done in places here as here, and if we don't want to make any breaking changes, we probably want to maintain this.

The test case we need to work is something like this, right (this should have been in the tests really):

burst_def = np.array([True, False, True, False, True, False, True, False, True, False])
sim_bursty_oscillation(1, 100, 10, burst_def=burst_def)

The failure point, as you found, is: if burst_def == 'prob' and burst_param not in burst_params:, from
here, which fails at type checking burst_def in the case it's an array (this used to work, but type checking against arrays has become stricter).

As an alternative fix here, I think we can just update this type check to the following:
if isinstance(burst_def, str) and burst_def == 'prob' and burst_param not in burst_params:

Does that make sense? I'm pretty sure that addresses the issue here, and in not moving around any ordering, preserves all previous functionality.

If this make sense to you, I think we can replace this PR by updates that:

  • update this type-checking line to the version above that tests for being a string
  • add an explicit test of burst_def as an array input (for example, from above)
  • sweep through and update examples that pass burst_params in the old style, so we model this approach better

Does this make sense / sound good to you? If so, I can PR this

@ryanhammonds
Copy link
Member Author

ryanhammonds commented Feb 10, 2025

@TomDonoghue That sounds good to me. Your proposed fix looks clean / backward compatible. Thanks for look into this!

@TomDonoghue
Copy link
Member

@ryanhammonds - okay sounds good - I added these changes in #349 - if that looks good, we can merge there, and close this! Thanks for finding / figuring out this bug!

@TomDonoghue
Copy link
Member

Updates done in #349

@TomDonoghue TomDonoghue deleted the burst_def branch February 11, 2025 04:02
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.

2 participants