@@ -13,6 +13,7 @@ def interpolate_templates(
1313 source_locations : np .ndarray ,
1414 dest_locations : np .ndarray ,
1515 interpolation_method : Literal ["cubic" , "linear" , "nearest" , "thin_plate" ] = "cubic" ,
16+ interpolation_kwargs : None | dict = None ,
1617):
1718 """
1819 Interpolate templates_array to new positions.
@@ -33,6 +34,9 @@ def interpolate_templates(
3334 shape = (num_channels, 2) or (num_motions, num_channels, 2)
3435 interpolation_method : str, default "cubic"
3536 The interpolation method.
37+ interpolation_kwargs
38+ Kwargs that are passed to RBFInterpolator (if interpolation_method = "thin_plate") or to
39+ griddata (otherwise).
3640
3741 Returns
3842 -------
@@ -41,6 +45,9 @@ def interpolate_templates(
4145 """
4246 from scipy .interpolate import griddata , RBFInterpolator
4347
48+ if interpolation_kwargs is None :
49+ interpolation_kwargs = dict ()
50+
4451 source_locations = np .asarray (source_locations )
4552 dest_locations = np .asarray (dest_locations )
4653
@@ -65,7 +72,15 @@ def interpolate_templates(
6572
6673 if interpolation_method == "thin_plate" :
6774
68- tps_interpolator = RBFInterpolator (source_locations , template , kernel = "thin_plate_spline" , neighbors = 12 )
75+ if "neighbors" not in interpolation_kwargs :
76+ # If neighbors it not passed, `RBFInterpolator` uses all channels.
77+ # This works poorly for standard ephys template interpolation.
78+ # Depending on the probe, you might want to decrease this value.
79+ interpolation_kwargs ["neighbors" ] = 12
80+
81+ tps_interpolator = RBFInterpolator (
82+ source_locations , template , kernel = "thin_plate_spline" , ** interpolation_kwargs
83+ )
6984 if dest_locations_dims == 2 :
7085 interp_template = tps_interpolator (dest_locations )
7186 elif dest_locations_dims == 3 :
@@ -75,7 +90,12 @@ def interpolate_templates(
7590
7691 else :
7792 interp_template = griddata (
78- source_locations , template , dest_locations , method = interpolation_method , fill_value = 0
93+ source_locations ,
94+ template ,
95+ dest_locations ,
96+ method = interpolation_method ,
97+ fill_value = 0 ,
98+ ** interpolation_kwargs ,
7999 )
80100
81101 if dest_locations_dims == 2 :
0 commit comments