Exporting to phy changes cluster channels

Open
#3,394 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start with the supplied script, especially read_phy, recording.set_probe, and export_to_phy, and inspect how channel_positions.npy is used before cluster_info.tsv is written. Reproduce the export with the shown analyzer and compare channel numbers before export with cluster_info.tsv afterward. Done means exported channel numbers match the analyzer and the resulting waveforms and quality metrics use the intended channels.

Written by the indexing model from the issue text.

Description

exporters

After manual curation, I'm recalculating cluster waveforms and some quality metrics using the script below. However, when I export to phy, the channel numbers are wrong. When I pause/debug the script before export_to_phy, channel numbers are correct, but inspecting cluster_info.tsv after exporting, they're different. I would fix this post-hoc, but because the channel numbers are wrong, the calculated waveforms and subsequent waveform based quality metrics are also incorrect. I'd very much appreciate any help!

                  rec_folder = Path(probe_folder, probe)
                        probe_number = find_numbers_in_string(probe)
                        phy_dir = rec_folder
                        ac_dir = Path(phy_dir, 'postprocessed')
                        ac_dir_wave = Path(ac_dir, 'waveforms')
                        ac_dir_phy = Path(ac_dir, 'phy')

                        if not os.path.isdir(ac_dir_phy):

                            waveform_folder = Path(phy_dir, "analyzer")
                            report_folder = Path(phy_dir, 'report')

                            # Load your sorted units from the Phy folder
                            sorting = read_phy(phy_dir)

                            # Get channel locations from .npy file
                            path_channel_location = Path(phy_dir, 'channel_positions.npy')
                            channel_locations = np.load(path_channel_location)
                            num_channels = channel_locations.shape[0]

                            # Load the original recording
                            recording = si.read_binary(Path(ses_folder, "ksData_probe" + str(probe_number[0]) + ".dat"),
                                                       sampling_frequency=fs,
                                                       num_channels=num_channels,
                                                       dtype="int16")

                            probe_64, locations = utils.gen_probe()
                            recording.set_probe(probe_64, in_place=True)

                            #recording.set_dummy_probe_from_locations(channel_locations)
                            recording.annotate(is_filtered=True)

                            sorting = remove_excess_spikes(sorting, recording)
                            sorting = remove_duplicated_spikes(sorting=sorting, censored_period_ms=0.5, method="keep_first")
                            #sorting = sorting.remove_empty_units()

                            print("building analyzer")
                            analyzer = si.create_sorting_analyzer(sorting=sorting, recording=recording, return_scaled=False)

                            analyzer.compute("random_spikes")
                            analyzer.compute("waveforms", save=True)
                            templates = analyzer.compute("templates", save=True)
                            analyzer.compute(
                                "spike_amplitudes",
                                peak_sign="pos"
                            )
                            analyzer.compute("noise_levels")

                            amp_cutoff = analyzer.compute(
                                "quality_metrics",
                                qm_params=dqm_params
                            )

                            print("Saving analyizer")
                            analyzer.save_as(format="binary_folder", folder=ac_dir_wave)
                            print("Exproting to phy")
                            export_to_phy(analyzer, output_folder=ac_dir_phy, copy_binary=False, additional_properties=['quality'], remove_if_exists=True)
                            print("Finished" + str(ac_dir_phy))

Dominant language
Python
Stars
847
Forks
280
Avg merge
3d 9h
Merged PRs (30d)
29

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SpikeInterface/spikeinterface

All issues in SpikeInterface/spikeinterface

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.