<s> """<STR_LIT>""" <EOL> from pytest import yield_fixture , fixture <EOL> import numpy as np <EOL> from numpy . testing import assert_array_equal as ae <EOL> from vispy . util import keys <EOL> from . . import gui_component <EOL> from . . gui_component import ( ManualClustering , <EOL> ) <EOL> from phy . io . array import _spikes_in_clusters <EOL> from phy . gui import GUI <EOL> from . conftest import MockController <EOL> @ yield_fixture <EOL> def gui ( tempdir , qtbot ) : <EOL> gui_component . _show_box = lambda _ : _ <EOL> gui = GUI ( position = ( <NUM_LIT:200> , <NUM_LIT:100> ) , size = ( <NUM_LIT> , <NUM_LIT> ) , config_dir = tempdir ) <EOL> gui . show ( ) <EOL> qtbot . waitForWindowShown ( gui ) <EOL> yield gui <EOL> qtbot . wait ( <NUM_LIT:5> ) <EOL> gui . close ( ) <EOL> del gui <EOL> qtbot . wait ( <NUM_LIT:5> ) <EOL> @ fixture <EOL> def manual_clustering ( qtbot , gui , cluster_ids , cluster_groups , <EOL> quality , similarity ) : <EOL> spike_clusters = np . array ( cluster_ids ) <EOL> spikes_per_cluster = lambda c : [ c ] <EOL> mc = ManualClustering ( spike_clusters , <EOL> spikes_per_cluster , <EOL> cluster_groups = cluster_groups , <EOL> shortcuts = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> quality = quality , <EOL> similarity = similarity , <EOL> ) <EOL> mc . attach ( gui ) <EOL> mc . set_default_sort ( quality . __name__ ) <EOL> return mc <EOL> def test_manual_clustering_edge_cases ( manual_clustering ) : <EOL> mc = manual_clustering <EOL> ae ( mc . clustering . cluster_ids , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:20> , <NUM_LIT:30> ] ) <EOL> mc . select ( [ <NUM_LIT:0> ] ) <EOL> assert mc . selected == [ <NUM_LIT:0> ] <EOL> mc . undo ( ) <EOL> mc . redo ( ) <EOL> mc . merge ( ) <EOL> assert mc . selected == [ <NUM_LIT:0> ] <EOL> mc . merge ( [ ] ) <EOL> assert mc . selected == [ <NUM_LIT:0> ] <EOL> mc . merge ( [ <NUM_LIT:10> ] ) <EOL> assert mc . selected == [ <NUM_LIT:0> ] <EOL> mc . split ( [ ] ) <EOL> assert mc . selected == [ <NUM_LIT:0> ] <EOL> mc . move ( [ ] , '<STR_LIT>' ) <EOL> mc . save ( ) <EOL> def test_manual_clustering_skip ( qtbot , gui , manual_clustering ) : <EOL> mc = manual_clustering <EOL> expected = [ <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:11> , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> for clu in expected : <EOL> mc . cluster_view . next ( ) <EOL> assert mc . selected == [ clu ] <EOL> def test_manual_clustering_merge ( manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . cluster_view . select ( [ <NUM_LIT:30> ] ) <EOL> mc . similarity_view . select ( [ <NUM_LIT:20> ] ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:20> ] <EOL> mc . merge ( ) <EOL> assert mc . selected == [ <NUM_LIT> , <NUM_LIT:11> ] <EOL> mc . undo ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:20> ] <EOL> mc . redo ( ) <EOL> assert mc . selected == [ <NUM_LIT> , <NUM_LIT:11> ] <EOL> def test_manual_clustering_split ( manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . select ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> mc . split ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> assert mc . selected == [ <NUM_LIT> ] <EOL> mc . undo ( ) <EOL> assert mc . selected == [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> mc . redo ( ) <EOL> assert mc . selected == [ <NUM_LIT> ] <EOL> def test_manual_clustering_split_2 ( gui , quality , similarity ) : <EOL> spike_clusters = np . array ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> mc = ManualClustering ( spike_clusters , <EOL> lambda c : _spikes_in_clusters ( spike_clusters , [ c ] ) , <EOL> similarity = similarity , <EOL> ) <EOL> mc . attach ( gui ) <EOL> mc . add_column ( quality , name = '<STR_LIT>' , default = True ) <EOL> mc . set_default_sort ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mc . split ( [ <NUM_LIT:0> ] ) <EOL> assert mc . selected == [ <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> def test_manual_clustering_state ( tempdir , qtbot , gui , manual_clustering ) : <EOL> mc = manual_clustering <EOL> cv = mc . cluster_view <EOL> cv . sort_by ( '<STR_LIT:id>' ) <EOL> gui . close ( ) <EOL> assert cv . state [ '<STR_LIT>' ] == ( '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> cv . set_state ( cv . state ) <EOL> assert cv . state [ '<STR_LIT>' ] == ( '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> def test_manual_clustering_split_lasso ( tempdir , qtbot ) : <EOL> controller = MockController ( config_dir = tempdir ) <EOL> gui = controller . create_gui ( ) <EOL> mc = controller . manual_clustering <EOL> view = gui . list_views ( '<STR_LIT>' , is_visible = False ) [ <NUM_LIT:0> ] <EOL> gui . show ( ) <EOL> mc . select ( <NUM_LIT:0> ) <EOL> ev = view . events <EOL> ev . mouse_press ( pos = ( <NUM_LIT> , <NUM_LIT:1> ) , button = <NUM_LIT:1> , modifiers = ( keys . CONTROL , ) ) <EOL> ev . mouse_press ( pos = ( <NUM_LIT> , <NUM_LIT:1> ) , button = <NUM_LIT:1> , modifiers = ( keys . CONTROL , ) ) <EOL> ev . mouse_press ( pos = ( <NUM_LIT> , <NUM_LIT:30> ) , button = <NUM_LIT:1> , modifiers = ( keys . CONTROL , ) ) <EOL> ev . mouse_press ( pos = ( <NUM_LIT> , <NUM_LIT:30> ) , button = <NUM_LIT:1> , modifiers = ( keys . CONTROL , ) ) <EOL> ups = [ ] <EOL> @ mc . clustering . connect <EOL> def on_cluster ( up ) : <EOL> ups . append ( up ) <EOL> mc . split ( ) <EOL> up = ups [ <NUM_LIT:0> ] <EOL> assert up . description == '<STR_LIT>' <EOL> assert up . added == [ <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> assert up . deleted == [ <NUM_LIT:0> ] <EOL> gui . close ( ) <EOL> def test_manual_clustering_move_1 ( manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . select ( [ <NUM_LIT:20> ] ) <EOL> assert mc . selected == [ <NUM_LIT:20> ] <EOL> mc . move ( [ <NUM_LIT:20> ] , '<STR_LIT>' ) <EOL> assert mc . selected == [ <NUM_LIT:11> ] <EOL> mc . undo ( ) <EOL> assert mc . selected == [ <NUM_LIT:20> ] <EOL> mc . redo ( ) <EOL> assert mc . selected == [ <NUM_LIT:11> ] <EOL> def test_manual_clustering_move_2 ( manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . select ( [ <NUM_LIT:20> ] ) <EOL> mc . similarity_view . select ( [ <NUM_LIT:10> ] ) <EOL> assert mc . selected == [ <NUM_LIT:20> , <NUM_LIT:10> ] <EOL> mc . move ( [ <NUM_LIT:10> ] , '<STR_LIT>' ) <EOL> assert mc . selected == [ <NUM_LIT:20> , <NUM_LIT:2> ] <EOL> mc . undo ( ) <EOL> assert mc . selected == [ <NUM_LIT:20> , <NUM_LIT:10> ] <EOL> mc . redo ( ) <EOL> assert mc . selected == [ <NUM_LIT:20> , <NUM_LIT:2> ] <EOL> def test_manual_clustering_action_reset ( qtbot , manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . actions . select ( [ <NUM_LIT:10> , <NUM_LIT:11> ] ) <EOL> mc . actions . reset ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> ] <EOL> mc . actions . next ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:20> ] <EOL> mc . actions . next ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:11> ] <EOL> mc . actions . previous ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:20> ] <EOL> def test_manual_clustering_action_nav ( qtbot , manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . actions . reset ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> ] <EOL> mc . actions . next_best ( ) <EOL> assert mc . selected == [ <NUM_LIT:20> ] <EOL> mc . actions . previous_best ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> ] <EOL> def test_manual_clustering_action_move_1 ( qtbot , manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . actions . next ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> ] <EOL> mc . actions . move_best_to_noise ( ) <EOL> assert mc . selected == [ <NUM_LIT:20> ] <EOL> mc . actions . move_best_to_mua ( ) <EOL> assert mc . selected == [ <NUM_LIT:11> ] <EOL> mc . actions . move_best_to_good ( ) <EOL> assert mc . selected == [ <NUM_LIT:2> ] <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:30> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:20> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:11> ) == '<STR_LIT>' <EOL> def test_manual_clustering_action_move_2 ( manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . select ( [ <NUM_LIT:30> ] ) <EOL> mc . similarity_view . select ( [ <NUM_LIT:20> ] ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:20> ] <EOL> mc . actions . move_similar_to_noise ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:11> ] <EOL> mc . actions . move_similar_to_mua ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:2> ] <EOL> mc . actions . move_similar_to_good ( ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:1> ] <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:20> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:11> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:2> ) == '<STR_LIT>' <EOL> def test_manual_clustering_action_move_3 ( manual_clustering ) : <EOL> mc = manual_clustering <EOL> mc . select ( [ <NUM_LIT:30> ] ) <EOL> mc . similarity_view . select ( [ <NUM_LIT:20> ] ) <EOL> assert mc . selected == [ <NUM_LIT:30> , <NUM_LIT:20> ] <EOL> mc . actions . move_all_to_noise ( ) <EOL> assert mc . selected == [ <NUM_LIT:11> , <NUM_LIT:2> ] <EOL> mc . actions . move_all_to_mua ( ) <EOL> assert mc . selected == [ <NUM_LIT:1> ] <EOL> mc . actions . move_all_to_good ( ) <EOL> assert mc . selected == [ <NUM_LIT:1> ] <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:30> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:20> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:11> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:10> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:2> ) == '<STR_LIT>' <EOL> mc . cluster_meta . get ( '<STR_LIT>' , <NUM_LIT:1> ) == '<STR_LIT>' </s>
