-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_s2c_als_sigmoid_sd_fits.py
44 lines (36 loc) · 1.93 KB
/
run_s2c_als_sigmoid_sd_fits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from spike2calcium_sigmoid_ALS_SD import *
import os, sys
import warnings
warnings.filterwarnings('ignore')
from glob import glob
# get cell list information
# flist = sorted(glob('GCaMP8_exported_ROIs_s2f_full/dff_v00/*.npz'))
# new fit based on the clean-up data
flist = sorted(glob('GCaMP8_exported_ROIs_s2f_full/dff_v03/*.npz'))
cell_info=["_".join(os.path.basename(f).split('_')[:6])[:-4] for f in flist]
cell_info_uq = np.unique(cell_info)
# fitting codes
def run_single_cell(nf):
nf = nf.squeeze()
if os.path.exists('GCaMP8_exported_ROIs_s2f_full/fit_als_sigmoid_sd_results_v03/'+nf+'_fit.npz'):
return None
_ = np.load(f'GCaMP8_exported_ROIs_s2f_full/dff_v03/{nf}.npz', allow_pickle=True)
spike_times = _['spike_times'] # raw fluorescence of the ROI
ca_times = _['ca_times'] # raw fluorescence of the surrounding neuropil, for neuropil subtraction
ca_trace = _['ca_trace'] # frame rate of the movie
cell_type = _['cell_type'] # timing of the action potentials from ephys
spike_times = [_ for _ in spike_times]
ca_times = [_ for _ in ca_times]
ca_trace =[_ for _ in ca_trace]
_=np.load('GCaMP8_exported_ROIs_s2f_full/fit_als_linear_sd_results_v05/'+nf+'_fit.npz', allow_pickle=True)
param_kernel = _['param_kernel']
for n in range(3): # do 4 times of ALS at 1st round, 2 times in 2nd
param_model = fit_spike2calcium_sigmoid(param_kernel, ca_trace, spike_times, ca_times)
param_kernel = fit_spike2calcium_kernel(param_kernel, param_model, ca_trace, spike_times, ca_times)
param_model = fit_spike2calcium_sigmoid(param_kernel, ca_trace, spike_times, ca_times)
np.savez('GCaMP8_exported_ROIs_s2f_full/fit_als_sigmoid_sd_results_v03/'+nf+'_fit', param_model=np.array(param_model), param_kernel=np.array(param_kernel))
return None
if __name__ == "__main__":
import dask
res = [dask.delayed(run_single_cell)(nf) for nf in cell_info_uq]
dask.compute(res)