forked from Schroeder-Lab/Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_preprocess.py
81 lines (74 loc) · 2.18 KB
/
main_preprocess.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
import numpy as np
from matplotlib import pyplot as plt
import random
import sklearn
import seaborn as sns
import scipy as sp
from matplotlib import rc
import matplotlib.ticker as mtick
import matplotlib as mpl
import pandas as pd
import os
import glob
import pickle
import traceback
from Data.TwoP.runners import *
from Data.Bonsai.extract_data import *
from Data.TwoP.folder_defs import *
# %%
csvDir, s2pDir, zstackDir, metadataDir = define_directories()
pops = create_processing_ops()
# %%
# read database
# In the file the values should be Name, Date, Zstack dir number, planes to ignore
# and save directory (if none default is wanted) and proces (True,False)
database = pd.read_csv(
csvDir,
dtype={
"Name": str,
"Date": str,
"Zstack": str,
"IgnorePlanes": str,
"SaveDir": str,
"Process": bool,
},
)
# %% run over data base
for i in range(len(database)):
if database.loc[i]["Process"]:
try:
print("reading directories")
(
s2pDirectory,
zstackPath,
metadataDirectory,
saveDirectory,
) = read_csv_produce_directories(
database.loc[i], s2pDir, zstackDir, metadataDir
)
ignorePlanes = np.atleast_1d(
np.array(database.loc[0]["IgnorePlanes"]).astype(int)
)
ops = get_ops_file(s2pDirectory)
print("getting piezo data")
planePiezo = get_piezo_data(ops)
print("processing suite2p data")
fc = process_s2p_directory(
s2pDirectory,
pops,
planePiezo,
zstackPath,
saveDirectory=saveDirectory,
ignorePlanes=ignorePlanes,
debug=pops["debug"],
)
print("reading bonsai data")
process_metadata_directory(
metadataDirectory, ops, pops, saveDirectory
)
except Exception:
print("Could not process due to errors, moving to next batch.")
print(traceback.format_exc())
else:
print("skipping " + str(database.loc[i]))
# %%