11# PLOTTING CSD
22
3- from netpyne import __gui__
4- if __gui__ :
5- import matplotlib
6- from matplotlib import pyplot as plt
7-
83from ..analysis .utils import exception , _showFigure
94import numpy as np
105import scipy
11-
6+ import matplotlib
7+ from matplotlib import pyplot as plt
8+
9+ def getPaddedCSD (CSDData , pad ):
10+ # pad the first/last row of CSDData by replication (to avoid edge artifacts when drawing colors plots)
11+ npcsd = []
12+ for i in range (pad ): npcsd .append (CSDData [0 ,:])
13+ for i in range (CSDData .shape [0 ]): npcsd .append (CSDData [i ,:])
14+ for i in range (pad ): npcsd .append (CSDData [- 1 ,:])
15+ npcsd = np .array (npcsd )
16+ return npcsd
1217
1318@exception
1419def plotCSD (
@@ -31,6 +36,7 @@ def plotCSD(
3136 showFig = False ,
3237 smooth = True ,
3338 colorbar = True ,
39+ pad = 1 ,
3440 ** kwargs
3541):
3642 """
@@ -113,9 +119,13 @@ def plotCSD(
113119 **Default:** ``True``
114120
115121 colorbar : bool
116- Whetehr or not to plot the colorbar
122+ Whether or not to plot the colorbar
117123 **Default:** ``True``
118124
125+ pad : int
126+ Amount to pad CSDData on top/bottom for more accurate interpolation at edges
127+ **Default:** ``1``
128+
119129 """
120130
121131 # If there is no input data, get the data from the NetPyNE sim object
@@ -137,6 +147,9 @@ def plotCSD(
137147 else :
138148 pass # TODO: ensure time slicing works properly in case CSDData is passed as an argument
139149
150+ npcsd = CSDData
151+ if pad > 0 : npcsd = getPaddedCSD (CSDData , pad ) # apply padding (replicate first,last rows)
152+
140153 if timeRange is None :
141154 timeRange = [0 , sim .cfg .duration ]
142155
@@ -145,20 +158,21 @@ def plotCSD(
145158
146159 # PLOTTING
147160 X = np .arange (timeRange [0 ], timeRange [1 ], dt ) # X == tt
148- Y = np .arange (CSDData .shape [0 ])
161+ Y = np .arange (npcsd .shape [0 ])
149162
150163 # interpolation
151- CSD_spline = scipy .interpolate .RectBivariateSpline (Y , X , CSDData )
152- Y_plot = np .linspace (0 , CSDData .shape [0 ], num = 1000 )
153- Z = CSD_spline (Y_plot , X )
164+ fctr = int (1000 / CSDData .shape [0 ])
165+ CSD_spline = scipy .interpolate .RectBivariateSpline (Y , X , npcsd )
166+ Y_plot = np .linspace (- pad , npcsd .shape [0 ] + pad , num = int (1000 * npcsd .shape [0 ]/ CSDData .shape [0 ]))
167+ Z = CSD_spline (Y_plot , X )[pad * fctr :pad * fctr + 1000 ,:]
154168
155169 # plotting options
156170 plt .rcParams .update ({'font.size' : fontSize })
157171 xmin = int (X [0 ])
158172 xmax = int (X [- 1 ]) + 1
159173 ymin = 0
160174 if ymax is None :
161- ymax = sim .cfg .recordLFP [- 1 ][1 ] + spacing_um
175+ ymax = sim .cfg .recordLFP [- 1 ][1 ] + spacing_um + pad
162176 extent_xy = [xmin , xmax , ymax , ymin ]
163177
164178 # set up figure
@@ -229,7 +243,7 @@ def plotCSD(
229243 subaxs [chan ].margins (0.0 , 0.01 )
230244 subaxs [chan ].get_xaxis ().set_visible (False )
231245 subaxs [chan ].get_yaxis ().set_visible (False )
232- subaxs [chan ].plot (X , CSDData [ chan , :], color = 'green' , linewidth = 0.3 , label = 'CSD time series' )
246+ subaxs [chan ].plot (X , npcsd [ pad + chan , :], color = 'green' , linewidth = 0.3 , label = 'CSD time series' )
233247 if legendLabel :
234248 subaxs [chan ].legend (loc = 'upper right' , fontsize = fontSize )
235249 legendLabel = False
0 commit comments