-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotTracesFromCellsScript.py
More file actions
148 lines (98 loc) · 4.77 KB
/
PlotTracesFromCellsScript.py
File metadata and controls
148 lines (98 loc) · 4.77 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 18 09:03:29 2019
@author: thugwithyoyo
"""
# Be sure to run PlotPeriEventAverages_TuningSorted (with resultant workspace
# loaded) prior to running this script.
# 2018-12-18-11-20-21 cells to select
#CellsToSelectList = ['C031', 'C085', 'C025', 'C081', 'C099', 'C101']
CellsToSelectList=['C025', 'C031', 'C085']
# select cells
CellsToSelectList = np.array(CellsToSelectList)
(NumCellsToSelect,) = CellsToSelectList.shape
# Generate averaged z-scored traces version of plot
fig, axes = plt.subplots(1, NumCellsToSelect)
fig.suptitle('Averaged Z-SCORED $\Delta$F trace averages from cells')
for i in np.arange(0, NumCellsToSelect):
axes[i].set_title(str(CellsToSelectList[i]))
if i == 0:
axes[i].set_ylabel('Average z-scored $\Delta$F')
axes[i].set_xlabel('time relative to zone-entry (sec.)')
for j in np.arange(0, NumEvents):
axes[i].plot(RelTimeVec,
AveragedTracesMatrices[SortProcessingDict['SortIndices']\
[Tuning_Frame['HeatMapRowIndex'].loc[CellsToSelectList[i]]], :, j])
# Generate non-z-scored, raw trace averages version
# Reload orignal cell fluorescence data frame
#RestoreFilePath = SavePath +'.dat'
root = tk.Tk()
RestoreFilePath = askopenfilename()
root.withdraw()
# Determine parent directory and filename from complete path.
drive, path_and_file = os.path.splitdrive(RestoreFilePath)
path, file = os.path.split(path_and_file)
exec(open('./RestoreShelvedWorkspaceScript.py').read())
# Re-initialize settings
### Specify a dictionary of parameters for tuning calcluation and plotting.
# Time domain to consider for calculation of tuning index
ParamsDict['SearchDomain'] = [0., 1.]
# Specify the method to be used to calculate tuning method.
#ParamsDict['TuningType'] = 'WeightedDifference'
ParamsDict['TuningType'] = 'DiffOfAvgsOverSumOfMagOfAvgs'
# For the WeightedDifference method, specify the standard deviation of the
# Gaussian weighting function.
ParamsDict['StdDev'] = 0.75
# Specify the number of bins to use to generate the histogram.
ParamsDict['NumHistoBins'] = 10
# Specify the list of quantiles to plot as vertical lines on histogram
ParamsDict['QuantilesList'] = [0.25, 0.75]
# The magnitude of the tuning index value that separates tuned cells from
# non-tuned cells.
ParamsDict['TuningCutoffLevel'] = 0.50
# Name of the color scheme used for plotting heat map.
ColorMap = 'seismic'
RefEventsList = RefEventsDict['RefEventsList']
SortingRefEvent = RefEventsList[1]
nEvents = len(RefEventsList)
# Acquire number of columns in fluorescence trace dataframe
nCols = CellFluorTraces_Frame.shape[1]
# BYPASS zScoring the calcium traces prior to peri-event extraction
# Z-scoring and replacing the z-scored traces in the array takes place here.
# Recompile PeriEvent activity dict to include Full Domain in boundary window.
PeriEventExtractorDict = PeriEventExtractor_Trace(BehavDict,
CellFluorTraces_Frame,
RefEventsDict,
ParamsDict['BoundaryWindow'])
# Count the number of trials and determine length of each row in the formatted
# Peri-event activity array.
NumTrials, NumCellsByNumSamples = PeriEventExtractorDict['PEA_Array'].shape
# Count the total number of columns in the fluorescence trace dataframe
(_, NumColumns) = CellFluorTraces_Frame.shape
#
NumCells = NumColumns - 1
NumSamples = int(NumCellsByNumSamples/NumCells)
RelTimeVec = np.linspace(ParamsDict['BoundaryWindow'][0],
ParamsDict['BoundaryWindow'][1],
num=NumSamples, endpoint=False)
NumEvents = len(RefEventsList)
AveragedTracesMatrices = np.empty((NumCells, NumSamples, NumEvents))
i = 0
for RefEvent in RefEventsList:
TracesFilt = PeriEventExtractorDict['TrialIndicesByEventDict'][RefEvent]
AveragedTraces = np.mean(PeriEventExtractorDict['PEA_Array'][TracesFilt,:],
axis=0)
AveragedTracesMatrices[:,:,i] = np.reshape(AveragedTraces, (NumCells, NumSamples))
i += 1
fig, axes = plt.subplots(1, NumCellsToSelect)
fig.suptitle('Averaged (raw) $\Delta$F trace averages from cells')
for i in np.arange(0, NumCellsToSelect):
axes[i].set_title(str(CellsToSelectList[i]))
if i == 0:
axes[i].set_ylabel('Average $\Delta$F')
axes[i].set_xlabel('time relative to zone-entry (sec.)')
for j in np.arange(0, NumEvents):
axes[i].plot(RelTimeVec,
AveragedTracesMatrices[SortProcessingDict['SortIndices']\
[Tuning_Frame['HeatMapRowIndex'].loc[CellsToSelectList[i]]], :, j])