-
Notifications
You must be signed in to change notification settings - Fork 195
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
Unexpected: AssertionError: 'inter_sample_shift' is not a property! #3628
Comments
Hey Brian, quick additional questions to help us: version of spikeinterface |
Ah, apologies for not including in the first message. import spikeinterface as s showed 0.101.2 import kilosort as k showed 4.0.22 Thanks! |
Thanks Brian. One quick thing. We recently discovered that we don't officially support Kilosort 4.0.2x yet (they update so fast that we need to double check our wrapper). I don't think that should be the problem here though. Do you have more of the error trace (it should be in the json file). It might be that we are not propagating a property appropriately, but more trace would be better to help find where this is happening. |
Hi Zach, Interestingly, I ran the same code I posted above, but under the section I named
the run_sorter_local runs successfully afterwards. But, regardless of what I do, oddly the following assert
passes right before running run_sorter_local in which it errors. { |
Hi guys, The problem is that by default properties in memory are not dumped to JSON. This results in the fact that when the run sorter reloads the recording, |
Hello! I just wanted to say that I saw there was a pull request initiated and that I'd be happy to help if possible! On this, I'm also currently using Thanks! |
Hello!
Thank you for producing and maintaining such a fabulous piece of software!
Briefly, when I run Kilosort4 via
runsorter.run_sorter_local
, it complains thatAssertionError: 'inter_sample_shift' is not a property!
even though, on the line immediately preceding this run_sorter command, the following passes:
assert 'inter_sample_shift' in rec.get_property_keys()
.I created a minimal example below to reproduce this behavior. The last section contains the error, and everything above is setup. For context, I originally encountered this assert error while preprocessing and motion correcting using spikeinterface, then passing this processed recording to Kilosort4 while skipping preprocessing and motion correction. In the example below, I run Kilosort4 on unprocessed data (which works) just to demonstrate the unexpected behavior.
Thanks for any advice!!
`
Load config file
config_file = '/mnt/lab/users/barnold/spike_sorting/package/spike_sort_config.yaml'
with open(config_file, 'r') as f:
config = yaml.safe_load(f)
Configure probe, specifying geometry of channels and other kwargs
positions = []
for i in range(config['probe']['n_row']):
# add channels by row, 2 channels per row
positions.append([0, i * config['probe']['pitch_row']])
positions.append([config['probe']['pitch_col'], i * config['probe']['pitch_row']])
positions = np.array(positions)
probe = Probe(ndim=config['probe']['n_dim'], si_units=config['probe']['units'])
probe.set_contacts(positions=positions,
shapes=config['probe']['shape'],
shape_params={'width': config['probe']['chan_width']})
probe.set_device_channel_indices(np.arange(config['probe']['n_chan']-1))
probe_kwargs = {'sampling_frequency': 30000.0561519867,
'num_channels': 385,
'dtype': 'int16',
'gain_to_uV': 2.3438,
'offset_to_uV': 0}
Load NP recording, assign probe
NP_file = '/mnt/mscratch1/Tarzan/2024-12-12_12-42-50/2024-12-12_12-43-01/NPElectrophysiology_2_2.bin'
rec = extractors.read_binary(file_paths = NP_file, **probe_kwargs)
rec = rec.select_channels([i for i in range(config['probe']['n_chan']-1)])
rec = rec.set_probe(probe)
set sample_shifts
sample_shifts = extractors.neuropixels_utils.get_neuropixels_sample_shifts(num_channels=rec.get_num_channels(), num_channels_per_adc=12)
rec.set_property('inter_sample_shift', sample_shifts)
take a small sample for testing
start_time_secs, duration_secs = 0,10
rec = rec.frame_slice(start_frame=int(start_time_secs * rec.sampling_frequency), end_frame=int((start_time_secs + duration_secs) * rec.sampling_frequency))
Unexpected AssertionError
this works like a charm
sorting = runsorter.run_sorter_local(sorter_name="kilosort4",
recording=rec,
folder=config['out_dir'],
**config['kilosort'])
do standard preprocessing using spikeinterface's preprocessing module
rec = preprocessing.bandpass_filter(recording=rec,
freq_min=config['ap_freqband']['lower'],
freq_max=config['ap_freqband']['upper'])
bad_channel_ids, channel_labels = preprocessing.detect_bad_channels(rec) # for this step, recording assumed to be filtered
rec = rec.remove_channels(remove_channel_ids=bad_channel_ids)
rec = preprocessing.phase_shift(recording=rec)
rec = preprocessing.common_reference(recording=rec, **config['common_reference'])
this passes
assert 'inter_sample_shift' in rec.get_property_keys()
this does NOT work and fails because of the assert error that just passed in previous line
sorting = runsorter.run_sorter_local(sorter_name="kilosort4",
recording=rec,
folder=config['out_dir'],
**config['kilosort']) `
This is the error message from the last command:
SpikeSortingError: Spike sorting error trace: ... File "/usr/local/lib/python3.9/dist-packages/spikeinterface/preprocessing/phase_shift.py", line 46, in __init__ assert "inter_sample_shift" in recording.get_property_keys(), "'inter_sample_shift' is not a property!" AssertionError: 'inter_sample_shift' is not a property!
Brian
The text was updated successfully, but these errors were encountered: