def _compute_scalings(scalings, inst):
 from ..io.base import BaseRaw
 from ..epochs import BaseEpochs
 if (not isinstance(inst, (BaseRaw, BaseEpochs))):
  raise ValueError('Must supply either Raw or Epochs')
 if (scalings is None):
  return scalings
 ch_types = channel_indices_by_type(inst.info)
 ch_types = dict([(i_type, i_ixs) for (i_type, i_ixs) in ch_types.items() if (len(i_ixs) != 0)])
 if (scalings == 'auto'):
  scalings = dict(((i_type, 'auto') for i_type in ch_types.keys()))
 if (not isinstance(scalings, dict)):
  raise ValueError(('scalings must be a dictionary of ch_type: val pairs, not type %s ' % type(scalings)))
 scalings = deepcopy(scalings)
 if (inst.preload is False):
  if isinstance(inst, BaseRaw):
   n_times = (100000000.0 // (len(inst.ch_names) * 8))
   n_times = np.clip(n_times, 1, inst.n_times)
   n_secs = (n_times / float(inst.info['sfreq']))
   time_middle = np.mean(inst.times)
   tmin = np.clip((time_middle - (n_secs / 2.0)), inst.times.min(), None)
   tmax = np.clip((time_middle + (n_secs / 2.0)), None, inst.times.max())
   data = inst._read_segment(tmin, tmax)
  elif isinstance(inst, BaseEpochs):
   n_epochs = (100000000.0 // ((len(inst.ch_names) * len(inst.times)) * 8))
   n_epochs = int(np.clip(n_epochs, 1, len(inst)))
   ixs_epochs = np.random.choice(range(len(inst)), n_epochs, False)
   inst = inst.copy()[ixs_epochs].load_data()
 else:
  data = inst._data
 if isinstance(inst, BaseEpochs):
  data = inst._data.reshape([len(inst.ch_names), (-1)])
 for (key, value) in scalings.items():
  if (value != 'auto'):
   continue
  if (key not in ch_types.keys()):
   raise ValueError("Sensor {0} doesn't exist in data".format(key))
  this_data = data[ch_types[key]]
  scale_factor = np.percentile(this_data.ravel(), [0.5, 99.5])
  scale_factor = np.max(np.abs(scale_factor))
  scalings[key] = scale_factor
 return scalings

def _compute_scalings ( scalings , inst ) : from . . io . base import BaseRaw from . . epochs import BaseEpochs if ( not isinstance ( inst , ( BaseRaw , BaseEpochs ) ) ) : raise ValueError ( 'Must supply either Raw or Epochs' ) if ( scalings is None ) : return scalings ch_types = channel_indices_by_type ( inst . info ) ch_types = dict ( [ ( i_type , i_ixs ) for ( i_type , i_ixs ) in ch_types . items ( ) if ( len ( i_ixs ) != 0 ) ] ) if ( scalings == 'auto' ) : scalings = dict ( ( ( i_type , 'auto' ) for i_type in ch_types . keys ( ) ) ) if ( not isinstance ( scalings , dict ) ) : raise ValueError ( ( 'scalings must be a dictionary of ch_type: val pairs, not type %s ' % type ( scalings ) ) ) scalings = deepcopy ( scalings ) if ( inst . preload is False ) : if isinstance ( inst , BaseRaw ) : n_times = ( 100000000.0 // ( len ( inst . ch_names ) * 8 ) ) n_times = np . clip ( n_times , 1 , inst . n_times ) n_secs = ( n_times / float ( inst . info [ 'sfreq' ] ) ) time_middle = np . mean ( inst . times ) tmin = np . clip ( ( time_middle - ( n_secs / 2.0 ) ) , inst . times . min ( ) , None ) tmax = np . clip ( ( time_middle + ( n_secs / 2.0 ) ) , None , inst . times . max ( ) ) data = inst . _read_segment ( tmin , tmax ) elif isinstance ( inst , BaseEpochs ) : n_epochs = ( 100000000.0 // ( ( len ( inst . ch_names ) * len ( inst . times ) ) * 8 ) ) n_epochs = int ( np . clip ( n_epochs , 1 , len ( inst ) ) ) ixs_epochs = np . random . choice ( range ( len ( inst ) ) , n_epochs , False ) inst = inst . copy ( ) [ ixs_epochs ] . load_data ( ) else : data = inst . _data if isinstance ( inst , BaseEpochs ) : data = inst . _data . reshape ( [ len ( inst . ch_names ) , ( - 1 ) ] ) for ( key , value ) in scalings . items ( ) : if ( value != 'auto' ) : continue if ( key not in ch_types . keys ( ) ) : raise ValueError ( "Sensor {0} doesn't exist in data" . format ( key ) ) this_data = data [ ch_types [ key ] ] scale_factor = np . percentile ( this_data . ravel ( ) , [ 0.5 , 99.5 ] ) scale_factor = np . max ( np . abs ( scale_factor ) ) scalings [ key ] = scale_factor return scalings
compute scale factors for a unified plot .