-
Notifications
You must be signed in to change notification settings - Fork 240
Good times extension #4299
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
base: main
Are you sure you want to change the base?
Good times extension #4299
Conversation
|
Depends on #4302 |
for more information, see https://pre-commit.ci
|
@m-beau @samuelgarcia the parallelization makes it extremely fast. I slightly refactored the misc_metrics so I can directly call the low-level functions. Now computing good periods for a full 1 hour NP probe takes a minute or so :) The cool trick is that we can compute all fp/fn values for all chunks (a chunk is unit+segment+period) and filter it all at once with thresholds. This simplifies the logic a lot! Take a look, for me this is ready to review. I also tested the relative period mode and it works very well! @m-beau I changed some defaults and naming to something that I think is a bit less strict, but not too much |
| HAVE_NUMBA = False | ||
|
|
||
|
|
||
| class ComputeGoodPeriodsPerUnit(AnalyzerExtension): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pretty bad for english but my first react is "good" could be replace by "valid" for a clearer semantic no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my suggestion too! I like it better as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my suggestion too! I like it better as well :)
| fn_threshold=fn_threshold, | ||
| minimum_n_spikes=minimum_n_spikes, | ||
| minimum_valid_period_duration=minimum_valid_period_duration, | ||
| user_defined_periods=user_defined_periods, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alejoe91
This could lead to a big json file no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point! We still have to add tests for the external periods, but what we could do is set it as a self.user_defined_period and pop in from the dict in self params, so they are not set in the JSON but the run function can still use it.
| def _merge_extension_data( | ||
| self, merge_unit_groups, new_unit_ids, new_sorting_analyzer, censor_ms=None, verbose=False, **job_kwargs | ||
| ): | ||
| new_extension_data = self.data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess for this we should decide the rules of merging valid period.
intersection or union or period pre merging ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in the last commit
| new_extension_data = self.data | ||
| return new_extension_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here what do we want for period after a split ?
maybe remove period of this units no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. Probably we want to recompute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelgarcia can you take a look?
| subperiod["end_sample_index"] = end | ||
| subperiod["unit_index"] = unit_index | ||
| periods_for_unit[i] = subperiod | ||
| all_subperiods = np.concatenate((all_subperiods, periods_for_unit), axis=0) |
There was a problem hiding this 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 better to make a final concatenate at the end of the loop and magaing this with list.
This avoid too much memory allocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
This looks cool. Could we make a very simple matplotlib widgets for this new extension ? (in addtion to sigui f course) |
|
Yes, I'll add some TODO's to the PR description so we keep track of it. |
| # TODO: in case of periods, should we use total samples only in provided periods? | ||
| total_samples = sorting_analyzer.get_total_samples() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-beau @samuelgarcia @chrishalcrow this is a critical point. I refactor the computation so that we can pass the total samples externally. This is needed both when computing in chunks for the compute_good_periods function and also when we update the metrics to use the valid periods. In that case, we will need to count the valid samples for each units, so total_samples can be a dictionary now
| "amplitude_scalings", | ||
| ), "Invalid amplitude_extension. It can be either 'spike_amplitudes' or 'amplitude_scalings'" | ||
| sorting = sorting_analyzer.sorting | ||
| total_duration = sorting_analyzer.get_total_duration() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello - do we need to be careful about stuff like this? Here the total_duration of the entire recording. It's used later to compute a firing rate, and this firing rate is the total num spikes divided by total duration, rather than num-spike-in-periods/duration-of-periods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case is the num spikes in period. So I think this is correct, but I'll double check carefully!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case is the num spikes in period. So I think this is correct, but I'll double check carefully!
Implements #4294