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

artifact detection indexerror on last timestamp #1206

Open
MichaelCoulter opened this issue Jan 4, 2025 · 3 comments
Open

artifact detection indexerror on last timestamp #1206

MichaelCoulter opened this issue Jan 4, 2025 · 3 comments

Comments

@MichaelCoulter
Copy link
Collaborator

i think this index error is caused because the detected artifact includes the last timestamp of the recording. can we make a work-around for this case? thanks.

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In [182], line 36
     34 print('rs12 8-13, num keys',len(key_list))
     35 for i in np.arange(len(key_list)):
---> 36     sgs.ArtifactDetection.populate(key_list[i])
     38 key = {'nwb_file_name': 'RS1220240814_.nwb'}
     39 key_list = (sgs.ArtifactDetectionSelection() << key).fetch('KEY')

File ~/spyglass/src/spyglass/utils/dj_mixin.py:589, in SpyglassMixin.populate(self, *restrictions, **kwargs)
    587 if use_transact:  # Pass single-process populate to super
    588     kwargs["processes"] = processes
--> 589     return super().populate(*restrictions, **kwargs)
    590 else:  # No transaction protection, use bare make
    591     for key in keys:

File ~/anaconda3/envs/spyglass2/lib/python3.9/site-packages/datajoint/autopopulate.py:248, in AutoPopulate.populate(self, suppress_errors, return_exception_objects, reserve_jobs, order, limit, max_calls, display_progress, processes, make_kwargs, *restrictions)
    242 if processes == 1:
    243     for key in (
    244         tqdm(keys, desc=self.__class__.__name__)
    245         if display_progress
    246         else keys
    247     ):
--> 248         status = self._populate1(key, jobs, **populate_kwargs)
    249         if status is True:
    250             success_list.append(1)

File ~/anaconda3/envs/spyglass2/lib/python3.9/site-packages/datajoint/autopopulate.py:315, in AutoPopulate._populate1(self, key, jobs, suppress_errors, return_exception_objects, make_kwargs)
    313 self.__class__._allow_insert = True
    314 try:
--> 315     make(dict(key), **(make_kwargs or {}))
    316 except (KeyboardInterrupt, SystemExit, Exception) as error:
    317     try:

File ~/spyglass/src/spyglass/spikesorting/v1/artifact.py:161, in ArtifactDetection.make(self, key)
    156 recording = se.read_nwb_recording(
    157     recording_analysis_nwb_file_abs_path, load_time_vector=True
    158 )
    160 # - detect artifacts
--> 161 artifact_removed_valid_times, _ = _get_artifact_times(
    162     recording,
    163     sort_interval_valid_times,
    164     **artifact_params,
    165 )
    167 # INSERT
    168 # - into IntervalList
    169 IntervalList.insert1(
    170     dict(
    171         nwb_file_name=(
   (...)
    179     skip_duplicates=True,
    180 )

File ~/spyglass/src/spyglass/spikesorting/v1/artifact.py:316, in _get_artifact_times(recording, sort_interval_valid_times, zscore_thresh, amplitude_thresh_uV, proportion_above_thresh, removal_window_ms, verbose, **job_kwargs)
    303 for interval_idx, interval in enumerate(artifact_intervals):
    304     interv_ind = [
    305         np.searchsorted(
    306             valid_timestamps,
   (...)
    312         ),
    313     ]
    314     artifact_intervals_s[interval_idx] = [
    315         valid_timestamps[interv_ind[0]],
--> 316         valid_timestamps[interv_ind[1]],
    317     ]
    319 # make the artifact intervals disjoint
    320 if len(artifact_intervals_s) > 1:

IndexError: index 36491204 is out of bounds for axis 0 with size 36491204
@CBroz1
Copy link
Member

CBroz1 commented Jan 6, 2025

Hi @MichaelCoulter - Thanks for reporting. Would you provide a snippet that defines your key/triggers the error?

@MichaelCoulter
Copy link
Collaborator Author

ill look for one.

@samuelbray32
Copy link
Collaborator

Related to #1196 ?

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

No branches or pull requests

3 participants