Skip to content
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

Modifications for Kilosort with posthoc merge #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions klusta_pipeline/make_kilo_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from string import Template
from klusta_pipeline import TEMPLATE_DIR


def get_args():
parser = argparse.ArgumentParser(description='Compile KWD file into flat binary .dat file for kilosort.')
parser.add_argument('path', default='./', nargs='?',
Expand All @@ -12,37 +13,38 @@ def get_args():
help='destination directory for chanMap.mat file')
parser.add_argument('local_sort_dir', default='./', nargs='?',
help='local data directory on sorting computer')
parser.add_argument('--kilodir', default='/home/mthielk/github/KiloSort',
dest='kilodir', type=str,
help='path to kilosort folder')
parser.add_argument('--npy_matdir', default='/home/mthielk/github/npy-matlab',
dest='npy_matdir', type=str,
help='path to npy-matlab scripts')
parser.add_argument('--kilodir', default='/home/earneodo/github/KiloSort',
dest='kilodir', type=str,
help='path to kilosort folder')
parser.add_argument('--npy_matdir', default='/home/earneodo/github/npy-matlab',
dest='npy_matdir', type=str,
help='path to npy-matlab scripts')
parser.add_argument('-s', '--sampling_rate', dest='fs', type=float, default=None,
help='target sampling rate for waveform alignment. If omitted, uses recording sampling rate')
help='target sampling rate for waveform alignment. If omitted, uses recording sampling rate')
parser.add_argument('--Nchan', dest='Nchan', type=float, default=None,
help='Target number of channels. If omitted, uses recording value')
help='Target number of channels. If omitted, uses recording value')
parser.add_argument('--Nfilt', dest='Nfilt', type=float, default=96,
help='Target number of filters for kilosort to use. 2-4 times more than Nchan, should be a multiple of 32. Defaults to 96')
help='Target number of filters for kilosort to use. 2-4 times more than Nchan, should be a multiple of 32. Defaults to 96')
return parser.parse_args()


def main():
args = get_args()
tstart = datetime.datetime.now()

path = os.path.abspath(args.path)
dest = os.path.abspath(args.dest)

assert len(glob.glob(os.path.join(path,'*.raw.kwd')))==1, "Error finding .raw.kwd file"
catlog = glob.glob(os.path.join(path,'*.raw.kwd'))[0]
assert len(glob.glob(os.path.join(path, '*.raw.kwd'))) == 1, "Error finding .raw.kwd file"
catlog = glob.glob(os.path.join(path, '*.raw.kwd'))[0]
blockname = os.path.split(catlog)[-1].split('.')[0]

if args.fs is None or args.Nchan is None:
params_file = os.path.join(path, 'params.prm')
with open(params_file, 'r') as f:
contents = f.read()
metadata = {}
exec(contents, {}, metadata)
exec (contents, {}, metadata)

if args.fs is None:
fs = metadata['traces']['sample_rate']
Expand All @@ -61,7 +63,8 @@ def main():
'blockname': blockname,
'fs': fs,
'Nchan': Nchan,
'Nfilt': args.Nfilt
'Nfilt': args.Nfilt,
'useGPU': 1
}

with open(os.path.join(TEMPLATE_DIR, 'master.template'), 'r') as src:
Expand All @@ -75,4 +78,4 @@ def main():
f.write(config_template.substitute(params))

print 'peak memory usage: %f GB' % (resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024. / 1024.)
print 'time elapsed: %s' % (datetime.datetime.now() - tstart)
print 'time elapsed: %s' % (datetime.datetime.now() - tstart)
2 changes: 1 addition & 1 deletion klusta_pipeline/make_kwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def main():
chans = chans.intersection(d2['chans'])
chans = list(chans)

for i,m in zip(info['exports'],mat_data):
for i,m in zip(info['exports'], mat_data):
i['chans'] = chans

port_map = port_site[args.rig]
Expand Down
115 changes: 102 additions & 13 deletions klusta_pipeline/maps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

#applies the transformation of sites to headstage introduced by an adapter

# applies the transformation of sites to headstage introduced by an adapter
def apply_adapter(a_port_site, adapter):
'''
a_port_site: a dictionary with port: site (mapping channels in a headstage to ports in a recording system)
Expand All @@ -9,22 +10,23 @@ def apply_adapter(a_port_site, adapter):
col 1: site in porbe end
retunrs: new dictionary with port: mapped_site, where mapped_site is the probe site that connects to that channel instead of site
'''
new_port_site = {port : adapter[adapter[:, 1] == site][0, 0] for port, site in a_port_site.iteritems()}
new_port_site = {port: adapter[adapter[:, 1] == site][0, 0] for port, site in a_port_site.iteritems()}
return new_port_site


# n_site x 2 numpy array
# col 0: site in headstage end
# col 1: site in porbe end
site_headstage = {
'A32-HST32V': np.transpose(np.array([[11, 9, 7, 5, 3, 2, 6, 8, 10, 12,
1, 4, 13, 14, 15, 16,
26, 24, 20, 19, 18, 17,
32, 30, 31, 28, 29, 27, 25, 22, 23, 21],
[1, 2, 3, 4, 6, 8, 10, 12, 14, 16,
5, 7, 9, 11, 13, 15,
21, 23, 25, 27, 29, 31,
17, 18, 19, 20, 22, 24, 26, 28, 30, 32]], dtype=np.int)
)}
1, 4, 13, 14, 15, 16,
26, 24, 20, 19, 18, 17,
32, 30, 31, 28, 29, 27, 25, 22, 23, 21],
[1, 2, 3, 4, 6, 8, 10, 12, 14, 16,
5, 7, 9, 11, 13, 15,
21, 23, 25, 27, 29, 31,
17, 18, 19, 20, 22, 24, 26, 28, 30, 32]], dtype=np.int)
)}

# dictionary yields port:site
port_site = {
Expand Down Expand Up @@ -80,14 +82,101 @@ def apply_adapter(a_port_site, adapter):
'Port_15': 6,
'Port_16': 5,
},
'passaro32-nn': {
'Port_1': 26,
'Port_2': 25,
'Port_3': 24,
'Port_4': 19,
'Port_5': 23,
'Port_6': 22,
'Port_7': 21,
'Port_8': 20,
'Port_9': 18,
'Port_10': 27,
'Port_11': 28,
'Port_12': 29,
'Port_13': 17,
'Port_14': 30,
'Port_15': 31,
'Port_16': 32,
'Port_17': 1,
'Port_18': 2,
'Port_19': 3,
'Port_20': 16,
'Port_21': 4,
'Port_22': 5,
'Port_23': 6,
'Port_24': 15,
'Port_25': 13,
'Port_26': 12,
'Port_27': 11,
'Port_28': 10,
'Port_29': 14,
'Port_30': 9,
'Port_31': 8,
'Port_32': 7,
},
'passaro16-nn': {
'Port_1': 13,
'Port_2': 10,
'Port_3': 11,
'Port_4': 12,
'Port_5': 14,
'Port_6': 15,
'Port_7': 9,
'Port_8': 16,
'Port_9': 1,
'Port_10': 8,
'Port_11': 2,
'Port_12': 3,
'Port_13': 5,
'Port_14': 6,
'Port_15': 7,
'Port_16': 4,
},
# Port 2 in John Hermiz's Flex-Intan Adapter v2 to rhd164 (upper connector)
'passaro64-fi2': {
'Port_16': 2,
'Port_17': 1,
'Port_18': 4,
'Port_19': 3,
'Port_20': 6,
'Port_21': 5,
'Port_22': 8,
'Port_23': 7,
'Port_24': 10,
'Port_25': 9,
'Port_26': 12,
'Port_27': 11,
'Port_28': 14,
'Port_29': 13,
'Port_30': 16,
'Port_31': 15,
'Port_32': 18,
'Port_33': 17,
'Port_34': 20,
'Port_35': 19,
'Port_36': 22,
'Port_37': 21,
'Port_38': 24,
'Port_39': 23,
'Port_40': 26,
'Port_41': 25,
'Port_42': 28,
'Port_43': 27,
'Port_44': 30,
'Port_45': 29,
'Port_46': 32,
'Port_47': 31,
}
}
port_site['ibon32'] = port_site['paukstis32']
port_site['bodegh16'] = {'Port_%d' % (i+1) : i+1 for i in range(16) }
port_site['bodegh16'] = {'Port_%d' % (i + 1): i + 1 for i in range(16)}
port_site['burung16'] = port_site['bodegh16']

# Burung system with 32 channels trhough amps 2, 3, with no adapter
burung32_No_Adapter = {'Port_%d' % (i+1+16) : i+1 for i in range(32)}
burung32_No_Adapter = {'Port_%d' % (i + 1 + 16): i + 1 for i in range(32)}

# Buring system with the A32 adapter for neuronexus probes
port_site['burung32-A32-HST32V'] = apply_adapter(burung32_No_Adapter, site_headstage['A32-HST32V'])
port_site['burung32'] = port_site['burung32-A32-HST32V']
port_site['burung32'] = port_site['burung32-A32-HST32V']
Loading