<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from . import backend as global_backend <EOL> from . varica import mvarica , cspvarica <EOL> from . plainica import plainica <EOL> from . datatools import dot_special , atleast_3d <EOL> from . connectivity import Connectivity <EOL> from . connectivity_statistics import surrogate_connectivity , bootstrap_connectivity , test_bootstrap_difference <EOL> from . connectivity_statistics import significance_fdr <EOL> class Workspace ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , var , locations = None , reducedim = None , nfft = <NUM_LIT> , fs = <NUM_LIT:2> , backend = None ) : <EOL> self . data_ = None <EOL> self . cl_ = None <EOL> self . fs_ = fs <EOL> self . time_offset_ = <NUM_LIT:0> <EOL> self . unmixing_ = None <EOL> self . mixing_ = None <EOL> self . premixing_ = None <EOL> self . activations_ = None <EOL> self . connectivity_ = None <EOL> self . locations_ = locations <EOL> self . reducedim_ = reducedim <EOL> self . nfft_ = nfft <EOL> self . backend_ = backend if backend is not None else global_backend <EOL> self . trial_mask_ = [ ] <EOL> self . topo_ = None <EOL> self . mixmaps_ = [ ] <EOL> self . unmixmaps_ = [ ] <EOL> self . var_multiclass_ = None <EOL> self . var_model_ = None <EOL> self . var_cov_ = None <EOL> self . plot_diagonal = '<STR_LIT>' <EOL> self . plot_outside_topo = False <EOL> self . plot_f_range = [ <NUM_LIT:0> , fs / <NUM_LIT:2> ] <EOL> self . topo_clipping = "<STR_LIT>" <EOL> self . _plotting = None <EOL> try : <EOL> self . var_ = self . backend_ [ '<STR_LIT>' ] ( ** var ) <EOL> except TypeError : <EOL> self . var_ = var <EOL> def __str__ ( self ) : <EOL> if self . data_ is not None : <EOL> datastr = '<STR_LIT>' % self . data_ . shape <EOL> else : <EOL> datastr = '<STR_LIT:None>' <EOL> if self . cl_ is not None : <EOL> clstr = str ( np . unique ( self . cl_ ) ) <EOL> else : <EOL> clstr = '<STR_LIT:None>' <EOL> if self . unmixing_ is not None : <EOL> sourcestr = str ( self . unmixing_ . shape [ <NUM_LIT:1> ] ) <EOL> else : <EOL> sourcestr = '<STR_LIT:None>' <EOL> if self . var_ is None : <EOL> varstr = '<STR_LIT:None>' <EOL> else : <EOL> varstr = str ( self . var_ ) <EOL> s = '<STR_LIT>' <EOL> s += '<STR_LIT>' + datastr + '<STR_LIT:\n>' <EOL> s += '<STR_LIT>' + clstr + '<STR_LIT:\n>' <EOL> s += '<STR_LIT>' + sourcestr + '<STR_LIT:\n>' <EOL> s += '<STR_LIT>' + varstr + '<STR_LIT:\n>' <EOL> return s <EOL> def set_locations ( self , locations ) : <EOL> """<STR_LIT>""" <EOL> self . locations_ = locations <EOL> return self <EOL> def set_premixing ( self , premixing ) : <EOL> """<STR_LIT>""" <EOL> self . premixing_ = premixing <EOL> return self <EOL> def set_data ( self , data , cl = None , time_offset = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . data_ = atleast_3d ( data ) <EOL> self . cl_ = np . asarray ( cl if cl is not None else [ None ] * self . data_ . shape [ <NUM_LIT:0> ] ) <EOL> self . time_offset_ = time_offset <EOL> self . var_model_ = None <EOL> self . var_cov_ = None <EOL> self . connectivity_ = None <EOL> self . trial_mask_ = np . ones ( self . cl_ . size , dtype = bool ) <EOL> if self . unmixing_ is not None : <EOL> self . activations_ = dot_special ( self . unmixing_ . T , self . data_ ) <EOL> return self <EOL> def set_used_labels ( self , labels ) : <EOL> """<STR_LIT>""" <EOL> mask = np . zeros ( self . cl_ . size , dtype = bool ) <EOL> for l in labels : <EOL> mask = np . logical_or ( mask , self . cl_ == l ) <EOL> self . trial_mask_ = mask <EOL> return self <EOL> def do_mvarica ( self , varfit = '<STR_LIT>' , random_state = None ) : <EOL> """<STR_LIT>""" <EOL> if self . data_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> result = mvarica ( x = self . data_ [ self . trial_mask_ , : , : ] , <EOL> cl = self . cl_ [ self . trial_mask_ ] , var = self . var_ , <EOL> reducedim = self . reducedim_ , backend = self . backend_ , <EOL> varfit = varfit , random_state = random_state ) <EOL> self . mixing_ = result . mixing <EOL> self . unmixing_ = result . unmixing <EOL> self . var_ = result . b <EOL> self . connectivity_ = Connectivity ( result . b . coef , result . b . rescov , <EOL> self . nfft_ ) <EOL> self . activations_ = dot_special ( self . unmixing_ . T , self . data_ ) <EOL> self . mixmaps_ = [ ] <EOL> self . unmixmaps_ = [ ] <EOL> return self <EOL> def do_cspvarica ( self , varfit = '<STR_LIT>' , random_state = None ) : <EOL> """<STR_LIT>""" <EOL> if self . data_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> try : <EOL> sorted ( self . cl_ ) <EOL> for c in self . cl_ : <EOL> assert ( c is not None ) <EOL> except ( TypeError , AssertionError ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> result = cspvarica ( x = self . data_ , var = self . var_ , cl = self . cl_ , <EOL> reducedim = self . reducedim_ , backend = self . backend_ , <EOL> varfit = varfit , random_state = random_state ) <EOL> self . mixing_ = result . mixing <EOL> self . unmixing_ = result . unmixing <EOL> self . var_ = result . b <EOL> self . connectivity_ = Connectivity ( self . var_ . coef , self . var_ . rescov , self . nfft_ ) <EOL> self . activations_ = dot_special ( self . unmixing_ . T , self . data_ ) <EOL> self . mixmaps_ = [ ] <EOL> self . unmixmaps_ = [ ] <EOL> return self <EOL> def do_ica ( self , random_state = None ) : <EOL> """<STR_LIT>""" <EOL> if self . data_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> result = plainica ( x = self . data_ [ self . trial_mask_ , : , : ] , reducedim = self . reducedim_ , backend = self . backend_ , random_state = random_state ) <EOL> self . mixing_ = result . mixing <EOL> self . unmixing_ = result . unmixing <EOL> self . activations_ = dot_special ( self . unmixing_ . T , self . data_ ) <EOL> self . var_model_ = None <EOL> self . var_cov_ = None <EOL> self . connectivity_ = None <EOL> self . mixmaps_ = [ ] <EOL> self . unmixmaps_ = [ ] <EOL> return self <EOL> def remove_sources ( self , sources ) : <EOL> """<STR_LIT>""" <EOL> if self . unmixing_ is None or self . mixing_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> self . mixing_ = np . delete ( self . mixing_ , sources , <NUM_LIT:0> ) <EOL> self . unmixing_ = np . delete ( self . unmixing_ , sources , <NUM_LIT:1> ) <EOL> if self . activations_ is not None : <EOL> self . activations_ = np . delete ( self . activations_ , sources , <NUM_LIT:1> ) <EOL> self . var_model_ = None <EOL> self . var_cov_ = None <EOL> self . connectivity_ = None <EOL> self . mixmaps_ = [ ] <EOL> self . unmixmaps_ = [ ] <EOL> return self <EOL> def keep_sources ( self , keep ) : <EOL> """<STR_LIT>""" <EOL> if self . unmixing_ is None or self . mixing_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> n_sources = self . mixing_ . shape [ <NUM_LIT:0> ] <EOL> self . remove_sources ( np . setdiff1d ( np . arange ( n_sources ) , np . array ( keep ) ) ) <EOL> return self <EOL> def fit_var ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . activations_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> self . var_ . fit ( data = self . activations_ [ self . trial_mask_ , : , : ] ) <EOL> self . connectivity_ = Connectivity ( self . var_ . coef , self . var_ . rescov , self . nfft_ ) <EOL> return self <EOL> def optimize_var ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . activations_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> self . var_ . optimize ( self . activations_ [ self . trial_mask_ , : , : ] ) <EOL> return self <EOL> def get_connectivity ( self , measure_name , plot = False ) : <EOL> """<STR_LIT>""" <EOL> if self . connectivity_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> cm = getattr ( self . connectivity_ , measure_name ) ( ) <EOL> cm = np . abs ( cm ) if np . any ( np . iscomplex ( cm ) ) else cm <EOL> if plot is None or plot : <EOL> fig = plot <EOL> if self . plot_diagonal == '<STR_LIT>' : <EOL> diagonal = <NUM_LIT:0> <EOL> elif self . plot_diagonal == '<STR_LIT:S>' : <EOL> diagonal = - <NUM_LIT:1> <EOL> sm = np . abs ( self . connectivity_ . S ( ) ) <EOL> sm /= np . max ( sm ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( sm , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = <NUM_LIT:1> , border = self . plot_outside_topo , fig = fig ) <EOL> else : <EOL> diagonal = - <NUM_LIT:1> <EOL> fig = self . plotting . plot_connectivity_spectrum ( cm , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = diagonal , border = self . plot_outside_topo , fig = fig ) <EOL> return cm , fig <EOL> return cm <EOL> def get_surrogate_connectivity ( self , measure_name , repeats = <NUM_LIT:100> , plot = False , random_state = None ) : <EOL> """<STR_LIT>""" <EOL> cs = surrogate_connectivity ( measure_name , self . activations_ [ : , : , self . trial_mask_ ] , <EOL> self . var_ , self . nfft_ , repeats , random_state = random_state ) <EOL> if plot is None or plot : <EOL> fig = plot <EOL> if self . plot_diagonal == '<STR_LIT>' : <EOL> diagonal = <NUM_LIT:0> <EOL> elif self . plot_diagonal == '<STR_LIT:S>' : <EOL> diagonal = - <NUM_LIT:1> <EOL> sb = self . get_surrogate_connectivity ( '<STR_LIT>' , repeats ) <EOL> sb /= np . max ( sb ) <EOL> su = np . percentile ( sb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ su ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = <NUM_LIT:1> , border = self . plot_outside_topo , fig = fig ) <EOL> else : <EOL> diagonal = - <NUM_LIT:1> <EOL> cu = np . percentile ( cs , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ cu ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = diagonal , border = self . plot_outside_topo , fig = fig ) <EOL> return cs , fig <EOL> return cs <EOL> def get_bootstrap_connectivity ( self , measure_names , repeats = <NUM_LIT:100> , num_samples = None , plot = False , random_state = None ) : <EOL> """<STR_LIT>""" <EOL> if num_samples is None : <EOL> num_samples = np . sum ( self . trial_mask_ ) <EOL> cb = bootstrap_connectivity ( measure_names , self . activations_ [ self . trial_mask_ , : , : ] , <EOL> self . var_ , self . nfft_ , repeats , num_samples , random_state = random_state ) <EOL> if plot is None or plot : <EOL> fig = plot <EOL> if self . plot_diagonal == '<STR_LIT>' : <EOL> diagonal = <NUM_LIT:0> <EOL> elif self . plot_diagonal == '<STR_LIT:S>' : <EOL> diagonal = - <NUM_LIT:1> <EOL> sb = self . get_bootstrap_connectivity ( '<STR_LIT>' , repeats , num_samples ) <EOL> sb /= np . max ( sb ) <EOL> sm = np . median ( sb , axis = <NUM_LIT:0> ) <EOL> sl = np . percentile ( sb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> su = np . percentile ( sb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ sm , sl , su ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = <NUM_LIT:1> , border = self . plot_outside_topo , fig = fig ) <EOL> else : <EOL> diagonal = - <NUM_LIT:1> <EOL> cm = np . median ( cb , axis = <NUM_LIT:0> ) <EOL> cl = np . percentile ( cb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> cu = np . percentile ( cb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ cm , cl , cu ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = diagonal , border = self . plot_outside_topo , fig = fig ) <EOL> return cb , fig <EOL> return cb <EOL> def get_tf_connectivity ( self , measure_name , winlen , winstep , plot = False , baseline = None , crange = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> if self . activations_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> _ , m , n = self . activations_ . shape <EOL> steps = list ( range ( <NUM_LIT:0> , n - winlen , winstep ) ) <EOL> nstep = len ( steps ) <EOL> result = np . zeros ( ( m , m , self . nfft_ , nstep ) , np . complex64 ) <EOL> for i , j in enumerate ( steps ) : <EOL> win = np . arange ( winlen ) + j <EOL> data = self . activations_ [ : , : , win ] <EOL> data = data [ self . trial_mask_ , : , : ] <EOL> self . var_ . fit ( data ) <EOL> con = Connectivity ( self . var_ . coef , self . var_ . rescov , self . nfft_ ) <EOL> result [ : , : , : , i ] = getattr ( con , measure_name ) ( ) <EOL> if baseline : <EOL> inref = np . zeros ( nstep , bool ) <EOL> for i , j in enumerate ( steps ) : <EOL> a , b = j , j + winlen - <NUM_LIT:1> <EOL> inref [ i ] = b >= baseline [ <NUM_LIT:0> ] and a <= baseline [ <NUM_LIT:1> ] <EOL> if np . any ( inref ) : <EOL> ref = np . mean ( result [ : , : , : , inref ] , axis = <NUM_LIT:3> , keepdims = True ) <EOL> result -= ref <EOL> if plot is None or plot : <EOL> fig = plot <EOL> t0 = <NUM_LIT:0.5> * winlen / self . fs_ + self . time_offset_ <EOL> t1 = self . data_ . shape [ <NUM_LIT:2> ] / self . fs_ - <NUM_LIT:0.5> * winlen / self . fs_ + self . time_offset_ <EOL> if self . plot_diagonal == '<STR_LIT>' : <EOL> diagonal = <NUM_LIT:0> <EOL> elif self . plot_diagonal == '<STR_LIT:S>' : <EOL> diagonal = - <NUM_LIT:1> <EOL> s = np . abs ( self . get_tf_connectivity ( '<STR_LIT:S>' , winlen , winstep ) ) <EOL> if crange == '<STR_LIT:default>' : <EOL> crange = [ np . min ( s ) , np . max ( s ) ] <EOL> fig = self . plotting . plot_connectivity_timespectrum ( s , fs = self . fs_ , crange = [ np . min ( s ) , np . max ( s ) ] , <EOL> freq_range = self . plot_f_range , time_range = [ t0 , t1 ] , <EOL> diagonal = <NUM_LIT:1> , border = self . plot_outside_topo , fig = fig ) <EOL> else : <EOL> diagonal = - <NUM_LIT:1> <EOL> tfc = self . _clean_measure ( measure_name , result ) <EOL> if crange == '<STR_LIT:default>' : <EOL> if diagonal == - <NUM_LIT:1> : <EOL> for m in range ( tfc . shape [ <NUM_LIT:0> ] ) : <EOL> tfc [ m , m , : , : ] = <NUM_LIT:0> <EOL> crange = [ np . min ( tfc ) , np . max ( tfc ) ] <EOL> fig = self . plotting . plot_connectivity_timespectrum ( tfc , fs = self . fs_ , crange = crange , <EOL> freq_range = self . plot_f_range , time_range = [ t0 , t1 ] , <EOL> diagonal = diagonal , border = self . plot_outside_topo , fig = fig ) <EOL> return result , fig <EOL> return result <EOL> def compare_conditions ( self , labels1 , labels2 , measure_name , alpha = <NUM_LIT> , repeats = <NUM_LIT:100> , num_samples = None , plot = False , random_state = None ) : <EOL> """<STR_LIT>""" <EOL> self . set_used_labels ( labels1 ) <EOL> ca = self . get_bootstrap_connectivity ( measure_name , repeats , num_samples , random_state = random_state ) <EOL> self . set_used_labels ( labels2 ) <EOL> cb = self . get_bootstrap_connectivity ( measure_name , repeats , num_samples , random_state = random_state ) <EOL> p = test_bootstrap_difference ( ca , cb ) <EOL> s = significance_fdr ( p , alpha ) <EOL> if plot is None or plot : <EOL> fig = plot <EOL> if self . plot_diagonal == '<STR_LIT>' : <EOL> diagonal = - <NUM_LIT:1> <EOL> elif self . plot_diagonal == '<STR_LIT>' : <EOL> diagonal = <NUM_LIT:0> <EOL> elif self . plot_diagonal is '<STR_LIT:S>' : <EOL> diagonal = - <NUM_LIT:1> <EOL> self . set_used_labels ( labels1 ) <EOL> sa = self . get_bootstrap_connectivity ( '<STR_LIT>' , repeats , num_samples ) <EOL> sm = np . median ( sa , axis = <NUM_LIT:0> ) <EOL> sl = np . percentile ( sa , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> su = np . percentile ( sa , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ sm , sl , su ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = <NUM_LIT:1> , border = self . plot_outside_topo , fig = fig ) <EOL> self . set_used_labels ( labels2 ) <EOL> sb = self . get_bootstrap_connectivity ( '<STR_LIT>' , repeats , num_samples ) <EOL> sm = np . median ( sb , axis = <NUM_LIT:0> ) <EOL> sl = np . percentile ( sb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> su = np . percentile ( sb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ sm , sl , su ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = <NUM_LIT:1> , border = self . plot_outside_topo , fig = fig ) <EOL> p_s = test_bootstrap_difference ( ca , cb ) <EOL> s_s = significance_fdr ( p_s , alpha ) <EOL> self . plotting . plot_connectivity_significance ( s_s , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = <NUM_LIT:1> , border = self . plot_outside_topo , fig = fig ) <EOL> else : <EOL> diagonal = - <NUM_LIT:1> <EOL> cm = np . median ( ca , axis = <NUM_LIT:0> ) <EOL> cl = np . percentile ( ca , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> cu = np . percentile ( ca , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ cm , cl , cu ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = diagonal , border = self . plot_outside_topo , fig = fig ) <EOL> cm = np . median ( cb , axis = <NUM_LIT:0> ) <EOL> cl = np . percentile ( cb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> cu = np . percentile ( cb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ cm , cl , cu ] , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = diagonal , border = self . plot_outside_topo , fig = fig ) <EOL> self . plotting . plot_connectivity_significance ( s , fs = self . fs_ , freq_range = self . plot_f_range , <EOL> diagonal = diagonal , border = self . plot_outside_topo , fig = fig ) <EOL> return p , s , fig <EOL> return p , s <EOL> def show_plots ( self ) : <EOL> """<STR_LIT>""" <EOL> self . plotting . show_plots ( ) <EOL> def plot_source_topos ( self , common_scale = None ) : <EOL> """<STR_LIT>""" <EOL> if self . unmixing_ is None and self . mixing_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> self . _prepare_plots ( True , True ) <EOL> self . plotting . plot_sources ( self . topo_ , self . mixmaps_ , self . unmixmaps_ , common_scale ) <EOL> def plot_connectivity_topos ( self , fig = None ) : <EOL> """<STR_LIT>""" <EOL> self . _prepare_plots ( True , False ) <EOL> if self . plot_outside_topo : <EOL> fig = self . plotting . plot_connectivity_topos ( '<STR_LIT>' , self . topo_ , self . mixmaps_ , fig ) <EOL> elif self . plot_diagonal == '<STR_LIT>' : <EOL> fig = self . plotting . plot_connectivity_topos ( '<STR_LIT>' , self . topo_ , self . mixmaps_ , fig ) <EOL> return fig <EOL> def plot_connectivity_surrogate ( self , measure_name , repeats = <NUM_LIT:100> , fig = None ) : <EOL> """<STR_LIT>""" <EOL> cb = self . get_surrogate_connectivity ( measure_name , repeats ) <EOL> self . _prepare_plots ( True , False ) <EOL> cu = np . percentile ( cb , <NUM_LIT> , axis = <NUM_LIT:0> ) <EOL> fig = self . plotting . plot_connectivity_spectrum ( [ cu ] , self . fs_ , freq_range = self . plot_f_range , fig = fig ) <EOL> return fig <EOL> @ property <EOL> def plotting ( self ) : <EOL> if not self . _plotting : <EOL> from . import plotting <EOL> self . _plotting = plotting <EOL> return self . _plotting <EOL> def _prepare_plots ( self , mixing = False , unmixing = False ) : <EOL> if self . locations_ is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> if self . topo_ is None : <EOL> from scot . eegtopo . topoplot import Topoplot <EOL> self . topo_ = Topoplot ( clipping = self . topo_clipping ) <EOL> self . topo_ . set_locations ( self . locations_ ) <EOL> if mixing and not self . mixmaps_ : <EOL> premix = self . premixing_ if self . premixing_ is not None else np . eye ( self . mixing_ . shape [ <NUM_LIT:1> ] ) <EOL> self . mixmaps_ = self . plotting . prepare_topoplots ( self . topo_ , np . dot ( self . mixing_ , premix ) ) <EOL> if unmixing and not self . unmixmaps_ : <EOL> preinv = np . linalg . pinv ( self . premixing_ ) if self . premixing_ is not None else np . eye ( self . unmixing_ . shape [ <NUM_LIT:0> ] ) <EOL> self . unmixmaps_ = self . plotting . prepare_topoplots ( self . topo_ , np . dot ( preinv , self . unmixing_ ) . T ) <EOL> @ staticmethod <EOL> def _clean_measure ( measure , a ) : <EOL> if measure in [ '<STR_LIT:a>' , '<STR_LIT:H>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return np . abs ( a ) <EOL> elif measure in [ '<STR_LIT:S>' , '<STR_LIT:g>' ] : <EOL> return np . log ( np . abs ( a ) ) <EOL> else : <EOL> return np . real ( a ) </s>
