Exemplo n.º 1
0
 def set_zoom(self, events_ds=None, address=None, pad=10):
     """
     Set the time range of the data that is displayed based on events.
     
     events_ds : 
         index of vizualizer/dataset containing events (None to 
         reset zoom and show all data)
     address : 
         event-address of events to display
     pad: scalar
         time to display outside of events
     
     
     **See also:** .set_window()
     
     """
     if events_ds is not None:
         v = self.visualizers[events_ds]
         ds = v.dataset
         if ds.properties['data_type'] != 'event':
             ui.message("'%s' is not an event dataset!"%ds.name, "", '!')
             return
     self._zoom_events = events_ds
     self._zoom_address = address
     self._zoom_pad = pad
     self._zoom_window = None
     self.OnRefresh(None)
Exemplo n.º 2
0
 def read_example_file(self, path):
     self._example_path = path
     if path == None:
         self.p.channels._set_n_channels(0)
         self._example_data = None
         self._example_prop = None
     else:
         data, properties = self.get_file(path)
         assert data.ndim == 2, "get_file returned invalid data"
         t, n = data.shape
         # save example
         properties['dtype'] = data.dtype
         self._example_data = data
         self._example_prop = properties
         
         # use example properties to set p
         self.p.channels._set_n_channels(n)
         if 'samplingrate' in properties:
             new_sr = properties['samplingrate']
             old_sr = self.p.samplingrate.get()
             if old_sr != new_sr and bool(new_sr):
                 self.p.samplingrate(new_sr)
                 ui.message("Samplingrate updated %s Hz -> %s Hz"%(old_sr, new_sr),
                            "The importer's samplingrate parameter has been "
                            "updated based on the file's properties.")
Exemplo n.º 3
0
    def _OnThreshold(self, event):
        """
        above: True, False, None
            how to mark segments that exceed the threshold: True->good;
            False->bad; None->don't change
        below:
            same as ``above`` but for segments that do not exceed the threshold

        """
        threshold = None
        above = False
        below = True

        msg = "What value should be used to threshold the data?"
        while threshold is None:
            dlg = wx.TextEntryDialog(self, msg, "Choose Threshold", "2e-12")
            if dlg.ShowModal() == wx.ID_OK:
                value = dlg.GetValue()
                try:
                    threshold = float(value)
                except ValueError:
                    ui.message("Invalid Entry", "%r is not a valid entry. Need "
                               "a float." % value, '!')
            else:
                return

        process.mark_by_threshold(self._dataset, DV=self._data,
                                  threshold=threshold, above=above,
                                  below=below, target=self._target)

        self._Refresh(event)
Exemplo n.º 4
0
def _is_bin_path(package, path):
    if package == 'mne':
        test = ['mne_add_patch_info', 'mne_analyze']
    elif package == 'freesurfer':
        test = ['mri_annotation2label']
    elif package == 'edfapi':
        test = ['edf2asc']
    else:
        raise KeyError("Unknown package: %r" % package)

    test_paths = [os.path.join(path, testname) for testname in test]
    if all(map(os.path.exists, test_paths)):
        return True
    else:
        msg = ("You need to select a directory containing the following "
               "executables: %r" % test)
        ui.message("Invalid Binary Directory", msg, 'error')
Exemplo n.º 5
0
 def OnCopyTextab(self, event=None):
     try:
         fmtxt.copy_pdf()
     except Exception as e:
         ui.message("Error in Copy Tex", str(e), '!')
Exemplo n.º 6
0
    def plot(self, fig_num=None):#, tmax=1000):
        if self._example_path == None:
            ui.message("No files specified", "Before an import preview can be "
                       "plotted, at least one source file has "
                       "to be specified through the p.source parameter.", '!')
            return
        
        data = self._example_data#[:tmax]
        
        # range correct data
        t, n = data.shape
        data = data - np.min(data, 0)
        data /= np.max(data, 0) * 1.1
        data += np.arange(n-1, -1, -1) # channel 1 on the top
        
        # collect properties
        name = os.path.basename(self._example_path)
        samplingrate = self.p.samplingrate.get()
        T = np.arange(0, t)
        if samplingrate:
            T /= samplingrate
        
        # start plot
        P.figure(fig_num)
        P.subplots_adjust(.2, .05, .99, .9)
        P.suptitle("Example: %s"%fmtxt.texify(name))
        ax = P.axes()
        lines = [ax.plot(data[:,i], c='.75', antialiased=False)[0] for i in xrange(n)]
        y_ticks = np.arange(n-1, -1, -1) + .45
        y_ticklabels = range(n)        
        # get channels data
        for index, settings in self.p.channels.iterchannels():
#            ax = P.subplot(n, 1, i+1, sharex=ax)
            name, ds_type, arg1, arg2 = settings
            
#            y_ticklabels.append(name)
            if isinstance(index, int):
                ls = [lines[index]]
                y_ticklabels[index] = name
#                y_ticks.append(i)
            else:
                if isinstance(index, slice):
                    start, stop = index.start, index.stop
                    ls = lines[index]
                    indexes = xrange(start+1, stop+1)
                else:
                    start = index[0]
                    indexes = index[1:]
                    ls = [lines[i] for i in index]
                y_ticklabels[start] = name
                for i in indexes:
                    y_ticklabels[i] = ''
#                tick_y = start + (stop-start)//2
#                y_ticks.append(tick_y)
            
            if ds_type == 'uts':
                c = 'k'
            elif ds_type == 'topo':
                c = 'r'
            elif ds_type == 'evt':
                c = 'b'
            
            for l in ls:
                l.set_color(c)
        
        if hasattr(ax, 'tick_params'):
            ax.tick_params(axis='y', length=0)
        
        ax.set_xlim(0, len(data))
        ax.set_yticks(y_ticks)
        ax.set_yticklabels(y_ticklabels)
#        ax.set_xlim(T[0], T[-1])
#        ax.set_xlim(0, tmax)
        P.show()