idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
240,600 | def _extend_spikes ( spike_ids , spike_clusters ) : old_spike_clusters = spike_clusters [ spike_ids ] unique_clusters = _unique ( old_spike_clusters ) changed_spike_ids = _spikes_in_clusters ( spike_clusters , unique_clusters ) extended_spike_ids = np . setdiff1d ( changed_spike_ids , spike_ids , assume_unique = True )... | Return all spikes belonging to the clusters containing the specified spikes . |
240,601 | def reset ( self ) : self . _undo_stack . clear ( ) self . _spike_clusters = self . _spike_clusters_base self . _new_cluster_id = self . _new_cluster_id_0 | Reset the clustering to the original clustering . |
240,602 | def _do_assign ( self , spike_ids , new_spike_clusters ) : spike_ids = _as_array ( spike_ids ) if len ( new_spike_clusters ) == 1 and len ( spike_ids ) > 1 : new_spike_clusters = ( np . ones ( len ( spike_ids ) , dtype = np . int64 ) * new_spike_clusters [ 0 ] ) old_spike_clusters = self . _spike_clusters [ spike_ids ]... | Make spike - cluster assignments after the spike selection has been extended to full clusters . |
240,603 | def merge ( self , cluster_ids , to = None ) : if not _is_array_like ( cluster_ids ) : raise ValueError ( "The first argument should be a list or " "an array." ) cluster_ids = sorted ( cluster_ids ) if not set ( cluster_ids ) <= set ( self . cluster_ids ) : raise ValueError ( "Some clusters do not exist." ) if to is No... | Merge several clusters to a new cluster . |
240,604 | def assign ( self , spike_ids , spike_clusters_rel = 0 ) : assert not isinstance ( spike_ids , slice ) if not hasattr ( spike_clusters_rel , '__len__' ) : spike_clusters_rel = spike_clusters_rel * np . ones ( len ( spike_ids ) , dtype = np . int64 ) spike_ids = _as_array ( spike_ids ) if len ( spike_ids ) == 0 : return... | Make new spike cluster assignments . |
240,605 | def undo ( self ) : _ , _ , undo_state = self . _undo_stack . back ( ) spike_clusters_new = self . _spike_clusters_base . copy ( ) for spike_ids , cluster_ids , _ in self . _undo_stack : if spike_ids is not None : spike_clusters_new [ spike_ids ] = cluster_ids changed = np . nonzero ( self . _spike_clusters != spike_cl... | Undo the last cluster assignment operation . |
240,606 | def redo ( self ) : item = self . _undo_stack . forward ( ) if item is None : return spike_ids , cluster_ids , undo_state = item assert spike_ids is not None up = self . _do_assign ( spike_ids , cluster_ids ) up . history = 'redo' self . emit ( 'cluster' , up ) return up | Redo the last cluster assignment operation . |
240,607 | def _increment ( arr , indices ) : arr = _as_array ( arr ) indices = _as_array ( indices ) bbins = np . bincount ( indices ) arr [ : len ( bbins ) ] += bbins return arr | Increment some indices in a 1D vector of non - negative integers . Repeated indices are taken into account . |
240,608 | def _symmetrize_correlograms ( correlograms ) : n_clusters , _ , n_bins = correlograms . shape assert n_clusters == _ correlograms [ ... , 0 ] = np . maximum ( correlograms [ ... , 0 ] , correlograms [ ... , 0 ] . T ) sym = correlograms [ ... , 1 : ] [ ... , : : - 1 ] sym = np . transpose ( sym , ( 1 , 0 , 2 ) ) return... | Return the symmetrized version of the CCG arrays . |
240,609 | def correlograms ( spike_times , spike_clusters , cluster_ids = None , sample_rate = 1. , bin_size = None , window_size = None , symmetrize = True , ) : assert sample_rate > 0. assert np . all ( np . diff ( spike_times ) >= 0 ) , ( "The spike times must be " "increasing." ) spike_times = np . asarray ( spike_times , dt... | Compute all pairwise cross - correlograms among the clusters appearing in spike_clusters . |
240,610 | def set_bin_window ( self , bin_size = None , window_size = None ) : bin_size = bin_size or self . bin_size window_size = window_size or self . window_size assert 1e-6 < bin_size < 1e3 assert 1e-6 < window_size < 1e3 assert bin_size < window_size self . bin_size = bin_size self . window_size = window_size b , w = self ... | Set the bin and window sizes . |
240,611 | def _md5 ( path , blocksize = 2 ** 20 ) : m = hashlib . md5 ( ) with open ( path , 'rb' ) as f : while True : buf = f . read ( blocksize ) if not buf : break m . update ( buf ) return m . hexdigest ( ) | Compute the checksum of a file . |
240,612 | def download_file ( url , output_path ) : output_path = op . realpath ( output_path ) assert output_path is not None if op . exists ( output_path ) : checked = _check_md5_of_url ( output_path , url ) if checked is False : logger . debug ( "The file `%s` already exists " "but is invalid: redownloading." , output_path ) ... | Download a binary file from an URL . |
240,613 | def _make_class ( cls , ** kwargs ) : kwargs = { k : ( v if v is not None else getattr ( cls , k , None ) ) for k , v in kwargs . items ( ) } name = cls . __name__ + '_' + _hash ( kwargs ) if name not in _CLASSES : logger . log ( 5 , "Create class %s %s." , name , kwargs ) cls = type ( name , ( cls , ) , kwargs ) _CLAS... | Return a custom Visual class with given parameters . |
240,614 | def _add_item ( self , cls , * args , ** kwargs ) : box_index = kwargs . pop ( 'box_index' , self . _default_box_index ) data = cls . validate ( * args , ** kwargs ) n = cls . vertex_count ( ** data ) if not isinstance ( box_index , np . ndarray ) : k = len ( self . _default_box_index ) box_index = _get_array ( box_ind... | Add a plot item . |
240,615 | def scatter ( self , * args , ** kwargs ) : cls = _make_class ( ScatterVisual , _default_marker = kwargs . pop ( 'marker' , None ) , ) return self . _add_item ( cls , * args , ** kwargs ) | Add a scatter plot . |
240,616 | def build ( self ) : for cls , data_list in self . _items . items ( ) : data = _accumulate ( data_list , cls . allow_list ) box_index = data . pop ( 'box_index' ) visual = cls ( ) self . add_visual ( visual ) visual . set_data ( ** data ) if 'a_box_index' in visual . program . _code_variables : visual . program [ 'a_bo... | Build all added items . |
240,617 | def _range_from_slice ( myslice , start = None , stop = None , step = None , length = None ) : assert isinstance ( myslice , slice ) step = myslice . step if myslice . step is not None else step if step is None : step = 1 start = myslice . start if myslice . start is not None else start if start is None : start = 0 sto... | Convert a slice to an array of integers . |
240,618 | def _index_of ( arr , lookup ) : lookup = np . asarray ( lookup , dtype = np . int32 ) m = ( lookup . max ( ) if len ( lookup ) else 0 ) + 1 tmp = np . zeros ( m + 1 , dtype = np . int ) tmp [ - 1 ] = - 1 if len ( lookup ) : tmp [ lookup ] = np . arange ( len ( lookup ) ) return tmp [ arr ] | Replace scalars in an array by their indices in a lookup table . |
240,619 | def _pad ( arr , n , dir = 'right' ) : assert dir in ( 'left' , 'right' ) if n < 0 : raise ValueError ( "'n' must be positive: {0}." . format ( n ) ) elif n == 0 : return np . zeros ( ( 0 , ) + arr . shape [ 1 : ] , dtype = arr . dtype ) n_arr = arr . shape [ 0 ] shape = ( n , ) + arr . shape [ 1 : ] if n_arr == n : as... | Pad an array with zeros along the first axis . |
240,620 | def _in_polygon ( points , polygon ) : from matplotlib . path import Path points = _as_array ( points ) polygon = _as_array ( polygon ) assert points . ndim == 2 assert polygon . ndim == 2 if len ( polygon ) : polygon = np . vstack ( ( polygon , polygon [ 0 ] ) ) path = Path ( polygon , closed = True ) return path . co... | Return the points that are inside a polygon . |
240,621 | def read_array ( path , mmap_mode = None ) : file_ext = op . splitext ( path ) [ 1 ] if file_ext == '.npy' : return np . load ( path , mmap_mode = mmap_mode ) raise NotImplementedError ( "The file extension `{}` " . format ( file_ext ) + "is not currently supported." ) | Read a . npy array . |
240,622 | def write_array ( path , arr ) : file_ext = op . splitext ( path ) [ 1 ] if file_ext == '.npy' : return np . save ( path , arr ) raise NotImplementedError ( "The file extension `{}` " . format ( file_ext ) + "is not currently supported." ) | Write an array to a . npy file . |
240,623 | def _concatenate_virtual_arrays ( arrs , cols = None , scaling = None ) : return None if not len ( arrs ) else ConcatenatedArrays ( arrs , cols , scaling = scaling ) | Return a virtual concatenate of several NumPy arrays . |
240,624 | def _excerpt_step ( n_samples , n_excerpts = None , excerpt_size = None ) : assert n_excerpts >= 2 step = max ( ( n_samples - excerpt_size ) // ( n_excerpts - 1 ) , excerpt_size ) return step | Compute the step of an excerpt set as a function of the number of excerpts or their sizes . |
240,625 | def chunk_bounds ( n_samples , chunk_size , overlap = 0 ) : s_start = 0 s_end = chunk_size keep_start = s_start keep_end = s_end - overlap // 2 yield s_start , s_end , keep_start , keep_end while s_end - overlap + chunk_size < n_samples : s_start = s_end - overlap s_end = s_start + chunk_size keep_start = keep_end keep... | Return chunk bounds . |
240,626 | def data_chunk ( data , chunk , with_overlap = False ) : assert isinstance ( chunk , tuple ) if len ( chunk ) == 2 : i , j = chunk elif len ( chunk ) == 4 : if with_overlap : i , j = chunk [ : 2 ] else : i , j = chunk [ 2 : ] else : raise ValueError ( "'chunk' should have 2 or 4 elements, " "not {0:d}" . format ( len (... | Get a data chunk . |
240,627 | def _spikes_in_clusters ( spike_clusters , clusters ) : if len ( spike_clusters ) == 0 or len ( clusters ) == 0 : return np . array ( [ ] , dtype = np . int ) return np . nonzero ( np . in1d ( spike_clusters , clusters ) ) [ 0 ] | Return the ids of all spikes belonging to the specified clusters . |
240,628 | def grouped_mean ( arr , spike_clusters ) : arr = np . asarray ( arr ) spike_clusters = np . asarray ( spike_clusters ) assert arr . ndim == 1 assert arr . shape [ 0 ] == len ( spike_clusters ) cluster_ids = _unique ( spike_clusters ) spike_clusters_rel = _index_of ( spike_clusters , cluster_ids ) spike_counts = np . b... | Compute the mean of a spike - dependent quantity for every cluster . |
240,629 | def regular_subset ( spikes , n_spikes_max = None , offset = 0 ) : assert spikes is not None if n_spikes_max is None or len ( spikes ) <= n_spikes_max : return spikes step = math . ceil ( np . clip ( 1. / n_spikes_max * len ( spikes ) , 1 , len ( spikes ) ) ) step = int ( step ) my_spikes = spikes [ offset : : step ] [... | Prune the current selection to get at most n_spikes_max spikes . |
240,630 | def select_spikes ( cluster_ids = None , max_n_spikes_per_cluster = None , spikes_per_cluster = None , batch_size = None , subset = None , ) : subset = subset or 'regular' assert _is_array_like ( cluster_ids ) if not len ( cluster_ids ) : return np . array ( [ ] , dtype = np . int64 ) if max_n_spikes_per_cluster in ( N... | Return a selection of spikes belonging to the specified clusters . |
240,631 | def _get_recording ( self , index ) : assert index >= 0 recs = np . nonzero ( ( index - self . offsets [ : - 1 ] ) >= 0 ) [ 0 ] if len ( recs ) == 0 : return len ( self . arrs ) - 1 return recs [ - 1 ] | Return the recording that contains a given index . |
240,632 | def bandpass_filter ( rate = None , low = None , high = None , order = None ) : assert low < high assert order >= 1 return signal . butter ( order , ( low / ( rate / 2. ) , high / ( rate / 2. ) ) , 'pass' ) | Butterworth bandpass filter . |
240,633 | def apply_filter ( x , filter = None , axis = 0 ) : x = _as_array ( x ) if x . shape [ axis ] == 0 : return x b , a = filter return signal . filtfilt ( b , a , x , axis = axis ) | Apply a filter to an array . |
240,634 | def fit ( self , x , fudge = 1e-18 ) : assert x . ndim == 2 ns , nc = x . shape x_cov = np . cov ( x , rowvar = 0 ) assert x_cov . shape == ( nc , nc ) d , v = np . linalg . eigh ( x_cov ) d = np . diag ( 1. / np . sqrt ( d + fudge ) ) w = np . dot ( np . dot ( v , d ) , v . T ) self . _matrix = w return w | Compute the whitening matrix . |
240,635 | def current_item ( self ) : if self . _history and self . _index >= 0 : self . _check_index ( ) return self . _history [ self . _index ] | Return the current element . |
240,636 | def _check_index ( self ) : assert 0 <= self . _index <= len ( self . _history ) - 1 assert len ( self . _history ) >= 1 | Check that the index is without the bounds of _history . |
240,637 | def iter ( self , start = 0 , end = None ) : if end is None : end = self . _index + 1 elif end == 0 : raise StopIteration ( ) if start >= end : raise StopIteration ( ) assert 0 <= end <= len ( self . _history ) assert 0 <= start <= end - 1 for i in range ( start , end ) : yield self . _history [ i ] | Iterate through successive history items . |
240,638 | def add ( self , item ) : self . _check_index ( ) self . _history = self . _history [ : self . _index + 1 ] self . _history . append ( item ) self . _index += 1 self . _check_index ( ) assert id ( self . current_item ) == id ( item ) | Add an item in the history . |
240,639 | def back ( self ) : if self . _index <= 0 : return None undone = self . current_item self . _index -= 1 self . _check_index ( ) return undone | Go back in history if possible . |
240,640 | def forward ( self ) : if self . _index >= len ( self . _history ) - 1 : return None self . _index += 1 self . _check_index ( ) return self . current_item | Go forward in history if possible . |
240,641 | def add_to_current_action ( self , controller ) : item = self . current_item self . _history [ self . _index ] = item + ( controller , ) | Add a controller to the current action . |
240,642 | def redo ( self ) : controllers = self . forward ( ) if controllers is None : ups = ( ) else : ups = tuple ( [ controller . redo ( ) for controller in controllers ] ) if self . process_ups is not None : return self . process_ups ( ups ) else : return ups | Redo the last action . |
240,643 | def _insert_glsl ( vertex , fragment , to_insert ) : vs_regex = re . compile ( r'gl_Position = transform\(([\S]+)\);' ) r = vs_regex . search ( vertex ) if not r : logger . debug ( "The vertex shader doesn't contain the transform " "placeholder: skipping the transform chain " "GLSL insertion." ) return vertex , fragmen... | Insert snippets in a shader . |
240,644 | def on_draw ( self ) : if self . program : self . program . draw ( self . gl_primitive_type ) else : logger . debug ( "Skipping drawing visual `%s` because the program " "has not been built yet." , self ) | Draw the visual . |
240,645 | def add_transform_chain ( self , tc ) : for t in tc . gpu_transforms : if isinstance ( t , Clip ) : self . insert_vert ( 'v_temp_pos_tr = temp_pos_tr;' ) continue self . insert_vert ( t . glsl ( 'temp_pos_tr' ) ) clip = tc . get ( 'Clip' ) if clip : self . insert_frag ( clip . glsl ( 'v_temp_pos_tr' ) , 'before_transfo... | Insert the GLSL snippets of a transform chain . |
240,646 | def insert_into_shaders ( self , vertex , fragment ) : to_insert = defaultdict ( str ) to_insert . update ( { key : '\n' . join ( self . _to_insert [ key ] ) + '\n' for key in self . _to_insert } ) return _insert_glsl ( vertex , fragment , to_insert ) | Apply the insertions to shader code . |
240,647 | def add_visual ( self , visual ) : inserter = visual . inserter inserter . add_transform_chain ( visual . transforms ) canvas_transforms = visual . canvas_transforms_filter ( self . transforms ) inserter . add_transform_chain ( canvas_transforms ) inserter += self . inserter vs , fs = visual . vertex_shader , visual . ... | Add a visual to the canvas and build its program by the same occasion . |
240,648 | def on_resize ( self , event ) : self . context . set_viewport ( 0 , 0 , event . size [ 0 ] , event . size [ 1 ] ) for visual in self . visuals : visual . on_resize ( event . size ) self . update ( ) | Resize the OpenGL context . |
240,649 | def on_draw ( self , e ) : gloo . clear ( ) for visual in self . visuals : logger . log ( 5 , "Draw visual `%s`." , visual ) visual . on_draw ( ) | Draw all visuals . |
240,650 | def update ( self ) : if not self . canvas : return for visual in self . canvas . visuals : self . update_program ( visual . program ) self . canvas . update ( ) | Update all visuals in the attached canvas . |
240,651 | def _add_log_file ( filename ) : handler = logging . FileHandler ( filename ) handler . setLevel ( logging . DEBUG ) formatter = _Formatter ( fmt = _logger_fmt , datefmt = '%Y-%m-%d %H:%M:%S' ) handler . setFormatter ( formatter ) logging . getLogger ( ) . addHandler ( handler ) | Create a phy . log log file with DEBUG level in the current directory . |
240,652 | def _run_cmd ( cmd , ctx , glob , loc ) : if PDB : _enable_pdb ( ) if IPYTHON : from IPython import start_ipython args_ipy = [ '-i' , '--gui=qt' ] ns = glob . copy ( ) ns . update ( loc ) return start_ipython ( args_ipy , user_ns = ns ) prof = __builtins__ . get ( 'profile' , None ) if prof : prof = __builtins__ [ 'pro... | Run a command with optionally a debugger IPython or profiling . |
240,653 | def load_cli_plugins ( cli , config_dir = None ) : from . config import load_master_config config = load_master_config ( config_dir = config_dir ) plugins = discover_plugins ( config . Plugins . dirs ) for plugin in plugins : if not hasattr ( plugin , 'attach_to_cli' ) : continue logger . debug ( "Attach plugin `%s` to... | Load all plugins and attach them to a CLI object . |
240,654 | def get_mouse_pos ( self , pos ) : position = np . asarray ( self . _normalize ( pos ) ) zoom = np . asarray ( self . _zoom_aspect ( ) ) pan = np . asarray ( self . pan ) mouse_pos = ( ( position / zoom ) - pan ) return mouse_pos | Return the mouse coordinates in NDC taking panzoom into account . |
240,655 | def pan ( self , value ) : assert len ( value ) == 2 self . _pan [ : ] = value self . _constrain_pan ( ) self . update ( ) | Pan translation . |
240,656 | def zoom ( self , value ) : if isinstance ( value , ( int , float ) ) : value = ( value , value ) assert len ( value ) == 2 self . _zoom = np . clip ( value , self . _zmin , self . _zmax ) self . _constrain_pan ( ) self . _constrain_zoom ( ) self . update ( ) | Zoom level . |
240,657 | def pan_delta ( self , d ) : dx , dy = d pan_x , pan_y = self . pan zoom_x , zoom_y = self . _zoom_aspect ( self . _zoom ) self . pan = ( pan_x + dx / zoom_x , pan_y + dy / zoom_y ) self . update ( ) | Pan the view by a given amount . |
240,658 | def zoom_delta ( self , d , p = ( 0. , 0. ) , c = 1. ) : dx , dy = d x0 , y0 = p pan_x , pan_y = self . _pan zoom_x , zoom_y = self . _zoom zoom_x_new , zoom_y_new = ( zoom_x * math . exp ( c * self . _zoom_coeff * dx ) , zoom_y * math . exp ( c * self . _zoom_coeff * dy ) ) zoom_x_new = max ( min ( zoom_x_new , self .... | Zoom the view by a given amount . |
240,659 | def set_range ( self , bounds , keep_aspect = False ) : bounds = np . asarray ( bounds , dtype = np . float64 ) v0 = bounds [ : 2 ] v1 = bounds [ 2 : ] pan = - .5 * ( v0 + v1 ) zoom = 2. / ( v1 - v0 ) if keep_aspect : zoom = zoom . min ( ) * np . ones ( 2 ) self . set_pan_zoom ( pan = pan , zoom = zoom ) | Zoom to fit a box . |
240,660 | def get_range ( self ) : p , z = np . asarray ( self . pan ) , np . asarray ( self . zoom ) x0 , y0 = - 1. / z - p x1 , y1 = + 1. / z - p return ( x0 , y0 , x1 , y1 ) | Return the bounds currently visible . |
240,661 | def on_mouse_move ( self , event ) : if event . modifiers : return if event . is_dragging : x0 , y0 = self . _normalize ( event . press_event . pos ) x1 , y1 = self . _normalize ( event . last_event . pos ) x , y = self . _normalize ( event . pos ) dx , dy = x - x1 , y - y1 if event . button == 1 : self . pan_delta ( (... | Pan and zoom with the mouse . |
240,662 | def on_mouse_wheel ( self , event ) : if event . modifiers : return dx = np . sign ( event . delta [ 1 ] ) * self . _wheel_coeff x0 , y0 = self . _normalize ( event . pos ) self . zoom_delta ( ( dx , dx ) , ( x0 , y0 ) ) | Zoom with the mouse wheel . |
240,663 | def on_key_press ( self , event ) : key = event . key if event . modifiers : return if self . enable_keyboard_pan and key in self . _arrows : self . _pan_keyboard ( key ) if key in self . _pm : self . _zoom_keyboard ( key ) if key == 'R' : self . reset ( ) | Pan and zoom with the keyboard . |
240,664 | def _replace_docstring_header ( paragraph ) : paragraph = re . sub ( _docstring_header_pattern , r'*\1*' , paragraph , ) paragraph = re . sub ( _docstring_parameters_pattern , r'\n* `\1` (\2)\n' , paragraph , ) return paragraph | Process NumPy - like function docstrings . |
240,665 | def _iter_vars ( mod ) : vars = sorted ( var for var in dir ( mod ) if _is_public ( var ) ) for var in vars : yield getattr ( mod , var ) | Iterate through a list of variables define in a module s public namespace . |
240,666 | def _function_header ( subpackage , func ) : args = inspect . formatargspec ( * inspect . getfullargspec ( func ) ) return "{name}{args}" . format ( name = _full_name ( subpackage , func ) , args = args , ) | Generate the docstring of a function . |
240,667 | def _doc_method ( klass , func ) : argspec = inspect . getfullargspec ( func ) if argspec . args and argspec . args [ 0 ] == 'self' : del argspec . args [ 0 ] args = inspect . formatargspec ( * argspec ) header = "{klass}.{name}{args}" . format ( klass = klass . __name__ , name = _name ( func ) , args = args , ) docstr... | Generate the docstring of a method . |
240,668 | def _doc_property ( klass , prop ) : header = "{klass}.{name}" . format ( klass = klass . __name__ , name = _name ( prop ) , ) docstring = _doc ( prop ) return _concat ( header , docstring ) | Generate the docstring of a property . |
240,669 | def _generate_paragraphs ( package , subpackages ) : for subpackage in _iter_subpackages ( package , subpackages ) : subpackage_name = subpackage . __name__ yield "## {}" . format ( subpackage_name ) yield _doc ( _import_module ( subpackage_name ) ) for func in _iter_functions ( subpackage ) : yield '##### ' + _doc_fun... | Generate the paragraphs of the API documentation . |
240,670 | def _add_field_column ( self , field ) : @ self . add_column ( name = field ) def get_my_label ( cluster_id ) : return self . cluster_meta . get ( field , cluster_id ) | Add a column for a given label field . |
240,671 | def _emit_select ( self , cluster_ids , ** kwargs ) : cluster_ids = self . _keep_existing_clusters ( cluster_ids ) logger . debug ( "Select cluster(s): %s." , ', ' . join ( map ( str , cluster_ids ) ) ) self . emit ( 'select' , cluster_ids , ** kwargs ) | Choose spikes from the specified clusters and emit the select event on the GUI . |
240,672 | def _update_cluster_view ( self ) : logger . log ( 5 , "Update the cluster view." ) cluster_ids = [ int ( c ) for c in self . clustering . cluster_ids ] self . cluster_view . set_rows ( cluster_ids ) | Initialize the cluster view with cluster data . |
240,673 | def _update_similarity_view ( self ) : if not self . similarity : return selection = self . cluster_view . selected if not len ( selection ) : return cluster_id = selection [ 0 ] cluster_ids = self . clustering . cluster_ids self . _best = cluster_id logger . log ( 5 , "Update the similarity view." ) similarities = sel... | Update the similarity view with matches for the specified clusters . |
240,674 | def on_cluster ( self , up ) : similar = self . similarity_view . selected if up . added : self . _update_cluster_view ( ) if up . history == 'undo' : clusters_0 , clusters_1 = up . undo_state [ 0 ] [ 'selection' ] self . cluster_view . select ( clusters_0 , up = up ) self . similarity_view . select ( clusters_1 , up =... | Update the cluster views after clustering actions . |
240,675 | def select ( self , * cluster_ids ) : if cluster_ids and isinstance ( cluster_ids [ 0 ] , ( tuple , list ) ) : cluster_ids = list ( cluster_ids [ 0 ] ) + list ( cluster_ids [ 1 : ] ) cluster_ids = self . _keep_existing_clusters ( cluster_ids ) self . cluster_view . select ( cluster_ids ) | Select a list of clusters . |
240,676 | def merge ( self , cluster_ids = None , to = None ) : if cluster_ids is None : cluster_ids = self . selected if len ( cluster_ids or [ ] ) <= 1 : return self . clustering . merge ( cluster_ids , to = to ) self . _global_history . action ( self . clustering ) | Merge the selected clusters . |
240,677 | def split ( self , spike_ids = None , spike_clusters_rel = 0 ) : if spike_ids is None : spike_ids = self . emit ( 'request_split' , single = True ) spike_ids = np . asarray ( spike_ids , dtype = np . int64 ) assert spike_ids . dtype == np . int64 assert spike_ids . ndim == 1 if len ( spike_ids ) == 0 : msg = ( "You fir... | Split the selected spikes . |
240,678 | def get_labels ( self , field ) : return { c : self . cluster_meta . get ( field , c ) for c in self . clustering . cluster_ids } | Return the labels of all clusters for a given field . |
240,679 | def label ( self , name , value , cluster_ids = None ) : if cluster_ids is None : cluster_ids = self . cluster_view . selected if not hasattr ( cluster_ids , '__len__' ) : cluster_ids = [ cluster_ids ] if len ( cluster_ids ) == 0 : return self . cluster_meta . set ( name , cluster_ids , value ) self . _global_history .... | Assign a label to clusters . |
240,680 | def move ( self , group , cluster_ids = None ) : if isinstance ( cluster_ids , string_types ) : logger . warn ( "The list of clusters should be a list of integers, " "not a string." ) return self . label ( 'group' , group , cluster_ids = cluster_ids ) | Assign a group to some clusters . |
240,681 | def next ( self ) : if not self . selected : self . cluster_view . next ( ) else : self . similarity_view . next ( ) | Select the next cluster . |
240,682 | def save ( self ) : spike_clusters = self . clustering . spike_clusters groups = { c : self . cluster_meta . get ( 'group' , c ) or 'unsorted' for c in self . clustering . cluster_ids } labels = [ ( field , self . get_labels ( field ) ) for field in self . cluster_meta . fields if field not in ( 'next_cluster' ) ] self... | Save the manual clustering back to disk . |
240,683 | def create_cluster_meta ( cluster_groups ) : meta = ClusterMeta ( ) meta . add_field ( 'group' ) cluster_groups = cluster_groups or { } data = { c : { 'group' : v } for c , v in cluster_groups . items ( ) } meta . from_dict ( data ) return meta | Return a ClusterMeta instance with cluster group support . |
240,684 | def add_field ( self , name , default_value = None ) : self . _fields [ name ] = default_value def func ( cluster ) : return self . get ( name , cluster ) setattr ( self , name , func ) | Add a field with an optional default value . |
240,685 | def set ( self , field , clusters , value , add_to_stack = True ) : if field not in self . _fields : self . add_field ( field ) assert field in self . _fields clusters = _as_list ( clusters ) for cluster in clusters : if cluster not in self . _data : self . _data [ cluster ] = { } self . _data [ cluster ] [ field ] = v... | Set the value of one of several clusters . |
240,686 | def get ( self , field , cluster ) : if _is_list ( cluster ) : return [ self . get ( field , c ) for c in cluster ] assert field in self . _fields default = self . _fields [ field ] return self . _data . get ( cluster , { } ) . get ( field , default ) | Retrieve the value of one cluster . |
240,687 | def set_from_descendants ( self , descendants ) : for field in self . fields : candidates = defaultdict ( set ) for old , new in descendants : candidates [ new ] . add ( self . get ( field , old ) ) for new , vals in candidates . items ( ) : vals = list ( vals ) default = self . _fields [ field ] if len ( vals ) == 1 a... | Update metadata of some clusters given the metadata of their ascendants . |
240,688 | def undo ( self ) : args = self . _undo_stack . back ( ) if args is None : return self . _data = deepcopy ( self . _data_base ) for clusters , field , value , up , undo_state in self . _undo_stack : if clusters is not None : self . set ( field , clusters , value , add_to_stack = False ) up , undo_state = args [ - 2 : ]... | Undo the last metadata change . |
240,689 | def redo ( self ) : args = self . _undo_stack . forward ( ) if args is None : return clusters , field , value , up , undo_state = args self . set ( field , clusters , value , add_to_stack = False ) up . history = 'redo' self . emit ( 'cluster' , up ) return up | Redo the next metadata change . |
240,690 | def _get_boxes ( pos , size = None , margin = 0 , keep_aspect_ratio = True ) : pos = np . asarray ( pos , dtype = np . float64 ) x , y = pos . T x = x [ : , np . newaxis ] y = y [ : , np . newaxis ] w , h = size if size is not None else _get_box_size ( x , y , margin = margin ) x0 , y0 = x - w , y - h x1 , y1 = x + w ,... | Generate non - overlapping boxes in NDC from a set of positions . |
240,691 | def _get_texture ( arr , default , n_items , from_bounds ) : if not hasattr ( default , '__len__' ) : default = [ default ] n_cols = len ( default ) if arr is None : arr = np . tile ( default , ( n_items , 1 ) ) assert arr . shape == ( n_items , n_cols ) arr = arr [ np . newaxis , ... ] . astype ( np . float64 ) assert... | Prepare data to be uploaded as a texture . |
240,692 | def _get_array ( val , shape , default = None , dtype = np . float64 ) : assert val is not None or default is not None if hasattr ( val , '__len__' ) and len ( val ) == 0 : val = None if ( isinstance ( val , np . ndarray ) and val . shape == shape and val . dtype == dtype ) : return val out = np . zeros ( shape , dtype... | Ensure an object is an array with the specified shape . |
240,693 | def _get_index ( n_items , item_size , n ) : index = np . arange ( n_items ) index = np . repeat ( index , item_size ) index = index . astype ( np . float64 ) assert index . shape == ( n , ) return index | Prepare an index attribute for GPU uploading . |
240,694 | def _load_shader ( filename ) : curdir = op . dirname ( op . realpath ( __file__ ) ) glsl_path = op . join ( curdir , 'glsl' ) path = op . join ( glsl_path , filename ) with open ( path , 'r' ) as f : return f . read ( ) | Load a shader file . |
240,695 | def _random_color ( h_range = ( 0. , 1. ) , s_range = ( .5 , 1. ) , v_range = ( .5 , 1. ) , ) : h , s , v = uniform ( * h_range ) , uniform ( * s_range ) , uniform ( * v_range ) r , g , b = hsv_to_rgb ( np . array ( [ [ [ h , s , v ] ] ] ) ) . flat return r , g , b | Generate a random RGB color . |
240,696 | def _is_bright ( rgb ) : r , g , b = rgb gray = 0.299 * r + 0.587 * g + 0.114 * b return gray >= .5 | Return whether a RGB color is bright or not . |
240,697 | def _bunchify ( b ) : assert isinstance ( b , dict ) b = Bunch ( b ) for k in b : if isinstance ( b [ k ] , dict ) : b [ k ] = Bunch ( b [ k ] ) return b | Ensure all dict elements are Bunch . |
240,698 | def _as_list ( obj ) : if obj is None : return None elif isinstance ( obj , string_types ) : return [ obj ] elif isinstance ( obj , tuple ) : return list ( obj ) elif not hasattr ( obj , '__len__' ) : return [ obj ] else : return obj | Ensure an object is a list . |
240,699 | def _as_array ( arr , dtype = None ) : if arr is None : return None if isinstance ( arr , np . ndarray ) and dtype is None : return arr if isinstance ( arr , integer_types + ( float , ) ) : arr = [ arr ] out = np . asarray ( arr ) if dtype is not None : if out . dtype != dtype : out = out . astype ( dtype ) if out . dt... | Convert an object to a numerical NumPy array . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.