Skip to content

Conversation

@alejoe91
Copy link
Member

@alejoe91 alejoe91 commented Jan 7, 2026

Depends on #4316

Slices a sorting object based on an array ov valid periods. Periods are defined as a structured dtype as:

base_period_dtype = [
    ("start_sample_index", "int64"),
    ("end_sample_index", "int64"),
    ("segment_index", "int64"),
    ("unit_index", "int64"),
]

EDIT:

Refactored computation of spike train metrics, to make sure that periods are consistently taken into account. Added 2 utils functions to compute durations per unit and bin edges per unit, that optionally use the provided periods

@alejoe91 alejoe91 added the core Changes to core module label Jan 7, 2026
@alejoe91 alejoe91 mentioned this pull request Jan 7, 2026
1 task
@alejoe91 alejoe91 marked this pull request as ready for review January 8, 2026 07:36
@alejoe91 alejoe91 requested a review from chrishalcrow January 8, 2026 07:36
self._segment_slices = None

@property
def segment_slices(self):
Copy link
Member

Choose a reason for hiding this comment

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

I want to have this in NumpySorting since long time. We could move it there no ?

And also you can do a np.searchsorted for segment at once. without any loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would make it in base sorting then, since it applies to all sorting objects (after to_spike_vector). No?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would make it in base sorting then, since it applies to all sorting objects (after to_spike_vector). No?

@samuelgarcia
Copy link
Member

This is OK for me.
Make a clear documentation somwhere woule help ?

rng = np.random.default_rng()

# number of random periods
n_periods = 10_000
Copy link
Member

Choose a reason for hiding this comment

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

duration, num_units and n_periods are all quite large for a test. Is it slow??

Copy link
Member

Choose a reason for hiding this comment

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

I agree we should put a small number

Copy link
Member Author

Choose a reason for hiding this comment

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

takes about 1 second

("unit_index", "int64"),
]

base_period_dtype = [
Copy link
Member Author

Choose a reason for hiding this comment

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

move all dtypes to base

Copy link
Member Author

Choose a reason for hiding this comment

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

done in #4314

@alejoe91
Copy link
Member Author

@chrishalcrow I refactored a few metrics to make sure durations, spike counts, and bins are properly accounted for when slicing with periods. Happy to discuss about this!

@alejoe91 alejoe91 changed the title Implement select_sorting_periods Implement select_sorting_periods in metrics Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants