-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preprocessing pipeline and associated configs.
- Loading branch information
1 parent
2b8b0c6
commit b4c21d1
Showing
7 changed files
with
674 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import glob | ||
import os | ||
from pathlib import Path | ||
from typing import Dict, Tuple | ||
|
||
import yaml | ||
|
||
from ..utils import utils | ||
|
||
|
||
def get_configs(name: str) -> Tuple[Dict, Dict, Dict]: | ||
""" | ||
Loads the config yaml file in the same folder | ||
(spikewrap/configs) containing preprocessing (pp) | ||
and sorter options. | ||
Once loaded, the list containing preprocesser name | ||
and kwargs is cast to tuple. This keeps the type | ||
checker happy while not requiring a tuple | ||
in the .yaml which require ugly tags. | ||
Parameters | ||
---------- | ||
name: name of the configs to load. Should not include the | ||
.yaml suffix. | ||
Returns | ||
------- | ||
pp_steps : a dictionary containing the preprocessing | ||
step order (keys) and a [pp_name, kwargs] | ||
list containing the spikeinterface preprocessing | ||
step and keyword options. | ||
sorter_options : a dictionary with sorter name (key) and | ||
a dictionary of kwargs to pass to the | ||
spikeinterface sorter class. | ||
""" | ||
config_dir = Path(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
available_files = glob.glob((config_dir / "*.yaml").as_posix()) | ||
available_files = [Path(path_).stem for path_ in available_files] | ||
|
||
if name not in available_files: # then assume it is a full path | ||
assert Path(name).is_file(), ( | ||
f"{name} is neither the name of an existing " | ||
f"config or valid path to configuration file." | ||
) | ||
|
||
assert Path(name).suffix in [ | ||
".yaml", | ||
".yml", | ||
], f"{name} is not the path to a .yaml file" | ||
|
||
config_filepath = Path(name) | ||
|
||
else: | ||
config_filepath = config_dir / f"{name}.yaml" | ||
|
||
with open(config_filepath) as file: | ||
config = yaml.full_load(file) | ||
|
||
pp_steps = config["preprocessing"] if "preprocessing" in config else {} | ||
sorter_options = config["sorting"] if "sorting" in config else {} | ||
waveform_options = config["waveforms"] if "waveforms" in config else {} | ||
|
||
utils.cast_pp_steps_values(pp_steps, "tuple") | ||
|
||
return pp_steps, sorter_options, waveform_options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'preprocessing': | ||
'1': | ||
- phase_shift | ||
- {} | ||
'2': | ||
- bandpass_filter | ||
- freq_min: 300 | ||
freq_max: 6000 | ||
'3': | ||
- common_reference | ||
- operator: median | ||
reference: global | ||
|
||
'sorting': | ||
'kilosort2': | ||
'car': False # common average referencing | ||
'freq_min': 150 # highpass filter cutoff, False nor 0 does not work to turn off. (results in KS error) | ||
'kilosort2_5': | ||
'car': False | ||
'freq_min': 150 | ||
'kilosort3': | ||
'car': False | ||
'freq_min': 300 | ||
'mountainsort5': | ||
'scheme': '2' | ||
'filter': False | ||
|
||
'waveforms': | ||
'ms_before': 2 | ||
'ms_after': 2 | ||
'max_spikes_per_unit': 500 | ||
'return_scaled': True | ||
# Sparsity Options | ||
'sparse': True | ||
'peak_sign': "neg" | ||
'method': "radius" | ||
'radius_um': 75 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
|
||
from spikewrap.pipeline.load_data import load_data | ||
from spikewrap.pipeline.preprocess import run_preprocessing | ||
|
||
base_path = Path( | ||
r"/ceph/neuroinformatics/neuroinformatics/scratch/jziminski/ephys/test_data/steve_multi_run/1119617/time-short-multises" | ||
# r"C:\data\ephys\test_data\steve_multi_run\1119617\time-miniscule-multises" | ||
) | ||
|
||
sub_name = "sub-1119617" | ||
sessions_and_runs = { | ||
"ses-001": [ | ||
"run-001_1119617_LSE1_shank12_g0", | ||
"run-002_made_up_g0", | ||
], | ||
"ses-002": [ | ||
"run-001_1119617_pretest1_shank12_g0", | ||
], | ||
"ses-003": [ | ||
"run-002_1119617_pretest1_shank12_g0", | ||
], | ||
} | ||
|
||
loaded_data = load_data(base_path, sub_name, sessions_and_runs, data_format="spikeglx") | ||
|
||
run_preprocessing( | ||
loaded_data, | ||
pp_steps="default", | ||
handle_existing_data="overwrite", | ||
log=True, | ||
) |
Oops, something went wrong.