<s> """<STR_LIT>""" <EOL> import os . path as op <EOL> from pytest import raises <EOL> import numpy as np <EOL> from numpy . testing import assert_array_equal as ae <EOL> from . . mea import ( _probe_channels , _remap_adjacency , _adjacency_subset , <EOL> _probe_positions , _probe_adjacency_list , <EOL> MEA , linear_positions , staggered_positions , <EOL> load_probe , list_probes <EOL> ) <EOL> def test_remap ( ) : <EOL> adjacency = { <NUM_LIT:1> : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:7> ] , <NUM_LIT:3> : [ <NUM_LIT:5> , <NUM_LIT:11> ] } <EOL> mapping = { <NUM_LIT:1> : <NUM_LIT:3> , <NUM_LIT:2> : <NUM_LIT:20> , <NUM_LIT:3> : <NUM_LIT:30> , <NUM_LIT:5> : <NUM_LIT:50> , <NUM_LIT:7> : <NUM_LIT> , <NUM_LIT:11> : <NUM_LIT:1> } <EOL> remapped = _remap_adjacency ( adjacency , mapping ) <EOL> assert sorted ( remapped . keys ( ) ) == [ <NUM_LIT:3> , <NUM_LIT:30> ] <EOL> assert remapped [ <NUM_LIT:3> ] == [ <NUM_LIT:20> , <NUM_LIT:30> , <NUM_LIT> ] <EOL> assert remapped [ <NUM_LIT:30> ] == [ <NUM_LIT:50> , <NUM_LIT:1> ] <EOL> def test_adjacency_subset ( ) : <EOL> adjacency = { <NUM_LIT:1> : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:7> ] , <NUM_LIT:3> : [ <NUM_LIT:5> , <NUM_LIT:11> ] , <NUM_LIT:5> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:11> ] } <EOL> subset = [ <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:32> ] <EOL> adjsub = _adjacency_subset ( adjacency , subset ) <EOL> assert sorted ( adjsub . keys ( ) ) == [ <NUM_LIT:1> , <NUM_LIT:5> ] <EOL> assert adjsub [ <NUM_LIT:1> ] == [ ] <EOL> assert adjsub [ <NUM_LIT:5> ] == [ <NUM_LIT:1> ] <EOL> def test_probe ( ) : <EOL> probe = { '<STR_LIT>' : { <EOL> <NUM_LIT:0> : { '<STR_LIT>' : [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : [ [ <NUM_LIT:0> , <NUM_LIT:3> ] , [ <NUM_LIT:1> , <NUM_LIT:0> ] ] , <EOL> '<STR_LIT>' : { <NUM_LIT:0> : ( <NUM_LIT:10> , <NUM_LIT:10> ) , <NUM_LIT:1> : ( <NUM_LIT:10> , <NUM_LIT:20> ) , <NUM_LIT:3> : ( <NUM_LIT:20> , <NUM_LIT:30> ) } , <EOL> } , <EOL> <NUM_LIT:1> : { '<STR_LIT>' : [ <NUM_LIT:7> ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> } } <EOL> adjacency = { <NUM_LIT:0> : set ( [ <NUM_LIT:1> , <NUM_LIT:3> ] ) , <EOL> <NUM_LIT:1> : set ( [ <NUM_LIT:0> ] ) , <EOL> <NUM_LIT:3> : set ( [ <NUM_LIT:0> ] ) , <EOL> } <EOL> assert _probe_channels ( probe , <NUM_LIT:0> ) == [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:1> ] <EOL> ae ( _probe_positions ( probe , <NUM_LIT:0> ) , [ ( <NUM_LIT:10> , <NUM_LIT:10> ) , ( <NUM_LIT:20> , <NUM_LIT:30> ) , ( <NUM_LIT:10> , <NUM_LIT:20> ) ] ) <EOL> assert _probe_adjacency_list ( probe ) == adjacency <EOL> mea = MEA ( probe = probe ) <EOL> assert mea . adjacency == adjacency <EOL> assert mea . channels_per_group == { <NUM_LIT:0> : [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:1> ] , <NUM_LIT:1> : [ <NUM_LIT:7> ] } <EOL> assert mea . channels == [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:1> ] <EOL> assert mea . n_channels == <NUM_LIT:3> <EOL> ae ( mea . positions , [ ( <NUM_LIT:10> , <NUM_LIT:10> ) , ( <NUM_LIT:20> , <NUM_LIT:30> ) , ( <NUM_LIT:10> , <NUM_LIT:20> ) ] ) <EOL> def test_mea ( ) : <EOL> n_channels = <NUM_LIT:10> <EOL> channels = np . arange ( n_channels ) <EOL> positions = np . random . randn ( n_channels , <NUM_LIT:2> ) <EOL> mea = MEA ( channels , positions = positions ) <EOL> ae ( mea . positions , positions ) <EOL> assert mea . adjacency is None <EOL> mea = MEA ( channels , positions = positions ) <EOL> assert mea . n_channels == n_channels <EOL> mea = MEA ( channels , positions = positions ) <EOL> assert mea . n_channels == n_channels <EOL> with raises ( ValueError ) : <EOL> MEA ( channels = np . arange ( n_channels + <NUM_LIT:1> ) , positions = positions ) <EOL> with raises ( ValueError ) : <EOL> MEA ( channels = channels , positions = positions [ : - <NUM_LIT:1> , : ] ) <EOL> def test_positions ( ) : <EOL> probe = staggered_positions ( <NUM_LIT> ) <EOL> assert probe . shape == ( <NUM_LIT> , <NUM_LIT:2> ) <EOL> ae ( probe [ - <NUM_LIT:1> ] , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> probe = linear_positions ( <NUM_LIT> ) <EOL> assert probe . shape == ( <NUM_LIT> , <NUM_LIT:2> ) <EOL> def test_library ( tempdir ) : <EOL> assert '<STR_LIT>' in list_probes ( ) <EOL> probe = load_probe ( '<STR_LIT>' ) <EOL> assert probe <EOL> assert probe . channels == list ( range ( <NUM_LIT:32> ) ) <EOL> path = op . join ( tempdir , '<STR_LIT>' ) <EOL> with raises ( IOError ) : <EOL> load_probe ( path ) <EOL> with open ( path , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' ) <EOL> with raises ( KeyError ) : <EOL> load_probe ( path ) </s>
