Skip to content

bug in remove_artifacts.py, can't handle sparsity #3290

Open
@maxjuv

Description

@maxjuv

Hello,
I was using the remove_artifacts function in "median" mode, and I was playing with the parameter "sparsity". I got an error because the sparsity was not applied on the artifact template. Indeed line 185-187 , the sparsity is not taken into account. I fixed it locally with the following code. If the solution is fine for you, I can create a pull request.

artifacts = {}
for i, label in enumerate(sorting.unit_ids):
    if sparsity is not None :
        artifacts[label] = templates[i, :, :][:,sparsity[label]]
    else :
        artifacts[label] = templates[i, :, :]

Detailed error :
I made sparsity masks conserving only 1 channel. My recording is composed of 192 channels. I got the following error :

 np.dot(trace_slice_values.flatten(), artifact_slice_values.flatten()) / norm
  File "<__array_function__ internals>", line 200, in dot
ValueError: shapes (18,) and (3456,) not aligned: 18 (dim 0) != 3456 (dim 0)

It happened that 3456 is exactly 192*18. So I tracked the shape of "artifact_slice_values", and I observed that sparsity mask was not applied on the template of the artifacts.
Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpreprocessingRelated to preprocessing module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions