Skip to content

interpolate_motion needs motion object calculated by compute_motion / dtype - #4971

Open
pas-calc wants to merge 4 commits into
SpikeInterface:mainfrom
pas-calc:patch-2
Open

pas-calc wants to merge 4 commits into
SpikeInterface:mainfrom
pas-calc:patch-2

Conversation

@pas-calc

@pas-calc pas-calc commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

additionally, integer dtype (as typical recording) is not automatically transformed to float, see

raise ValueError(f"Can't interpolate traces of recording with non-floating dtype={recording.dtype=}.")

we could use

elif recording.dtype.kind == "i":
    dtype="float32"

@JoeZiminski

Copy link
Copy Markdown
Contributor

Thanks @pas-calc good catch on the docstring. For the conversion it makes sense to me, though it will lead to a potentially subtle change in recording dtype:

recording = si.load(path)  # int16
...
recording = interpolate_motion(motion, recording)  # now float

but I think that's okay, its basically the same for compute_motion which returns the corrected recording in f32.

Previously we were moving to automating this anyway see here, here and PR here .

I would guess the original intention was to make the user aware the dtype of the recording had changed, but the errors became very annoying. Maybe we should give a warning?

If we proceed I think we could drop the auto-convert from correct_motion as it will be directly handled in interpolate_motion, I would vote to add a warning there too.

@JoeZiminski

JoeZiminski commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Actually maybe use != "f" like correct_motion to handle unsigned int similarly

@alejoe91

alejoe91 commented Dec 1, 2026

Copy link
Copy Markdown
Member

Thanks @pas-calc good catch on the docstring. For the conversion it makes sense to me, though it will lead to a potentially subtle change in recording dtype:

recording = si.load(path)  # int16
...
recording = interpolate_motion(motion, recording)  # now float

but I think that's okay, its basically the same for compute_motion which returns the corrected recording in f32.

Previously we were moving to automating this anyway see here, here and PR here .

I would guess the original intention was to make the user aware the dtype of the recording had changed, but the errors became very annoying. Maybe we should give a warning?

If we proceed I think we could drop the auto-convert from correct_motion as it will be directly handled in interpolate_motion, I would vote to add a warning there too.

@JoeZiminski I agree we should move the correct_motion logic here, so it will apply to both functions. @pas-calc could you do that?

Removed dtype parameter from the function signature and adjusted dtype handling for non-floating recordings.
@pas-calc

pas-calc commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

a simple change, see commit e9204e8
one could implement this across different functions, like for whiten which also requires float, maybe other functions like bandpass filter would also profit from first converting the recording to float before applying the function

@alejoe91 alejoe91 added the preprocessing Related to preprocessing module label Dec 1, 2026
@alejoe91

alejoe91 commented Dec 1, 2026

Copy link
Copy Markdown
Member

@pas-calc can you check and fix failures in tests? There is an undefinded dtype

dtype will be read from recording
@alejoe91

alejoe91 commented Dec 3, 2026

Copy link
Copy Markdown
Member

Thanks @pas-calc, another error came up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preprocessing Related to preprocessing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants