-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_data.py
574 lines (441 loc) · 25.8 KB
/
update_data.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
import induc_SPW as ispw
import numpy as np
#import read_data as reader
import pylab as py
import data_mang as dat
import folder_manager as fold_mng
import gc #garbage collector
def up_intraSpikes(save_folder, save_file = 'intra_spikes.npz', load_file = 'data_intra.npz', reanalize = False):
""" finds the spikes in the intracellular data"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_intraSpikes(save_folder, save_file = save_file, load_file = load_file, pulse_len = 500)
else:
print 'intracellular spikes were already found previously'
gc.collect()
def up_intrafile(filename, save_folder, save_file = 'data_intra.npz', int_electrodes = [1], reanalize = False):
""" read intracellular data"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_datafile(filename, int_electrodes, save_folder, data_file = save_file)
else:
print 'raw intracellular data was already loaded'
gc.collect()
def up_datafile(filename, save_folder, save_file = 'data.npz', ext_electrodes = [1], intr_electrode = 1, reanalize = False):
""" updates only the datafile for the given values """
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
ispw.update_datafile(filename, ext_electrodes, save_folder, data_file = save_file)
else:
print 'raw data file already exists'
gc.collect()
def up_databas(save_folder, save_file = "data_dspl.npz", load_file = 'data.npz', reanalize = False):
""" it downsamples the data taken from the given file and saves it in another file"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_databas(data_load = load_file, save_folder = save_folder, data_file = save_file)
else:
print 'raw data was already moved to the baseline'
gc.collect()
def up_highWaves(save_folder, filter_folder, save_file = "data_movavg.npz", load_datafile = 'data.npz', reanalize = False):
""" it subtracts moving average from the data"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_highWaves(load_datafile, filter_folder, save_folder, data_file = save_file, atten_len = 25)
else:
print 'raw data was already moved to the baseline'
gc.collect()
def up_highWaves_numb(save_folder, save_file = 'spws_params.npz', load_spwsfile = 'spws_potential', reanalize = False):
""" it finds the characteristics of each spw"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load spike params
ispw.update_highWaves_numb(load_spwsfile, save_folder, save_file)
else:
print 'spws were already analysed'
gc.collect()
def up_spws_spikes_ampl(save_folder, save_file = 'data.npz', load_spwsspike = 'SPWs_spikes.npz', load_spikefile = 'spikes_params.npz', reanalize = False):
""" Finds which of the spikes detected is of the same amplitude as coresponding highest spike - it returns only the highest amplitude spikes"""
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
ispw.update_SPW_spikes_ampl(load_spikefile, load_spwsspike, save_folder, save_file)
else:
print 'spws were already analysed'
gc.collect()
def up_spikes_ampl(save_folder, save_file ='spikes_in_spws', load_spike_file = 'spikes.npz', reanalize = False):
""" finds all the spikes for the given spw"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_spikes_ampls(save_folder, save_file, load_spike_file)
else:
print 'origins of spikes were already calculated'
gc.collect()
def up_remove_too_small_spws(save_folder, save_file, load_datafile, load_spwsipsp, min_ampl, reanalize = False, ext = '.pdf'):
"""analyse all the ipsps and correct them"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
fig_fold_name = 'SPW_IPSPs/'
fold_mng.create_folder(save_folder + fig_fold_name)
ispw.update_remove_too_small_spws(load_datafile, load_spwsipsp, min_ampl, save_folder, save_file, ext)
gc.collect()
def up_correct_ipsps(save_folder, save_fig = 'spw_ipsp', save_file = 'save_it.npz', load_datafile = 'data.npz', load_spwsipsp = 'spws.npz', load_spwsspike = 'spw_spike.npz', reanalize = False, ext = '.pdf'):
"""analyse all the ipsps and correct them"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
fig_fold_name = 'SPW_IPSPs/'
fold_mng.create_folder(save_folder + fig_fold_name)
ispw.corect_ipsps(load_datafile, load_spwsipsp, load_spwsspike, save_folder, fig_fold_name + save_fig, save_file, ext)
gc.collect()
def up_spws_first_max(save_folder, save_file, spws, datafile, reanalize = False):
""" alignes spws on the first maximum within the window"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
fig_fold_name = 'SPW_IPSPs/'
fold_mng.create_folder(save_folder + fig_fold_name)
ispw.update_spws_first_max(save_folder, spws, datafile, save_file, window = [-1, 3])
gc.collect()
def up_divide_to_groups(load_datafile, load_spwsipsp, save_folder, save_file, reanalize):
"""analyse the beginning of each SPW - finds the beginnings - time and location"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
fig_fold_name = 'SPW_IPSPs/'
fold_mng.create_folder(save_folder + fig_fold_name)
ispw.divide_to_groups(load_datafile, load_spwsipsp, save_folder, save_file)
gc.collect()
def up_spws_beg(save_folder, save_fig = 'spw_ipsp', save_file = 'save_it.npz', load_datafile = 'data.npz', load_spwsipsp = 'spws.npz', load_spwsspike = 'spw_spike.npz', reanalize = False, ext = '.pdf', expected_min_ipsp_ampl= 30):
"""analyse the beginning of each SPW - finds the beginnings - time and location"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
fig_fold_name = 'SPW_IPSPs/'
fold_mng.create_folder(save_folder + fig_fold_name)
ispw.update_spws_beg(load_datafile, load_spwsipsp, load_spwsspike, save_folder, fig_fold_name + save_fig, save_file, ext, expected_min_ipsp_ampl = expected_min_ipsp_ampl)
gc.collect()
def up_group_ipsps(save_folder, ipsps_groups, load_spwsipsp, load_datafile, save_file, reanalize):
""" groups the IPSPs and assigns to them groups"""
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
fig_fold_name = 'SPW_IPSPs/'
fold_mng.create_folder(save_folder + fig_fold_name)
# load the data
ispw.update_ipsps_groups(save_folder, ipsps_groups, load_spwsipsp, load_datafile, save_file)
gc.collect()
def up_spws_ipsp_beg(save_folder, filter_folder, save_fig = 'spw_ipsp', save_file = 'save_it.npz', load_datafile = 'data.npz', load_spwsipsp = 'spws.npz', load_spwsspike = 'spw_spike.npz', reanalize = False, ext = '.pdf', expected_min_ipsp_ampl = 30):
"""analyse the ipsps in each SPWs - finds the beginnings, and removes those which are not correct"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
fig_fold_name = 'SPW_IPSPs/'
fold_mng.create_folder(save_folder + fig_fold_name)
# load the data (save_folder, ipsps_groups, load_spwsipsp, load_datafile, save_file)
ispw.update_spws_ipsp_beg(load_datafile, filter_folder, load_spwsipsp, load_spwsspike, save_folder, fig_fold_name + save_fig, save_file, ext, expected_min_ipsp_ampl)
gc.collect()
#def up_spws_ipsp_ampl(save_folder, save_file = 'save_it.npz', load_datafile = 'data.npz', load_spwsipsp = 'spws.npz', reanalize = False):
# """analyse the ipsps and checks in which electrode it has the highest amplitude"""
# # check if folder already exists
# fold_mng.create_folder(save_folder)
#
# # check if this file already exists
# exists = fold_mng.file_exists(save_folder, save_file)
# if reanalize or not exists:
# # load the data
# npzfile = np.load(save_folder + load_datafile)
# data = npzfile['data']
# fs = npzfile['fs']
# npzfile.close()
#
# npzfile = np.load(save_folder + load_spwsipsp)
# npzfile.close()
# import pdb; pdb.set_trace()
#
# ispw.update_SPW_ipsp_ampl(save_folder, save_file, data, fs)
# gc.collect()
def update_ipsp_exSpikes(save_folder, save_file):
pass
def equalize_number_spws(save_folder, save_file, induc_spont, load_distances, reanalize):
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_equalize_number_spws(save_folder = save_folder, save_file = save_file, induc_spont = induc_spont, load_distances = load_distances)
else:
print 'Initiated SPWs were already saved'
gc.collect()
def up_merge_close_groups(save_folder, save_file, spw_file, data_file, reanalize = False):
""" it merges too close groups of IPSPs, it chooses the one which is lower if there are
two on the same electrode"""
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_merge_close_groups(save_folder = save_folder, save_file = save_file, spw_file = spw_file, data_file = data_file)
else:
print 'Initiated SPWs were already saved'
gc.collect()
def up_add_missing_electrodes_SPW(save_folder, save_file, spw_file, data_file, reanalize = False, expected_min_ipsp_ampl = 30):
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_add_missing_electrodes_SPW(save_folder = save_folder, save_file = save_file, spw_file = spw_file, data_file = data_file)
else:
print 'Initiated SPWs were already saved'
gc.collect()
def up_remove_with_to_few_ipsps(save_folder, save_file, spw_file, to_remove, reanalize = False):
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_remove_with_to_few_ipsps(save_folder = save_folder, save_file = save_file, spw_file = spw_file, to_remove = to_remove)
else:
print 'Initiated SPWs were already saved'
gc.collect()
def up_display_SPWs(save_folder, data_file, spw_file, reanalize = False):
# load the data
ispw.up_display_SPWs(save_folder = save_folder, data_file = data_file, spw_file = spw_file)
gc.collect()
def up_fill_gap_between_ipsp_groups(save_folder, save_file, spw_file, data_file, reanalize = False):
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_fill_gap_between_ipsp_groups(save_folder = save_folder, save_file = save_file, spw_file = spw_file, data_file = data_file)
else:
print 'Initiated SPWs were already saved'
gc.collect()
def up_induc_spont_spw(save_folder, save_file = 'i_s_spws', load_distances = 'distances.npz', load_spwfile = 'spws.npz', max_init_dist = 10, reanalize = False, ext = '.pdf'):
""" it finds which spws are initiated and which are sponteneaus"""
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_induc_spont_spw(save_folder = save_folder, save_file = save_file, load_distances = load_distances, load_spwfile = load_spwfile, max_dist =max_init_dist, ext = ext)
else:
print 'Initiated SPWs were already saved'
gc.collect()
def up_dist_SpwfromSpike(save_folder, save_file = 'spw_dist.npz', load_intrafile = 'intra_data.npz', load_spwfile = 'spw_data.npz', spikes = 'all', reanalize = False):
""" it finds the distance intracellular spike to each spw"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_dist_SPWfromSpike(save_folder = save_folder, save_file = save_file, load_intrafile = load_intrafile, load_spwfile = load_spwfile, max_dist = 15, spikes = spikes)
else:
print 'distances of spws to intracellular spikes were already calculated'
gc.collect()
def up_SPW_ipsp(save_folder, filter_folder, save_file = 'spws_params.npz', load_datafile = "data_movavg.npz", load_waves = 'spws.npz', load_spikes = 'spws_potential', induced_dist = 7, reanalize = False):
""" it finds the characteristics of each spw"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
# load the data
ispw.update_SPW_ipsp(load_datafile, filter_folder, load_waves, load_spikes, save_folder, save_file)
else:
print 'spws were already analysed'
gc.collect()
def up_filtered(save_folder, save_file = 'spw_data.npz', load_file = "data_dspl.npz", freq = [1.5, 500.0], reanalize = False):
""" filteres the data from the given file to given frequencies"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
npzfile = np.load(save_folder + load_file)
data = npzfile['data']
fs = npzfile['fs']
npzfile.close()
data_filt, freq, fs_data = ispw.update_filtered(data, fs, save_folder, freq, data_file = save_file)
else:
print 'raw data was already filtered'
gc.collect()
def up_extraspikes(save_folder, filter_folder, save_file = "ex_spikes", load_file = "data_dspl.npz", spikes_filter = 'filter_', reanalize = False):
""" finding extracellular spikes in the data """
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
ispw.update_extraspikes(data_load = load_file, filter_folder = filter_folder, save_folder = save_folder, save_file = save_file, save_filter = spikes_filter)
else:
print 'spikes were already found'
gc.collect()
def up_create_sup_fig(save_fig_name, save_folder, data_file, filter_folder, spike_file, spikes_raw, spikes_largest, final_Ipsp_spw, ext = '.pdf', start_no = 11):
ispw.create_sup_fig(save_fig_name, save_folder, data_file, filter_folder, spike_file, spikes_raw, spikes_largest, final_Ipsp_spw, ext = ext, start_no = start_no)
def up_spws(save_folder, save_file = 'spw_data.npz', load_file = 'spw_data.npz', reanalize = False):
""" updates details of the spws"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
npzfile = np.load(save_folder + load_file)
data = npzfile['data']
fs = npzfile['fs']
npzfile.close()
spw_idxs, spw_maxs, starts_spw, ends_spw, lengths_spw, fs_spws = ispw.update_spws(data, fs = fs, save_folder = save_folder, save_file = save_file)
else:
print 'raw data was already filtered'
gc.collect()
def up_expikes_params(save_folder, save_file = 'spw_data.npz', load_datafile = 'spw_data.npz', load_spikefile = 'spikefile.npz', reanalize = False):
""" finds different parameters of the spike and returns them in ms"""
# check if folder already exists
fold_mng.create_folder(save_folder)
# check if this file already exists
exists = fold_mng.file_exists(save_folder, save_file)
if reanalize or not exists:
ispw.update_expikes_params(load_datafile, load_spikefile, save_folder, save_file = save_file)
else:
print 'spikes parameters were already calculated'
gc.collect()
def up_downsample(save_folder, dspl = 2, data_file = 'data_dspl'):
""" updates only downsampling data"""
data_all, fs = reader.read_datafile(save_folder) # read existing data
data_dspl, fs_dspl = ispw.update_downsample(data_all, fs, save_folder, dspl, data_file = 'data_dspl')
return data_dspl, fs_dspl
def up_ipsp(save_folder):
""" updates details of the spws"""
data_bas, fs = reader.read_databas(save_folder)
spw_idxs, spw_maxs, starts_spw, ends_spw, lengths_spw, fs_spws = ispw.update_spws(data_bas, fs = fs, save_folder = save_folder, save_file = 'IPSPs', thresh_mult= 1.5)
#spw_idxs, spw_maxs, starts_spw, ends_spw, lengths_spw, fs = reader.read_SPWs(save_folder)
#print spw_idxs
return spw_idxs, spw_maxs, starts_spw, ends_spw, lengths_spw, fs_spws
def up_ripples(save_folder):
data_ripple, freq, fs = reader.read_filtered_ripple(save_folder, save_file = "ripple_data.npz")
rip_idxs, fs_ripple = ispw.update_ripples(data_ripple, fs, save_folder, data_file = 'ripples')
return rip_idxs, fs_ripple
def up_spw_ripple(save_folder):
spw_idxs, spw_maxs, starts_spw, ends_spw, lengths_spw, fs = reader.read_SPWs(save_folder)
ris_all, iris_no_all = ispw.update_spw_ripple(starts_spw, ends_spw, spw_idxs, save_folder, data_file = 'spw_ripple')
return ris_all, iris_no_all
def update_fs(fs_1, fs_2, values = []):
# all the values will be updated to the fs_2
if fs_1 != fs_2:
fs_div = fs_2/ fs_1 # if the sampling rate is different
# the sampling rates in the two data sets are different
for val in range(len(values)):
#print np.size(spw_idxs)
for electr in range(len(values[val])):
for trace in range(len(values[val][electr])):
for individual in range(len(values[val][electr][trace])):
values[val][electr][trace][individual] = values[val][electr][trace][individual] * fs_div
values[val] = ispw.round_spike_idxs(values[val])
fs = fs_1 * fs_div
else:
fs = fs_2
return values, fs
def up_dist_fromSPW(save_folder, intra = 0):
spw_idxs, spw_maxs, starts_spw, ends_spw, lengths_spw, fs_spw = reader.read_SPWs(save_folder)
spike_idxs, spikes_ampl, fs_spike = reader.read_extraspikes(save_folder)
values, fs = update_fs(fs_spw, fs_spike, values = [spw_idxs, starts_spw, ends_spw])
spw_idxs = values[0]
starts_spw = values[1]
ends_spw = values[2]
distances, min_distances, fs, max_dist = ispw.update_dist_fromSpike(starts_spw, spike_idxs, fs, save_folder, data_file = 'dist_fromSPW', allowms = 5, intra = 0)
def up_downsample_intra(save_folder, dspl = 2):
""" updates only downsampling data"""
data_intra, fs = reader.read_datafile(save_folder, 'intra.npz') # read existing data
data_dspl_intra, fs_new_down = ispw.update_downsample(data_intra, fs, save_folder, dspl = 2, data_file = 'data_dspl_intra')
return data_dspl_intra, fs_new_down
def up_dist_fromSpike(save_folder, intra = 0):
sp_intra_first, sp_intra_all, fs_intra = reader.read_intra_spikes(save_folder, save_file = "intra_spikes.npz")
spike_extra, spikes_ampl, fs_extra = reader.read_extraspikes(save_folder, save_file = "ex_spikes.npz")
values, fs = update_fs(fs_extra, fs_intra, values = [spike_extra])
spike_extra = values[0]
distances, min_distances, fs, max_dist = ispw.update_dist_fromSpike(sp_intra_all, spike_extra, fs_intra, save_folder, data_file = 'dist_fromSpike', max_dist = 3, intra = intra)
return distances, min_distances, fs, max_dist
def update_all(filename, ext_electrodes, save_folder, intr_electrode = 1, data_part = 'all'):
""" should be done each time the data is to be run from the beginning to the end again"""
# read all the data
data_all, fs = ispw.update_datafile(filename, ext_electrodes, save_folder, data_file = 'data', data_part = data_part)
data_dspl, fs_dspl = ispw.update_downsample(data_all, fs, save_folder, data_file = 'data_dspl')
data_bas, fs_bas = ispw.update_databas(data_dspl, fs_dspl, save_folder, data_file = 'data_bas') # move to baseline
# update filtered data
SPW_freq = [1.5, 500.0]
ripple_freq = [100.0, 300.0]
fast_freq = [750.0, -1]
data_spw, freq, fs_data = ispw.update_filtered(data_bas, fs_bas, save_folder, SPW_freq, 'spw_data')
data_ripple, freq, fs_ripple = ispw.update_filtered(data_bas, fs_bas, save_folder, ripple_freq, "ripple_data")
data_fast, freq, fs_fast = ispw.update_filtered(data_bas, fs_bas, save_folder, fast_freq, "fast_data")
#uspl = 1
#data_uspl_extra, fs_new_up = update_upsample(data_all, fs, save_folder, uspl = uspl, data_file = 'data_uspl_extra')
spike_idxs, spikes_ampl, fs_espikes = ispw.update_extraspikes(data_all, fs, save_folder, save_file = "ex_spikes")
spike_idxs, all_valley_to_peak, all_half_valley_width, all_half_peak_width, fs_new = ispw.update_expikes_params(data_all, fs_espikes, save_folder, spike_idxs, save_file = "ex_sparamas")
spw_idxs, spw_maxs, starts_spw, ends_spw, lengths_spw, fs_spws = ispw.update_spws(data_bas, data_fast, data_spw, fs_bas, save_folder, save_file = 'SPWs')
rip_idxs, fs_ripple = ispw.update_ripples(data_ripple, fs_ripple, save_folder, data_file = 'ripples')
ris_all, iris_no_all = ispw.update_spw_ripple(starts_spw, ends_spw, spw_idxs, save_folder, data_file = 'spw_ripple')
if fs_spws != fs_espikes:
fs_div = fs_espikes/ fs_spws # if the sampling rate is different
print np.shape(spw_idxs[0])
for i in range(len(spw_idxs)):
for g in range(len(spw_idxs[i])):
spw_idxs[i][g] = spw_idxs[i][g] * fs_div
starts_spw[i][g] = starts_spw[i][g] * fs_div
ends_spw[i][g] = ends_spw[i][g] * fs_div
spw_idxs = ispw.round_spike_idxs(spw_idxs)
starts_spw = ispw.round_spike_idxs(starts_spw)
ends_spw = ispw.round_spike_idxs(ends_spw)
fs_spws = fs_spws * fs_div
distances, min_distances, fs, max_dist = ispw.update_dist_fromSpike(starts_spw, spike_idxs, fs_spws, save_folder, data_file = 'dist_fromSPW')
if intr_electrode != -1:
data_intra, fs = ispw.update_datafile(filename, [intr_electrode], save_folder, data_file = 'intra', data_part = data_part)
data_dspl_intra, fs_new_down = ispw.update_downsample(data_intra, fs, save_folder, dspl = 2, data_file = 'data_dspl_intra')
sp_idx_first, sp_idx_all, fs = ispw.update_intraSpikes(data_intra[0], fs, save_folder, save_file = "intra_spikes", pulse_len = 500)
# compare extra and intra data
distances, min_distances, fs, max_dist = ispw.update_dist_fromSpike(sp_idx_all, spike_idxs, fs, save_folder, data_file = 'dist_fromSpike', max_dist = 3)
distances, min_distances, fs, max_dist = ispw.update_dist_fromSpike(sp_idx_first, starts_spw, fs, save_folder, data_file = 'dist_SpwfromSpike', max_dist = 10)