@@ -1299,3 +1299,176 @@ def dlc_key(sgp, dlc_selection):
12991299def populate_dlc (sgp , dlc_key ):
13001300 sgp .v1 .DLCPosV1 ().populate (dlc_key )
13011301 yield
1302+
1303+
1304+ # ----------------------- FIXTURES, SPIKESORTING TABLES -----------------------
1305+ # ------------------------ Note: Used in decoding tests ------------------------
1306+
1307+
1308+ @pytest .fixture (scope = "session" )
1309+ def spike_v1 (common ):
1310+ from spyglass .spikesorting import v1
1311+
1312+ yield v1
1313+
1314+
1315+ @pytest .fixture (scope = "session" )
1316+ def pop_rec (spike_v1 , mini_dict , team_name ):
1317+ spike_v1 .SortGroup .set_group_by_shank (** mini_dict )
1318+ key = {
1319+ ** mini_dict ,
1320+ "sort_group_id" : 0 ,
1321+ "preproc_param_name" : "default" ,
1322+ "interval_list_name" : "01_s1" ,
1323+ "team_name" : team_name ,
1324+ }
1325+ spike_v1 .SpikeSortingRecordingSelection .insert_selection (key )
1326+ ssr_pk = (
1327+ (spike_v1 .SpikeSortingRecordingSelection & key ).proj ().fetch1 ("KEY" )
1328+ )
1329+ spike_v1 .SpikeSortingRecording .populate (ssr_pk )
1330+
1331+ yield ssr_pk
1332+
1333+
1334+ @pytest .fixture (scope = "session" )
1335+ def pop_art (spike_v1 , mini_dict , pop_rec ):
1336+ key = {
1337+ "recording_id" : pop_rec ["recording_id" ],
1338+ "artifact_param_name" : "default" ,
1339+ }
1340+ spike_v1 .ArtifactDetectionSelection .insert_selection (key )
1341+ spike_v1 .ArtifactDetection .populate ()
1342+
1343+ yield spike_v1 .ArtifactDetection ().fetch ("KEY" , as_dict = True )[0 ]
1344+
1345+
1346+ @pytest .fixture (scope = "session" )
1347+ def spike_merge (spike_v1 ):
1348+ from spyglass .spikesorting .spikesorting_merge import SpikeSortingOutput
1349+
1350+ yield SpikeSortingOutput ()
1351+
1352+
1353+ @pytest .fixture (scope = "session" )
1354+ def sorter_dict ():
1355+ return {"sorter" : "mountainsort4" }
1356+
1357+
1358+ @pytest .fixture (scope = "session" )
1359+ def pop_sort (spike_v1 , pop_rec , pop_art , mini_dict , sorter_dict ):
1360+ key = {
1361+ ** mini_dict ,
1362+ ** sorter_dict ,
1363+ "recording_id" : pop_rec ["recording_id" ],
1364+ "interval_list_name" : str (pop_art ["artifact_id" ]),
1365+ "sorter_param_name" : "franklab_tetrode_hippocampus_30KHz" ,
1366+ }
1367+ spike_v1 .SpikeSortingSelection .insert_selection (key )
1368+ spike_v1 .SpikeSorting .populate ()
1369+
1370+ yield spike_v1 .SpikeSorting ().fetch ("KEY" , as_dict = True )[0 ]
1371+
1372+
1373+ @pytest .fixture (scope = "session" )
1374+ def sorting_objs (spike_v1 , pop_sort ):
1375+ sort_nwb = (spike_v1 .SpikeSorting & pop_sort ).fetch_nwb ()
1376+ sort_si = spike_v1 .SpikeSorting .get_sorting (pop_sort )
1377+ yield sort_nwb , sort_si
1378+
1379+
1380+ @pytest .fixture (scope = "session" )
1381+ def pop_curation (spike_v1 , pop_sort ):
1382+ spike_v1 .CurationV1 .insert_curation (
1383+ sorting_id = pop_sort ["sorting_id" ],
1384+ description = "testing sort" ,
1385+ )
1386+
1387+ yield (spike_v1 .CurationV1 () & {"parent_curation_id" : - 1 }).fetch (
1388+ "KEY" , as_dict = True
1389+ )[0 ]
1390+
1391+
1392+ @pytest .fixture (scope = "session" )
1393+ def pop_metric (spike_v1 , pop_sort , pop_curation ):
1394+ _ = pop_curation # make sure this happens first
1395+ key = {
1396+ "sorting_id" : pop_sort ["sorting_id" ],
1397+ "curation_id" : 0 ,
1398+ "waveform_param_name" : "default_not_whitened" ,
1399+ "metric_param_name" : "franklab_default" ,
1400+ "metric_curation_param_name" : "default" ,
1401+ }
1402+
1403+ spike_v1 .MetricCurationSelection .insert_selection (key )
1404+ spike_v1 .MetricCuration .populate (key )
1405+
1406+ yield spike_v1 .MetricCuration ().fetch ("KEY" , as_dict = True )[0 ]
1407+
1408+
1409+ @pytest .fixture (scope = "session" )
1410+ def metric_objs (spike_v1 , pop_metric ):
1411+ key = {"metric_curation_id" : pop_metric ["metric_curation_id" ]}
1412+ labels = spike_v1 .MetricCuration .get_labels (key )
1413+ merge_groups = spike_v1 .MetricCuration .get_merge_groups (key )
1414+ metrics = spike_v1 .MetricCuration .get_metrics (key )
1415+ yield labels , merge_groups , metrics
1416+
1417+
1418+ @pytest .fixture (scope = "session" )
1419+ def pop_curation_metric (spike_v1 , pop_metric , metric_objs ):
1420+ labels , merge_groups , metrics = metric_objs
1421+ parent_dict = {"parent_curation_id" : 0 }
1422+ spike_v1 .CurationV1 .insert_curation (
1423+ sorting_id = (
1424+ spike_v1 .MetricCurationSelection
1425+ & {"metric_curation_id" : pop_metric ["metric_curation_id" ]}
1426+ ).fetch1 ("sorting_id" ),
1427+ ** parent_dict ,
1428+ labels = labels ,
1429+ merge_groups = merge_groups ,
1430+ metrics = metrics ,
1431+ description = "after metric curation" ,
1432+ )
1433+
1434+ yield (spike_v1 .CurationV1 & parent_dict ).fetch ("KEY" , as_dict = True )[0 ]
1435+
1436+
1437+ @pytest .fixture (scope = "session" )
1438+ def pop_spike_merge (
1439+ spike_v1 , pop_curation_metric , spike_merge , mini_dict , sorter_dict
1440+ ):
1441+ # TODO: add figurl fixtures when kachery_cloud is initialized
1442+
1443+ spike_merge .insert ([pop_curation_metric ], part_name = "CurationV1" )
1444+
1445+ yield (spike_merge << pop_curation_metric ).fetch1 ("KEY" )
1446+
1447+
1448+ @pytest .fixture (scope = "session" )
1449+ def spike_v1_group ():
1450+ from spyglass .spikesorting .analysis .v1 import group
1451+
1452+ yield group
1453+
1454+
1455+ @pytest .fixture (scope = "session" )
1456+ def group_name ():
1457+ yield "test_group"
1458+
1459+
1460+ @pytest .fixture (scope = "session" )
1461+ def pop_spikes_group (
1462+ group_name , spike_v1_group , spike_merge , mini_dict , pop_spike_merge
1463+ ):
1464+
1465+ _ = pop_spike_merge # make sure this happens first
1466+
1467+ spike_v1_group .UnitSelectionParams ().insert_default ()
1468+ spike_v1_group .SortedSpikesGroup ().create_group (
1469+ ** mini_dict ,
1470+ group_name = group_name ,
1471+ keys = spike_merge .proj (spikesorting_merge_id = "merge_id" ).fetch ("KEY" ),
1472+ unit_filter_params_name = "default_exclusion" ,
1473+ )
1474+ yield spike_v1_group .SortedSpikesGroup ().fetch ("KEY" , as_dict = True )[0 ]
0 commit comments