idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
23,600
def return_dat ( self , chan , begsam , endsam ) : dat = empty ( ( len ( chan ) , endsam - begsam ) ) dat . fill ( NaN ) stc , all_stamp = _read_stc ( self . _filename . with_suffix ( '.stc' ) ) all_erd = all_stamp [ 'segment_name' ] . astype ( 'U' ) all_beg = all_stamp [ 'start_stamp' ] all_end = all_stamp [ 'end_stam...
Read the data based on begsam and endsam .
23,601
def return_markers ( self ) : ent_file = self . _filename . with_suffix ( '.ent' ) if not ent_file . exists ( ) : ent_file = self . _filename . with_suffix ( '.ent.old' ) try : ent_notes = _read_ent ( ent_file ) except ( FileNotFoundError , PermissionError ) : markers = [ ] else : allnote = [ ] for n in ent_notes : try...
Reads the notes of the Ktlx recordings .
23,602
def return_markers ( self , trigger_bits = 8 , trigger_zero = True ) : nev_file = splitext ( self . filename ) [ 0 ] + '.nev' markers = _read_neuralev ( nev_file , read_markers = True ) if trigger_bits == 8 : to8 = lambda x : str ( int ( x ) - ( 256 ** 2 - 256 ) ) for m in markers : m [ 'name' ] = to8 ( m [ 'name' ] ) ...
We always read triggers as 16bit but we convert them to 8 here if requested .
23,603
def tridi_inverse_iteration ( d , e , w , x0 = None , rtol = 1e-8 ) : eig_diag = d - w if x0 is None : x0 = np . random . randn ( len ( d ) ) x_prev = np . zeros_like ( x0 ) norm_x = np . linalg . norm ( x0 ) x0 /= norm_x while np . linalg . norm ( np . abs ( x0 ) - np . abs ( x_prev ) ) > rtol : x_prev = x0 . copy ( )...
Perform an inverse iteration to find the eigenvector corresponding to the given eigenvalue in a symmetric tridiagonal system .
23,604
def tridisolve ( d , e , b , overwrite_b = True ) : N = len ( b ) dw = d . copy ( ) ew = e . copy ( ) if overwrite_b : x = b else : x = b . copy ( ) for k in range ( 1 , N ) : t = ew [ k - 1 ] ew [ k - 1 ] = t / dw [ k - 1 ] dw [ k ] = dw [ k ] - t * ew [ k - 1 ] for k in range ( 1 , N ) : x [ k ] = x [ k ] - ew [ k - ...
Symmetric tridiagonal system solver from Golub and Van Loan Matrix Computations pg 157
23,605
def autocov ( x , ** kwargs ) : debias = kwargs . pop ( 'debias' , True ) axis = kwargs . get ( 'axis' , - 1 ) if debias : x = remove_bias ( x , axis ) kwargs [ 'debias' ] = False return crosscov ( x , x , ** kwargs )
Returns the autocovariance of signal s at all lags .
23,606
def fftconvolve ( in1 , in2 , mode = "full" , axis = None ) : s1 = np . array ( in1 . shape ) s2 = np . array ( in2 . shape ) complex_result = ( np . issubdtype ( in1 . dtype , np . complexfloating ) or np . issubdtype ( in2 . dtype , np . complexfloating ) ) if axis is None : size = s1 + s2 - 1 fslice = tuple ( [ slic...
Convolve two N - dimensional arrays using FFT . See convolve .
23,607
def band_power ( data , freq , scaling = 'power' , n_fft = None , detrend = None , array_out = False ) : if not array_out : power = { } peakf = { } else : power = zeros ( ( data . number_of ( 'chan' ) [ 0 ] , 1 ) ) peakf = zeros ( ( data . number_of ( 'chan' ) [ 0 ] , 1 ) ) if isinstance ( data , ChanFreq ) : Sxx = dat...
Compute power or energy acoss a frequency band and its peak frequency . Power is estimated using the mid - point rectangle rule . Input can be ChanTime or ChanFreq .
23,608
def _create_morlet ( options , s_freq ) : wavelets = [ ] foi = options . pop ( 'foi' ) for f in foi : wavelets . append ( morlet ( f , s_freq , ** options ) ) return wavelets
Create morlet wavelets with scipy . signal doing the actual computation .
23,609
def morlet ( freq , s_freq , ratio = 5 , sigma_f = None , dur_in_sd = 4 , dur_in_s = None , normalization = 'peak' , zero_mean = False ) : if sigma_f is None : sigma_f = freq / ratio else : ratio = freq / sigma_f sigma_t = 1 / ( 2 * pi * sigma_f ) if ratio < 5 and not zero_mean : lg . info ( 'The wavelet won\'t have ze...
Create a Morlet wavelet .
23,610
def create_widgets ( self ) : self . bbox = QDialogButtonBox ( QDialogButtonBox . Ok | QDialogButtonBox . Cancel ) self . idx_ok = self . bbox . button ( QDialogButtonBox . Ok ) self . idx_cancel = self . bbox . button ( QDialogButtonBox . Cancel ) self . idx_group = FormMenu ( [ gr [ 'name' ] for gr in self . groups ]...
Build basic components of dialog .
23,611
def update_groups ( self ) : self . groups = self . parent . channels . groups self . idx_group . clear ( ) for gr in self . groups : self . idx_group . addItem ( gr [ 'name' ] ) self . update_channels ( )
Update the channel groups list when dialog is opened .
23,612
def update_channels ( self ) : group_dict = { k [ 'name' ] : i for i , k in enumerate ( self . groups ) } group_index = group_dict [ self . idx_group . currentText ( ) ] self . one_grp = self . groups [ group_index ] self . idx_chan . clear ( ) self . idx_chan . setSelectionMode ( QAbstractItemView . ExtendedSelection ...
Update the channels list when a new group is selected .
23,613
def update_cycles ( self ) : self . idx_cycle . clear ( ) try : self . cycles = self . parent . notes . annot . get_cycles ( ) except ValueError as err : self . idx_cycle . setEnabled ( False ) msg = 'There is a problem with the cycle markers: ' + str ( err ) self . parent . statusBar ( ) . showMessage ( msg ) else : i...
Enable cycles checkbox only if there are cycles marked with no errors .
23,614
def _create_data_to_plot ( data , chan_groups ) : chan_to_plot = [ one_chan for one_grp in chan_groups for one_chan in one_grp [ 'chan_to_plot' ] ] output = ChanTime ( ) output . s_freq = data . s_freq output . start_time = data . start_time output . axis [ 'time' ] = data . axis [ 'time' ] output . axis [ 'chan' ] = e...
Create data after montage and filtering .
23,615
def _convert_timestr_to_seconds ( time_str , rec_start ) : if not CHECK_TIME_STR . match ( time_str ) : raise ValueError ( 'Input can only contain digits and colons' ) if ':' in time_str : time_split = [ int ( x ) for x in time_str . split ( ':' ) ] if len ( time_split ) == 2 : time_split . append ( 0 ) clock_time = ti...
Convert input from user about time string to an absolute time for the recordings .
23,616
def read_data ( self ) : window_start = self . parent . value ( 'window_start' ) window_end = window_start + self . parent . value ( 'window_length' ) dataset = self . parent . info . dataset groups = self . parent . channels . groups chan_to_read = [ ] for one_grp in groups : chan_to_read . extend ( one_grp [ 'chan_to...
Read the data to plot .
23,617
def display ( self ) : if self . data is None : return if self . scene is not None : self . y_scrollbar_value = self . verticalScrollBar ( ) . value ( ) self . scene . clear ( ) self . create_chan_labels ( ) self . create_time_labels ( ) window_start = self . parent . value ( 'window_start' ) window_length = self . par...
Display the recordings .
23,618
def create_chan_labels ( self ) : self . idx_label = [ ] for one_grp in self . parent . channels . groups : for one_label in one_grp [ 'chan_to_plot' ] : item = QGraphicsSimpleTextItem ( one_label ) item . setBrush ( QBrush ( QColor ( one_grp [ 'color' ] ) ) ) item . setFlag ( QGraphicsItem . ItemIgnoresTransformations...
Create the channel labels but don t plot them yet .
23,619
def create_time_labels ( self ) : min_time = int ( floor ( min ( self . data . axis [ 'time' ] [ 0 ] ) ) ) max_time = int ( ceil ( max ( self . data . axis [ 'time' ] [ 0 ] ) ) ) n_time_labels = self . parent . value ( 'n_time_labels' ) self . idx_time = [ ] self . time_pos = [ ] for one_time in linspace ( min_time , m...
Create the time labels but don t plot them yet .
23,620
def add_chan_labels ( self ) : window_start = self . parent . value ( 'window_start' ) window_length = self . parent . value ( 'window_length' ) label_width = window_length * self . parent . value ( 'label_ratio' ) for row , one_label_item in enumerate ( self . idx_label ) : self . scene . addItem ( one_label_item ) on...
Add channel labels on the left .
23,621
def add_time_labels ( self ) : for text , pos in zip ( self . idx_time , self . time_pos ) : self . scene . addItem ( text ) text . setPos ( pos )
Add time labels at the bottom .
23,622
def add_traces ( self ) : y_distance = self . parent . value ( 'y_distance' ) self . chan = [ ] self . chan_pos = [ ] self . chan_scale = [ ] row = 0 for one_grp in self . parent . channels . groups : for one_chan in one_grp [ 'chan_to_plot' ] : chan_name = one_chan + ' (' + one_grp [ 'name' ] + ')' dat = ( self . data...
Add traces based on self . data .
23,623
def display_grid ( self ) : window_start = self . parent . value ( 'window_start' ) window_length = self . parent . value ( 'window_length' ) window_end = window_start + window_length if self . parent . value ( 'grid_x' ) : x_tick = self . parent . value ( 'grid_xtick' ) x_ticks = arange ( window_start , window_end + x...
Display grid on x - axis and y - axis .
23,624
def display_markers ( self ) : for item in self . idx_markers : self . scene . removeItem ( item ) self . idx_markers = [ ] window_start = self . parent . value ( 'window_start' ) window_length = self . parent . value ( 'window_length' ) window_end = window_start + window_length y_distance = self . parent . value ( 'y_...
Add markers on top of first plot .
23,625
def step_prev ( self ) : window_start = around ( self . parent . value ( 'window_start' ) - self . parent . value ( 'window_length' ) / self . parent . value ( 'window_step' ) , 2 ) if window_start < 0 : return self . parent . overview . update_position ( window_start )
Go to the previous step .
23,626
def step_next ( self ) : window_start = around ( self . parent . value ( 'window_start' ) + self . parent . value ( 'window_length' ) / self . parent . value ( 'window_step' ) , 2 ) self . parent . overview . update_position ( window_start )
Go to the next step .
23,627
def page_prev ( self ) : window_start = ( self . parent . value ( 'window_start' ) - self . parent . value ( 'window_length' ) ) if window_start < 0 : return self . parent . overview . update_position ( window_start )
Go to the previous page .
23,628
def page_next ( self ) : window_start = ( self . parent . value ( 'window_start' ) + self . parent . value ( 'window_length' ) ) self . parent . overview . update_position ( window_start )
Go to the next page .
23,629
def go_to_epoch ( self , checked = False , test_text_str = None ) : if test_text_str is not None : time_str = test_text_str ok = True else : time_str , ok = QInputDialog . getText ( self , 'Go To Epoch' , 'Enter start time of the ' 'epoch,\nin seconds ("1560") ' 'or\nas absolute time ' '("22:30")' ) if not ok : return ...
Go to any window
23,630
def line_up_with_epoch ( self ) : if self . parent . notes . annot is None : error_dialog = QErrorMessage ( ) error_dialog . setWindowTitle ( 'Error moving to epoch' ) error_dialog . showMessage ( 'No score file loaded' ) error_dialog . exec ( ) return new_window_start = self . parent . notes . annot . get_epoch_start ...
Go to the start of the present epoch .
23,631
def add_time ( self , extra_time ) : window_start = self . parent . value ( 'window_start' ) + extra_time self . parent . overview . update_position ( window_start )
Go to the predefined time forward .
23,632
def X_more ( self ) : if self . parent . value ( 'window_length' ) < 0.3 : return self . parent . value ( 'window_length' , self . parent . value ( 'window_length' ) * 2 ) self . parent . overview . update_position ( )
Zoom in on the x - axis .
23,633
def X_less ( self ) : self . parent . value ( 'window_length' , self . parent . value ( 'window_length' ) / 2 ) self . parent . overview . update_position ( )
Zoom out on the x - axis .
23,634
def X_length ( self , new_window_length ) : self . parent . value ( 'window_length' , new_window_length ) self . parent . overview . update_position ( )
Use presets for length of the window .
23,635
def Y_more ( self ) : self . parent . value ( 'y_scale' , self . parent . value ( 'y_scale' ) * 2 ) self . parent . traces . display ( )
Increase the scaling .
23,636
def Y_less ( self ) : self . parent . value ( 'y_scale' , self . parent . value ( 'y_scale' ) / 2 ) self . parent . traces . display ( )
Decrease the scaling .
23,637
def Y_ampl ( self , new_y_scale ) : self . parent . value ( 'y_scale' , new_y_scale ) self . parent . traces . display ( )
Make scaling on Y axis using predefined values
23,638
def Y_wider ( self ) : self . parent . value ( 'y_distance' , self . parent . value ( 'y_distance' ) * 1.4 ) self . parent . traces . display ( )
Increase the distance of the lines .
23,639
def Y_tighter ( self ) : self . parent . value ( 'y_distance' , self . parent . value ( 'y_distance' ) / 1.4 ) self . parent . traces . display ( )
Decrease the distance of the lines .
23,640
def Y_dist ( self , new_y_distance ) : self . parent . value ( 'y_distance' , new_y_distance ) self . parent . traces . display ( )
Use preset values for the distance between lines .
23,641
def mousePressEvent ( self , event ) : if not self . scene : return if self . event_sel or self . current_event : self . parent . notes . idx_eventtype . setCurrentText ( self . current_etype ) self . current_etype = None self . current_event = None self . deselect = True self . event_sel = None self . current_event_ro...
Create a marker or start selection
23,642
def mouseReleaseEvent ( self , event ) : if not self . scene : return if self . event_sel : return if self . deselect : self . deselect = False return if not self . ready : return chk_marker = self . parent . notes . action [ 'new_bookmark' ] . isChecked ( ) chk_event = self . parent . notes . action [ 'new_event' ] . ...
Create a new event or marker or show the previous power spectrum
23,643
def next_event ( self , delete = False ) : if delete : msg = "Delete this event? This cannot be undone." msgbox = QMessageBox ( QMessageBox . Question , 'Delete event' , msg ) msgbox . setStandardButtons ( QMessageBox . Yes | QMessageBox . No ) msgbox . setDefaultButton ( QMessageBox . Yes ) response = msgbox . exec_ (...
Go to next event .
23,644
def resizeEvent ( self , event ) : if self . scene is not None : ratio = self . width ( ) / ( self . scene . width ( ) * 1.1 ) self . resetTransform ( ) self . scale ( ratio , 1 )
Resize scene so that it fits the whole widget .
23,645
def return_dat ( self , chan , begsam , endsam ) : assert begsam < endsam dat = empty ( ( len ( chan ) , endsam - begsam ) ) dat . fill ( NaN ) with self . filename . open ( 'rb' ) as f : for i_dat , blk , i_blk in _select_blocks ( self . blocks , begsam , endsam ) : dat_in_rec = self . _read_record ( f , blk , chan ) ...
Read data from an EDF file .
23,646
def _read_record ( self , f , blk , chans ) : dat_in_rec = empty ( ( len ( chans ) , self . max_smp ) ) i_ch_in_dat = 0 for i_ch in chans : offset , n_smp_per_chan = self . _offset ( blk , i_ch ) f . seek ( offset ) x = fromfile ( f , count = n_smp_per_chan , dtype = EDF_FORMAT ) ratio = int ( self . max_smp / n_smp_pe...
Read raw data from a single EDF channel .
23,647
def write_brainvision ( data , filename , markers = None ) : filename = Path ( filename ) . resolve ( ) . with_suffix ( '.vhdr' ) if markers is None : markers = [ ] with filename . open ( 'w' ) as f : f . write ( _write_vhdr ( data , filename ) ) with filename . with_suffix ( '.vmrk' ) . open ( 'w' ) as f : f . write (...
Export data in BrainVision format
23,648
def calc_xyz2surf ( surf , xyz , threshold = 20 , exponent = None , std = None ) : if exponent is None and std is None : exponent = 1 if exponent is not None : lg . debug ( 'Vertex values based on inverse-law, with exponent ' + str ( exponent ) ) funct = partial ( calc_one_vert_inverse , xyz = xyz , exponent = exponent...
Calculate transformation matrix from xyz values to vertices .
23,649
def calc_one_vert_inverse ( one_vert , xyz = None , exponent = None ) : trans = empty ( xyz . shape [ 0 ] ) for i , one_xyz in enumerate ( xyz ) : trans [ i ] = 1 / ( norm ( one_vert - one_xyz ) ** exponent ) return trans
Calculate how many electrodes influence one vertex using the inverse function .
23,650
def calc_one_vert_gauss ( one_vert , xyz = None , std = None ) : trans = empty ( xyz . shape [ 0 ] ) for i , one_xyz in enumerate ( xyz ) : trans [ i ] = gauss ( norm ( one_vert - one_xyz ) , std ) return trans
Calculate how many electrodes influence one vertex using a Gaussian function .
23,651
def _read_history ( f , zone ) : pos , length = zone f . seek ( pos , SEEK_SET ) histories = [ ] while f . tell ( ) < ( pos + length ) : history = { 'nSample' : unpack ( MAX_SAMPLE * 'I' , f . read ( MAX_SAMPLE * 4 ) ) , 'lines' : unpack ( 'H' , f . read ( 2 ) ) , 'sectors' : unpack ( 'H' , f . read ( 2 ) ) , 'base_tim...
This matches the Matlab reader from Matlab Exchange but doesn t seem correct .
23,652
def create_video ( self ) : self . instance = vlc . Instance ( ) video_widget = QFrame ( ) self . mediaplayer = self . instance . media_player_new ( ) if system ( ) == 'Linux' : self . mediaplayer . set_xwindow ( video_widget . winId ( ) ) elif system ( ) == 'Windows' : self . mediaplayer . set_hwnd ( video_widget . wi...
Create video widget .
23,653
def stop_video ( self , tick ) : if self . cnt_video == self . n_video : if tick >= self . end_diff : self . idx_button . setText ( 'Start' ) self . video . stop ( )
Stop video if tick is more than the end only for last file .
23,654
def next_video ( self , _ ) : self . cnt_video += 1 lg . info ( 'Update video to ' + str ( self . cnt_video ) )
Also runs when file is loaded so index starts at 2 .
23,655
def start_stop_video ( self ) : if self . parent . info . dataset is None : self . parent . statusBar ( ) . showMessage ( 'No Dataset Loaded' ) return if 'Start' in self . idx_button . text ( ) . replace ( '&' , '' ) : try : self . update_video ( ) except IndexError as er : lg . debug ( er ) self . idx_button . setText...
Start and stop the video and change the button .
23,656
def update_video ( self ) : window_start = self . parent . value ( 'window_start' ) window_length = self . parent . value ( 'window_length' ) d = self . parent . info . dataset videos , begsec , endsec = d . read_videos ( window_start , window_start + window_length ) lg . debug ( f'Video: {begsec} - {endsec}' ) self . ...
Read list of files convert to video time and add video to queue .
23,657
def montage ( data , ref_chan = None , ref_to_avg = False , bipolar = None , method = 'average' ) : if ref_to_avg and ref_chan is not None : raise TypeError ( 'You cannot specify reference to the average and ' 'the channels to use as reference' ) if ref_chan is not None : if ( not isinstance ( ref_chan , ( list , tuple...
Apply linear transformation to the channels .
23,658
def _assert_equal_channels ( axis ) : for i0 in axis : for i1 in axis : if not all ( i0 == i1 ) : raise ValueError ( 'The channels for all the trials should have ' 'the same labels, in the same order.' )
check that all the trials have the same channels in the same order .
23,659
def compute_average_regress ( x , idx_chan ) : if x . ndim != 2 : raise ValueError ( f'The number of dimensions must be 2, not {x.ndim}' ) x = moveaxis ( x , idx_chan , 0 ) avg = mean ( x , axis = 0 ) x_o = [ ] for i in range ( x . shape [ 0 ] ) : r = lstsq ( avg [ : , None ] , x [ i , : ] [ : , None ] , rcond = 0 ) [ ...
Take the mean across channels and regress out the mean from each channel
23,660
def keep_recent_datasets ( max_dataset_history , info = None ) : history = settings . value ( 'recent_recordings' , [ ] ) if isinstance ( history , str ) : history = [ history ] if info is not None and info . filename is not None : new_dataset = info . filename if new_dataset in history : lg . debug ( new_dataset + ' a...
Keep track of the most recent recordings .
23,661
def choose_file_or_dir ( ) : question = QMessageBox ( QMessageBox . Information , 'Open Dataset' , 'Do you want to open a file or a directory?' ) dir_button = question . addButton ( 'Directory' , QMessageBox . YesRole ) file_button = question . addButton ( 'File' , QMessageBox . NoRole ) question . addButton ( QMessage...
Create a simple message box to see if the user wants to open dir or file
23,662
def convert_name_to_color ( s ) : h = 100 v = [ 5 * ord ( x ) for x in s ] sum_mod = lambda x : sum ( x ) % 100 color = QColor ( sum_mod ( v [ : : 3 ] ) + h , sum_mod ( v [ 1 : : 3 ] ) + h , sum_mod ( v [ 2 : : 3 ] ) + h ) return color
Convert any string to an RGB color .
23,663
def freq_from_str ( freq_str ) : freq = [ ] as_list = freq_str [ 1 : - 1 ] . replace ( ' ' , '' ) . split ( ',' ) try : if freq_str [ 0 ] == '[' and freq_str [ - 1 ] == ']' : for i in as_list : one_band = i [ 1 : - 1 ] . split ( '-' ) one_band = float ( one_band [ 0 ] ) , float ( one_band [ 1 ] ) freq . append ( one_ba...
Obtain frequency ranges from input string either as list or dynamic notation .
23,664
def export_graphics_to_svg ( widget , filename ) : generator = QSvgGenerator ( ) generator . setFileName ( filename ) generator . setSize ( widget . size ( ) ) generator . setViewBox ( widget . rect ( ) ) painter = QPainter ( ) painter . begin ( generator ) widget . render ( painter ) painter . end ( )
Export graphics to svg
23,665
def get_value ( self , default = None ) : if default is None : default = [ ] try : text = literal_eval ( self . text ( ) ) if not isinstance ( text , list ) : pass except ValueError : lg . debug ( 'Cannot convert "' + str ( text ) + '" to list. ' + 'Using default ' + str ( default ) ) text = default self . set_value ( ...
Get int from widget .
23,666
def connect ( self , funct ) : def get_directory ( ) : rec = QFileDialog . getExistingDirectory ( self , 'Path to Recording' ' Directory' ) if rec == '' : return self . setText ( rec ) funct ( ) self . clicked . connect ( get_directory )
Call funct when the text was changed .
23,667
def get_value ( self , default = None ) : if default is None : default = '' try : text = self . currentText ( ) except ValueError : lg . debug ( 'Cannot convert "' + str ( text ) + '" to list. ' + 'Using default ' + str ( default ) ) text = default self . set_value ( text ) return text
Get selection from widget .
23,668
def _write_ieeg_json ( output_file ) : dataset_info = { "TaskName" : "unknown" , "Manufacturer" : "n/a" , "PowerLineFrequency" : 50 , "iEEGReference" : "n/a" , } with output_file . open ( 'w' ) as f : dump ( dataset_info , f , indent = ' ' )
Use only required fields
23,669
def value ( self , parameter , new_value = None ) : for widget_name , values in DEFAULTS . items ( ) : if parameter in values . keys ( ) : widget = getattr ( self , widget_name ) if new_value is None : return widget . config . value [ parameter ] else : lg . debug ( 'setting value {0} of {1} to {2}' '' . format ( param...
This function is a shortcut for any parameter . Instead of calling the widget its config and its values you can call directly the parameter .
23,670
def update ( self ) : self . info . display_dataset ( ) self . overview . update ( ) self . labels . update ( labels = self . info . dataset . header [ 'chan_name' ] ) self . channels . update ( ) try : self . info . markers = self . info . dataset . read_markers ( ) except FileNotFoundError : lg . info ( 'No notes/mar...
Once you open a dataset it activates all the widgets .
23,671
def reset ( self ) : max_dataset_history = self . value ( 'max_dataset_history' ) keep_recent_datasets ( max_dataset_history , self . info ) self . labels . reset ( ) self . channels . reset ( ) self . info . reset ( ) self . notes . reset ( ) self . overview . reset ( ) self . spectrum . reset ( ) self . traces . rese...
Remove all the information from previous dataset before loading a new dataset .
23,672
def show_settings ( self ) : self . notes . config . put_values ( ) self . overview . config . put_values ( ) self . settings . config . put_values ( ) self . spectrum . config . put_values ( ) self . traces . config . put_values ( ) self . video . config . put_values ( ) self . settings . show ( )
Open the Setting windows after updating the values in GUI .
23,673
def show_spindle_dialog ( self ) : self . spindle_dialog . update_groups ( ) self . spindle_dialog . update_cycles ( ) self . spindle_dialog . show ( )
Create the spindle detection dialog .
23,674
def show_slow_wave_dialog ( self ) : self . slow_wave_dialog . update_groups ( ) self . slow_wave_dialog . update_cycles ( ) self . slow_wave_dialog . show ( )
Create the SW detection dialog .
23,675
def show_event_analysis_dialog ( self ) : self . event_analysis_dialog . update_types ( ) self . event_analysis_dialog . update_groups ( ) self . event_analysis_dialog . update_cycles ( ) self . event_analysis_dialog . show ( )
Create the event analysis dialog .
23,676
def show_analysis_dialog ( self ) : self . analysis_dialog . update_evt_types ( ) self . analysis_dialog . update_groups ( ) self . analysis_dialog . update_cycles ( ) self . analysis_dialog . show ( )
Create the analysis dialog .
23,677
def closeEvent ( self , event ) : max_dataset_history = self . value ( 'max_dataset_history' ) keep_recent_datasets ( max_dataset_history , self . info ) settings . setValue ( 'window/geometry' , self . saveGeometry ( ) ) settings . setValue ( 'window/state' , self . saveState ( ) ) event . accept ( )
save the name of the last open dataset .
23,678
def _read_header ( filename ) : header = _read_header_text ( filename ) first_row = header [ 0 ] EXTRA_ROWS = 3 hdr = { } for group in finditer ( '(\w*)= ([\w.]*)' , first_row ) : hdr [ group . group ( 1 ) ] = group . group ( 2 ) if first_row . startswith ( 'BCI2000V' ) : VERSION = hdr [ 'BCI2000V' ] else : VERSION = '...
It s a pain to parse the header . It might be better to use the cpp code but I would need to include it here .
23,679
def remove_artf_evts ( times , annot , chan = None , min_dur = 0.1 ) : new_times = times beg = times [ 0 ] [ 0 ] end = times [ - 1 ] [ - 1 ] chan = ( chan , '' ) if chan else None artefact = annot . get_events ( name = 'Artefact' , time = ( beg , end ) , chan = chan , qual = 'Good' ) if artefact : new_times = [ ] for s...
Correct times to remove events marked Artefact .
23,680
def statement_ref_mode ( self , value ) : valid_values = [ 'STRICT_KEEP' , 'STRICT_KEEP_APPEND' , 'STRICT_OVERWRITE' , 'KEEP_GOOD' , 'CUSTOM' ] if value not in valid_values : raise ValueError ( 'Not an allowed reference mode, allowed values {}' . format ( ' ' . join ( valid_values ) ) ) self . _statement_ref_mode = val...
Set the reference mode for a statement always overrides the global reference state .
23,681
def equals ( self , that , include_ref = False , fref = None ) : if not include_ref : return self == that if include_ref and self != that : return False if include_ref and fref is None : fref = WDBaseDataType . refs_equal return fref ( self , that )
Tests for equality of two statements . If comparing references the order of the arguments matters!!! self is the current statement the next argument is the new statement . Allows passing in a function to use to compare the references fref . Default is equality . fref accepts two arguments oldrefs and newrefs each of wh...
23,682
def refs_equal ( olditem , newitem ) : oldrefs = olditem . references newrefs = newitem . references ref_equal = lambda oldref , newref : True if ( len ( oldref ) == len ( newref ) ) and all ( x in oldref for x in newref ) else False if len ( oldrefs ) == len ( newrefs ) and all ( any ( ref_equal ( oldref , newref ) fo...
tests for exactly identical references
23,683
def try_write ( wd_item , record_id , record_prop , login , edit_summary = '' , write = True ) : if wd_item . require_write : if wd_item . create_new_item : msg = "CREATE" else : msg = "UPDATE" else : msg = "SKIP" try : if write : wd_item . write ( login = login , edit_summary = edit_summary ) wdi_core . WDItemEngine ....
Write a PBB_core item . Log if item was created updated or skipped . Catch and log all errors .
23,684
def _build_app_dict ( site , request , label = None ) : app_dict = { } if label : models = { m : m_a for m , m_a in site . _registry . items ( ) if m . _meta . app_label == label } else : models = site . _registry for model , model_admin in models . items ( ) : app_label = model . _meta . app_label has_module_perms = m...
Builds the app dictionary . Takes an optional label parameters to filter models of a specific app .
23,685
def get_app_list ( site , request ) : app_dict = _build_app_dict ( site , request ) app_list = sorted ( app_dict . values ( ) , key = lambda x : x [ 'name' ] . lower ( ) ) for app in app_list : app [ 'models' ] . sort ( key = lambda x : x [ 'name' ] ) return app_list
Returns a sorted list of all the installed apps that have been registered in this site .
23,686
def format_query_results ( self , r , prop_nr ) : prop_dt = self . get_prop_datatype ( prop_nr ) for i in r : for value in { 'item' , 'sid' , 'pq' , 'pr' , 'ref' } : if value in i : i [ value ] = i [ value ] [ 'value' ] . split ( '/' ) [ - 1 ] for value in { 'v' , 'qval' , 'rval' } : if value in i : if i [ value ] . ge...
r is the results of the sparql query in _query_data and is modified in place prop_nr is needed to get the property datatype to determine how to format the value
23,687
def clear ( self ) : self . prop_dt_map = dict ( ) self . prop_data = dict ( ) self . rev_lookup = defaultdict ( set )
convinience function to empty this fastrun container
23,688
def times ( p , mint , maxt = None ) : maxt = maxt if maxt else mint @ Parser def times_parser ( text , index ) : cnt , values , res = 0 , Value . success ( index , [ ] ) , None while cnt < maxt : res = p ( text , index ) if res . status : values = values . aggregate ( Value . success ( res . index , [ res . value ] ) ...
Repeat a parser between mint and maxt times . DO AS MUCH MATCH AS IT CAN . Return a list of values .
23,689
def optional ( p , default_value = None ) : @ Parser def optional_parser ( text , index ) : res = p ( text , index ) if res . status : return Value . success ( res . index , res . value ) else : return Value . success ( res . index , default_value ) return optional_parser
Make a parser as optional . If success return the result otherwise return default_value silently without raising any exception . If default_value is not provided None is returned instead .
23,690
def separated ( p , sep , mint , maxt = None , end = None ) : maxt = maxt if maxt else mint @ Parser def sep_parser ( text , index ) : cnt , values , res = 0 , Value . success ( index , [ ] ) , None while cnt < maxt : if end in [ False , None ] and cnt > 0 : res = sep ( text , index ) if res . status : index , values =...
Repeat a parser p separated by s between mint and maxt times . When end is None a trailing separator is optional . When end is True a trailing separator is required . When end is False a trailing separator is not allowed . MATCHES AS MUCH AS POSSIBLE . Return list of values returned by p .
23,691
def one_of ( s ) : @ Parser def one_of_parser ( text , index = 0 ) : if index < len ( text ) and text [ index ] in s : return Value . success ( index + 1 , text [ index ] ) else : return Value . failure ( index , 'one of {}' . format ( s ) ) return one_of_parser
Parser a char from specified string .
23,692
def none_of ( s ) : @ Parser def none_of_parser ( text , index = 0 ) : if index < len ( text ) and text [ index ] not in s : return Value . success ( index + 1 , text [ index ] ) else : return Value . failure ( index , 'none of {}' . format ( s ) ) return none_of_parser
Parser a char NOT from specified string .
23,693
def space ( ) : @ Parser def space_parser ( text , index = 0 ) : if index < len ( text ) and text [ index ] . isspace ( ) : return Value . success ( index + 1 , text [ index ] ) else : return Value . failure ( index , 'one space' ) return space_parser
Parser a whitespace character .
23,694
def letter ( ) : @ Parser def letter_parser ( text , index = 0 ) : if index < len ( text ) and text [ index ] . isalpha ( ) : return Value . success ( index + 1 , text [ index ] ) else : return Value . failure ( index , 'a letter' ) return letter_parser
Parse a letter in alphabet .
23,695
def digit ( ) : @ Parser def digit_parser ( text , index = 0 ) : if index < len ( text ) and text [ index ] . isdigit ( ) : return Value . success ( index + 1 , text [ index ] ) else : return Value . failure ( index , 'a digit' ) return digit_parser
Parse a digit character .
23,696
def eof ( ) : @ Parser def eof_parser ( text , index = 0 ) : if index >= len ( text ) : return Value . success ( index , None ) else : return Value . failure ( index , 'EOF' ) return eof_parser
Parser EOF flag of a string .
23,697
def string ( s ) : @ Parser def string_parser ( text , index = 0 ) : slen , tlen = len ( s ) , len ( text ) if text [ index : index + slen ] == s : return Value . success ( index + slen , s ) else : matched = 0 while matched < slen and index + matched < tlen and text [ index + matched ] == s [ matched ] : matched = mat...
Parser a string .
23,698
def loc_info ( text , index ) : if index > len ( text ) : raise ValueError ( 'Invalid index.' ) line , last_ln = text . count ( '\n' , 0 , index ) , text . rfind ( '\n' , 0 , index ) col = index - ( last_ln + 1 ) return ( line , col )
Location of index in source code text .
23,699
def loc ( self ) : try : return '{}:{}' . format ( * ParseError . loc_info ( self . text , self . index ) ) except ValueError : return '<out of bounds index {!r}>' . format ( self . index )
Locate the error position in the source code text .