def kit2fiff(meg_sdir=None, sfreq=250, aligntol=25, **more_kwargs): """ Reads multiple input files and combines them into a fiff file that can be used with mne. Implemented after Gwyneth's Manual Arguments: sfreq : scalar samplingrate of the data meg_sdir : path(str) Path to the subjects's meg directory. If ``None``, a file dialog is displayed to ask for the directory. more_kwargs : more keyword arguments (see MNE manual p. 224) e.g., ``lowpass`` """ if meg_sdir is None: msg = "Select Subject's Meg Directory" meg_sdir = ui.ask_dir(msg, msg, True) param_dir = os.path.join(meg_sdir, 'parameters') assert os.path.exists(param_dir) subject = os.path.basename(meg_sdir) mapath = os.path.join(param_dir, '%s_eref3_markers_average.txt' % subject) mafile = marker_avg_file(mapath) elp_file = os.path.join(param_dir, '%s_eref3_electrodes.elp' % subject) hsp_file = os.path.join(param_dir, '%s_eref3_headshape.hsp' % subject) hpi_file = mafile.path sns_file = '~/Documents/Eclipse/Eelbrain\ Reloaded/aux_files/sns.txt' data_file = '~/Documents/Data/eref/meg/R0368/data/%s_eref3_exported.txt' % subject out_file = os.path.join(meg_sdir, 'myfif', '%s_raw.fif' % subject) kwargs = {'elp': elp_file, 'hsp': hsp_file, 'sns': sns_file, 'hpi': hpi_file, 'raw': data_file, 'out': out_file, 'stim': '161:162:163:164:165:166:167:168', 'sfreq': sfreq, 'aligntol': aligntol} kwargs.update(more_kwargs) _run('mne_kit2fiff', kwargs)
def _export(self, address, format='txt', sensors=slice(None)): """ .. WARNING:: METHOD NOT MAINTAINED Possible values for format: 'txt': export tsv files to folder (ask) 'names': print a list of filenames ordered for 2 vars in address """ segDict = address.dict( self.segments ) dictKey = address.keys() if format == 'txt': folder = ui.ask_dir('target dir: ') if folder == False: raise IOError("no valid target directory") for index, segments in segDict.iteritems(): data = np.vstack([s.data for s in segments]) name = '_'.join([ var.name+'-'+var[v] for var,v in zip(dictKey, index) ]) filename = folder + name +'.txt' np.savetxt(filename, data, delimiter='\t') elif format == 'names': if len(dictKey)!=2: raise NotImplementedError d0=[]; d1=[]; names={} for index in segDict.keys(): if index[0] not in d0: d0.append(index[0]) if index[1] not in d1: d1.append(index[1]) if index not in names: names[index]= '_'.join([var.name+'-'+var[v] for var,v in \ zip(dictKey, index)]+['.txt']) txt=['\t'] for i1 in d1: txt.append( dictKey[1][i1]+'\t' ) for i0 in d0: txt.append('\n'+dictKey[0][i0]+'\t') for i1 in d1: txt.append(names[(i0,i1)]+'\t') print ''.join(txt)
def set(self, path=None): """ path can be file or directory if path==None: a dialog will be displayed to select a directory (use .set_ext('ext') method to modify file extension) """ if path is None: path = ui.ask_dir() if not path: return if isinstance(path, basestring): if os.path.isdir(path): self._value['d'].append(path) elif os.path.exists(path): self._value['f'].append(path) else: raise IOError("%s does not exists"%path) self._changed() else: raise ValueError("must be string")
def OnInsertPath(self, event, t=None): if t is None: t = event.GetSelection() # get if t == 0: # File filenames = ui.ask_file(mult=True) elif t == 1: # Dir filenames = ui.ask_dir() elif t == 2: # New filenames = ui.ask_saveas(title = "Get New File Name", message = "Please Pick a File Name", ext = None) # put to terminal if filenames: if len(filenames) == 1: filenames = '"'+filenames[0]+'"' else: filenames = '"'+str(filenames)+'"' if 'wxMSW' in wx.PlatformInfo: filenames = 'r'+filenames self.InsertStr(filenames)
def set_bin_dir(package): """ Change the location from which binaries are used. package : str Binary package for which to set the directory. One from: ``['mne', 'freesurfer', 'edfapi']`` """ have_valid_path = False while not have_valid_path: title = "Select %r bin Directory" % package message = ("Please select the directory containing the binaries for " "the %r package." % package) answer = ui.ask_dir(title, message, must_exist=True) if answer: if _is_bin_path(package, answer): _bin_dirs[package] = answer pickle.dump(_bin_dirs, open(_cfg_path, 'w')) _set_bin_dirs(**{package: answer}) have_valid_path = True else: raise IOError("%r bin directory not set" % package)