How to preprocess a session#

Note

This is a quick how-to on session preprocessing. See here for a long-form tutorial.

if __name__ == "__main__":  # for multiprocessing

    import spikewrap as sw

    # We will use these configs
    sw.show_configs("neuropixels+kilosort2_5")

    # Now we will preprocess and save all sesssion data.

    session = sw.Session(
        subject_path=sw.get_example_data_path() / "rawdata" / "sub-001",
        session_name="ses-001",
        file_format="spikeglx",  # or "openephys"
        run_names="all",
        probe=None  # (optional argument), auto-detected for Neuropixels, but can set ProbeInterface probes here
    )

    session.preprocess(
        configs="neuropixels+kilosort2_5",
        per_shank=True,
        concat_runs=True
    )

    plots = session.plot_preprocessed(
        show=True,
        time_range=(0, 0.5),
        show_channel_ids=False,  # also, "mode"="map" or "line"
    )

    session.save_preprocessed(overwrite=True, n_jobs=6, slurm=False)
Session: ses-001, Run: concat_run, shank_0, Session: ses-001, Run: concat_run, shank_1
The preprocessing options are: {
    "1": [
        "phase_shift",
        {}
    ],
    "2": [
        "bandpass_filter",
        {
            "freq_max": 6000,
            "freq_min": 300
        }
    ],
    "3": [
        "common_reference",
        {
            "operator": "median",
            "reference": "global"
        }
    ]
}


The sorting options are: {
  "kilosort2_5": {
    "car": false,
    "freq_min": 150
  }
}


The preprocessing options are: {
    "1": [
        "phase_shift",
        {}
    ],
    "2": [
        "bandpass_filter",
        {
            "freq_max": 6000,
            "freq_min": 300
        }
    ],
    "3": [
        "common_reference",
        {
            "operator": "median",
            "reference": "global"
        }
    ]
}
/home/runner/work/spikewrap/spikewrap/spikewrap/process/_loading.py:147: UserWarning: The sessions or runs provided for are not in creation datetime order.
They will be concatenated in the order provided, as:
['run-002_g0_imec0', 'run-001_g0_imec0'].
  warnings.warn(

Loading data from path: /home/runner/work/spikewrap/spikewrap/spikewrap/examples/example_tiny_data/spikeglx/rawdata/sub-001/ses-001/ephys/run-002_g0_imec0

Loading data from path: /home/runner/work/spikewrap/spikewrap/spikewrap/examples/example_tiny_data/spikeglx/rawdata/sub-001/ses-001/ephys/run-001_g0_imec0

Concatenating raw recordings in the following order:['run-002_g0_imec0', 'run-001_g0_imec0']

Split run: concat_run by shank. There are 2 shanks.

Saving data for: concat_run...
write_binary_recording
engine=process - n_jobs=4 - samples_per_chunk=60,000 - chunk_memory=21.97 MiB - total_memory=87.89 MiB - chunk_duration=2.00s

write_binary_recording (workers: 1 processes):   0%|          | 0/1 [00:00<?, ?it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.64it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.64it/s]
write_binary_recording
engine=process - n_jobs=4 - samples_per_chunk=60,000 - chunk_memory=21.97 MiB - total_memory=87.89 MiB - chunk_duration=2.00s

write_binary_recording (workers: 1 processes):   0%|          | 0/1 [00:00<?, ?it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.67it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.67it/s]

We could run again with different configs and multiprocessing:

if __name__ == "__main__":

    pp_steps = {
        "1": ["phase_shift", {}],
        "2": ["bandpass_filter", {"freq_min": 300, "freq_max": 6000}],
        "3": ["common_reference", {"operator": "median", "reference": "global"}],
    }

    session.preprocess(configs=pp_steps, per_shank=False, concat_runs=False)

    session.plot_preprocessed(
        show=True,
        time_range=(0, 0.5),
        show_channel_ids=False,  # also, "mode"="map" or "line"
    )

    session.save_preprocessed(overwrite=True, n_jobs=6, slurm=False)
  • Session: ses-001, Run: run-002_g0_imec0
  • Session: ses-001, Run: run-001_g0_imec0
The preprocessing options are: {
    "1": [
        "phase_shift",
        {}
    ],
    "2": [
        "bandpass_filter",
        {
            "freq_max": 6000,
            "freq_min": 300
        }
    ],
    "3": [
        "common_reference",
        {
            "operator": "median",
            "reference": "global"
        }
    ]
}
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/spikeinterface/widgets/traces.py:150: UserWarning: You have selected a time after the end of the segment. The range will be clipped to 0.4999999999999989
  warnings.warn(
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/spikeinterface/widgets/traces.py:150: UserWarning: You have selected a time after the end of the segment. The range will be clipped to 0.4999999999999989
  warnings.warn(

Saving data for: run-002_g0_imec0...
write_binary_recording
engine=process - n_jobs=4 - samples_per_chunk=60,000 - chunk_memory=43.95 MiB - total_memory=175.78 MiB - chunk_duration=2.00s

write_binary_recording (workers: 1 processes):   0%|          | 0/1 [00:00<?, ?it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.55it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.55it/s]

Saving data for: run-001_g0_imec0...
write_binary_recording
engine=process - n_jobs=4 - samples_per_chunk=60,000 - chunk_memory=43.95 MiB - total_memory=175.78 MiB - chunk_duration=2.00s

write_binary_recording (workers: 1 processes):   0%|          | 0/1 [00:00<?, ?it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.48it/s]
write_binary_recording (workers: 1 processes): 100%|██████████| 1/1 [00:00<00:00,  1.48it/s]

Total running time of the script: (0 minutes 5.682 seconds)

Gallery generated by Sphinx-Gallery