11import numpy as np
22import scipy .ndimage as ndimage
33import scipy .ndimage .filters as filters
4+ from scipy .interpolate import interp2d , interp1d
45from .tools import fftcorrelate2d , autocorrelation
56
67def border_score (rate_map , fields ):
@@ -118,9 +119,7 @@ def separate_fields_by_laplace(rate_map, threshold=0, minimum_field_area=None):
118119
119120 # Labels areas of the laplacian not connected by values > 0.
120121 fields , field_count = ndimage .label (l )
121- print (field_count )
122122 fields = sort_fields_by_rate (rate_map , fields )
123- print (np .unique (fields .ravel ()))
124123 if minimum_field_area is not None :
125124 fields = remove_fields_by_area (fields , minimum_field_area )
126125 return fields
@@ -217,7 +216,7 @@ def calculate_field_centers(rate_map, labels, center_method='maxima'):
217216 return bc
218217
219218
220- def in_field (x , y , fields , box_size ):
219+ def which_field (x , y , fields , box_size ):
221220 """Returns which spatial field each (x,y)-position is in.
222221
223222 Parameters:
@@ -239,14 +238,16 @@ def in_field(x, y, fields, box_size):
239238 if len (x )!= len (y ):
240239 raise ValueError ('x and y must have same length' )
241240
242- sx ,sy = fields .shape
241+ sx , sy = fields .shape
243242 # bin sizes
244- dx = box_size [0 ]/ sx
245- dy = box_size [1 ]/ sy
246- x_bins = dx + np .arange (0 , box_size [0 ], dx )
247- y_bins = dy + np .arange (0 , box_size [1 ], dy )
248- ix = np .digitize (x , x_bins )
249- iy = np .digitize (y , y_bins )
243+ dx = box_size [0 ]/ sx
244+ dy = box_size [1 ]/ sy
245+ x_bins = dx + np .arange (0 , box_size [0 ] + dx , dx )
246+ y_bins = dy + np .arange (0 , box_size [1 ] + dx , dy )
247+ # x_bins = np.arange(0, box_size[0] + dx, dx)
248+ # y_bins = np.arange(0, box_size[1] + dx, dy)
249+ ix = np .digitize (x , x_bins )
250+ iy = np .digitize (y , y_bins )
250251
251252 # fix for boundaries:
252253 ix [ix == sx ] = sx - 1
@@ -283,7 +284,6 @@ def distance_to_edge_function(x_c, y_c, field, box_size, interpolation='linear')
283284 """
284285
285286 from skimage import measure
286- from scipy import interpolate
287287 contours = measure .find_contours (field , 0.8 )
288288
289289 box_dim = np .array (box_size )
@@ -309,8 +309,8 @@ def distance_to_edge_function(x_c, y_c, field, box_size, interpolation='linear')
309309 pad_x = np .delete (pad_x , mask )
310310 pad_y = np .delete (pad_y , mask )
311311
312- x_func = interpolate . interp1d (pad_a , pad_x , kind = interpolation )
313- y_func = interpolate . interp1d (pad_a , pad_y , kind = interpolation )
312+ x_func = interp1d (pad_a , pad_x , kind = interpolation )
313+ y_func = interp1d (pad_a , pad_y , kind = interpolation )
314314
315315 def dist_func (angle ):
316316 x = x_func (angle )
0 commit comments