99
1010
1111def activate (
12- schema_name : str ,
13- * ,
12+ schema_name : str ,
13+ * ,
1414 create_schema : bool = True ,
15- create_tables : bool = True ,
15+ create_tables : bool = True ,
1616):
17- """Activates the `probe` schemas.
17+ """Activates the `probe` schemas.
1818
1919 Args:
2020 schema_name (str): A string containing the name of the probe scehma.
2121 create_schema (bool): If True, schema will be created in the database.
2222 create_tables (bool): If True, tables related to the schema will be created in the database.
23-
23+
2424 Dependencies:
2525 Upstream tables:
2626 Session: A parent table to ProbeInsertion.
27-
27+
2828 Functions:
2929 """
30- schema .activate (schema_name , create_schema = create_schema , create_tables = create_tables )
30+ schema .activate (
31+ schema_name , create_schema = create_schema , create_tables = create_tables
32+ )
3133
3234 # Add neuropixels probes
3335 for probe_type in (
@@ -47,6 +49,7 @@ class ProbeType(dj.Lookup):
4749 Attributes:
4850 probe_type (foreign key, varchar (32) ): Name of the probe type.
4951 """
52+
5053 definition = """
5154 # Type of probe, with specific electrodes geometry defined
5255 probe_type: varchar(32) # e.g. neuropixels_1.0
@@ -64,16 +67,16 @@ class Electrode(dj.Part):
6467 x_coord (float): x-coordinate of the electrode within the probe in micrometers.
6568 y_coord (float): y-coordinate of the electrode within the probe in micrometers.
6669 """
67-
70+
6871 definition = """
6972 -> master
7073 electrode: int # electrode index, starts at 0
7174 ---
7275 shank: int # shank index, starts at 0, advance left to right
7376 shank_col: int # column index, starts at 0, advance left to right
7477 shank_row: int # row index, starts at 0, advance tip to tail
75- x_coord=NULL: float # (um ) x coordinate of the electrode within the probe, (0, 0) is the bottom left corner of the probe
76- y_coord=NULL: float # (um ) y coordinate of the electrode within the probe, (0, 0) is the bottom left corner of the probe
78+ x_coord=NULL: float # (μm ) x coordinate of the electrode within the probe, (0, 0) is the bottom left corner of the probe
79+ y_coord=NULL: float # (μm ) y coordinate of the electrode within the probe, (0, 0) is the bottom left corner of the probe
7780 """
7881
7982 @staticmethod
@@ -139,62 +142,7 @@ def create_neuropixels_probe(probe_type: str = "neuropixels 1.0 - 3A"):
139142 ),
140143 }
141144
142- def build_electrodes (
143- site_count : int ,
144- col_spacing : float ,
145- row_spacing : float ,
146- white_spacing : float ,
147- col_count : int ,
148- shank_count : int ,
149- shank_spacing : float ,
150- ) -> dict :
151- """Builds electrode layouts.
152-
153- Args:
154- site_count (int): site count per shank
155- col_spacing (float): (um) horrizontal spacing between sites
156- row_spacing (float): (um) vertical spacing between columns
157- white_spacing (float): (um) offset spacing
158- col_count (int): number of column per shank
159- shank_count (int): number of shank
160- shank_spacing (float): spacing between shanks
161- """
162- row_count = int (site_count / col_count )
163- x_coords = np .tile (
164- np .arange (0 , col_spacing * col_count , col_spacing ), row_count
165- )
166- y_coords = np .repeat (np .arange (row_count ) * row_spacing , col_count )
167-
168- if white_spacing :
169- x_white_spaces = np .tile (
170- [white_spacing , white_spacing , 0 , 0 ], int (row_count / 2 )
171- )
172- x_coords = x_coords + x_white_spaces
173-
174- shank_cols = np .tile (range (col_count ), row_count )
175- shank_rows = np .repeat (range (row_count ), col_count )
176-
177- npx_electrodes = []
178- for shank_no in range (shank_count ):
179- npx_electrodes .extend (
180- [
181- {
182- "electrode" : (site_count * shank_no ) + e_id ,
183- "shank" : shank_no ,
184- "shank_col" : c_id ,
185- "shank_row" : r_id ,
186- "x_coord" : x + (shank_no * shank_spacing ),
187- "y_coord" : y ,
188- }
189- for e_id , (c_id , r_id , x , y ) in enumerate (
190- zip (shank_cols , shank_rows , x_coords , y_coords )
191- )
192- ]
193- )
194-
195- return npx_electrodes
196-
197- electrodes = build_electrodes (** neuropixels_probes_config [probe_type ])
145+ electrodes = build_electrode_layouts (** neuropixels_probes_config [probe_type ])
198146 probe_type = {"probe_type" : probe_type }
199147 with ProbeType .connection .transaction :
200148 ProbeType .insert1 (probe_type , skip_duplicates = True )
@@ -247,8 +195,65 @@ class Electrode(dj.Part):
247195 ElectrodeConfig (foreign key): ElectrodeConfig primary key.
248196 ProbeType.Electrode (foreign key): ProbeType.Electrode primary key.
249197 """
250-
198+
251199 definition = """ # Electrodes selected for recording
252200 -> master
253201 -> ProbeType.Electrode
254202 """
203+
204+
205+ def build_electrode_layouts (
206+ site_count : int ,
207+ col_spacing : float = 1 ,
208+ row_spacing : float = 1 ,
209+ white_spacing : float = None ,
210+ col_count : int = 1 ,
211+ shank_count : int = 1 ,
212+ shank_spacing : float = 1 ,
213+ y_origin = "bottom" ,
214+ ) -> dict :
215+
216+ """Builds electrode layouts.
217+
218+ Args:
219+ site_count (int): site count per shank
220+ col_spacing (float): (μm) horizontal spacing between sites. Defaults to 1 (single column).
221+ row_spacing (float): (μm) vertical spacing between columns. Defaults to 1 (single row).
222+ white_spacing (float): (μm) offset spacing. Defaults to None.
223+ col_count (int): number of column per shank. Defaults to 1 (single column).
224+ shank_count (int): number of shank. Defaults to 1 (single shank).
225+ shank_spacing (float): spacing between shanks. Defaults to 1 (single shank).
226+ y_origin (str): {"bottom", "top"}. y value decrements if "top". Defaults to "bottom".
227+ """
228+ row_count = int (site_count / col_count )
229+ x_coords = np .tile (np .arange (0 , col_spacing * col_count , col_spacing ), row_count )
230+ y_coords = np .repeat (np .arange (row_count ) * row_spacing , col_count )
231+
232+ if white_spacing :
233+ x_white_spaces = np .tile (
234+ [white_spacing , white_spacing , 0 , 0 ], int (row_count / 2 )
235+ )
236+ x_coords = x_coords + x_white_spaces
237+
238+ shank_cols = np .tile (range (col_count ), row_count )
239+ shank_rows = np .repeat (range (row_count ), col_count )
240+
241+ electrode_layouts = []
242+ for shank_no in range (shank_count ):
243+ electrode_layouts .extend (
244+ [
245+ {
246+ "electrode" : (site_count * shank_no ) + e_id ,
247+ "shank" : shank_no ,
248+ "shank_col" : c_id ,
249+ "shank_row" : r_id ,
250+ "x_coord" : x + (shank_no * shank_spacing ),
251+ "y_coord" : y * {"top" : - 1 , "bottom" : 1 }[y_origin ],
252+ }
253+ for e_id , (c_id , r_id , x , y ) in enumerate (
254+ zip (shank_cols , shank_rows , x_coords , y_coords )
255+ )
256+ ]
257+ )
258+
259+ return electrode_layouts
0 commit comments