Skip to content

Expose hidden KiloSort1 parameters and descriptions #3956

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

kushaangupta
Copy link
Contributor

Closes #3943

@kushaangupta kushaangupta changed the title Expose hidden Kilosort parameters and descriptions Expose hidden KiloSort1 parameters and descriptions May 27, 2025
ops["fshigh"] = params["freq_min"] # frequency for high pass filtering
ops["fslow"] = params["freq_max"] # frequency for low pass filtering (optional)
ops["ntbuff"] = params["ntbuff"] # samples of symmetrical buffer for whitening and spike detection
ops["scaleproc"] = 200.0 # int16 scaling of whitened data
ops["scaleproc"] = params["scaleproc"] # int16 scaling of whitened data
Copy link
Member

Choose a reason for hiding this comment

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

My only concern is that there are a few parameters that are always fixed (I guess someone could fork KS1 and change it themselves), but I think they always do the scaling at 200 for their own thing. So I will wait for @alejoe91 to comment on this since I started using KS at KS2 so maybe he knows better if we shouldn't expose certain parameters. Unless you really want to expose everything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah maybe not everything, some parameters apparently aren't meant to be changed. I can remove those. It's hard for me to distinguish the internal parameters from the internally configurable ones. But some parameters that were earlier hardcoded like max/minFR, Th, lam etc were useful to be configured definitely

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 I think the ones you listed are fair to change. But I agree the documentation for the truly "internal" vs the configurable is not super clear. Let's wait for Alessio to comment as well and then we can come up with a strategy :)

Copy link
Member

Choose a reason for hiding this comment

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

Hi guys! Yeah this looks good to me! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zm711 let me know if u need anything else for the merge

Copy link
Member

Choose a reason for hiding this comment

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

I think this is in principle good to go. I just need to take a moment to carefully read through to make sure no parameters got missed. I'm away from computer tomorrow so I'll try to read it over Friday or Saturday to confirm that I don't see anything that didn't get transferred over.

@zm711 zm711 added the sorters Related to sorters module label May 27, 2025
Copy link
Member

@zm711 zm711 left a comment

Choose a reason for hiding this comment

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

Just a few comments @kushaangupta

ops["nSkipCov"] = params["nSkipCov"] # compute whitening matrix from every N-th batch (1)
ops["whiteningRange"] = params[
"whiteningRange"
] # how many channels to whiten together (Inf for whole probe whitening, should be fine if Nchan<=32)
Copy link
Member

Choose a reason for hiding this comment

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

Based on this comment it seems like if we are allowing the user to set their own number then we should either prevent them from using > 32 or warn them. But we do say inf is possible.

Do you know if we should be doing some sort of check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if I fully understand. Isn't it saying that it can be infinity if Nchan <=32?

Copy link
Member

Choose a reason for hiding this comment

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

The issue is that users should use Nchan <=32, but alternatively they could whitened based on a whole probe by doing infinite, but this is not recommended. So the question would be do we

  1. assert <=32 to ensure that people use the more appropriate local whitening rather than allowing global whitening
  2. keep what you've done and let people do whatever they want, but default to 32
  3. let people do what they want, but warn if > 32

I'm note completely sure what the right answer is. I'm leaning toward 3, but if you have strong opinions I would love to hear arguments for 1 or 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated it for 3

Copy link
Member

Choose a reason for hiding this comment

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

Close. So what I would do instead is:

if params["whiteningRange"] > 32:
    n_channels_whitening = params["whiteningRange"] if np.isfinite(params["whiteningRange"]) else "all"
    warn(f"Kilosort recommends whitening with 32 or fewer channels you are whitening with {n_channels_whitening} channels"
ops["whiteningRange"] = params['whiteningRange"]

But in this case at the top of the file you would need to add

from warnings import warn

Want to give that a go instead? If not I can push this change myself.

Copy link
Member

Choose a reason for hiding this comment

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

Now that testing is working again did you want to give a go editing to something like what I did above? Or would you like me to just push it myself?

Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com>
@zm711
Copy link
Member

zm711 commented Jun 2, 2025

Tests aren't working right now. Seems like pytest released a new version today. We are in the process of fixing the testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sorters Related to sorters module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kilosort 1 customize parameters
3 participants