def __init__(self, infile, montage, *args, **kwargs): """Set montage and initialise EEGFile object""" if not montage in MONTAGES: msg = "Unrecognised montage: '{0}'".format(montage) raise UnrecognisedMontageError(msg) self.montage = MONTAGES[montage] EEGFile.__init__(self, infile, *args, **kwargs)
def __init__(self, chan_pars, rec_id="Generated Signals", duration=60, sample_rate=200, secsblock=5): """Generate and store header information. The EEGFile is deemed to have as many channels as there are items in chan_pars, which should be a list of dictionaries. The label for each channel is taken from chan_pars[n]['label']. """ # Generate channel header from chan_pars item def chan_from_pars(cp): return Chan(label=cp["label"], dim="uV", calib=1, offset=0, nsblock=int(secsblock * sample_rate), finfo=cp) # Initialise chan = [chan_from_pars(cp) for cp in chan_pars] descr = [(c.label, "i2", c.nsblock) for c in chan] descr = BlockDescriptor(descr) # Store self._head = Head( tstart=datetime.datetime.today(), nblocks=int(duration // secsblock), secsblock=secsblock, nchan=len(chan_pars), chan=chan, ) self._block_descriptor = descr self.nblocks = self._head.nblocks self.name = "<genfile>" # Pass self in to silence EEGFile EEGFile.__init__(self, self)
def __init__(self, eegfile, mode): """eegfile can be a path to a file or an open file object. mode should be 'r' or 'w'. 1) On Windows if the file object is either sys.stdin or sys.stdout the mode will be changed to binary using msvcrt.setmode 2) The file object must be a 'real' file object not a python 'file-like' object. 3) No other code should operate on the file. """ # Accept only real files or file paths if not isinstance(eegfile, (file, basestring)): raise TypeError("eegfile must be either 'file' or 'string'") if not mode in ['r','w']: raise ValueError("Mode should be 'r' or 'w'") # Ensure eegfile is a binary file objects if isinstance(eegfile, basestring): _mode = mode if self._binary: _mode += 'b' eegfile = open(eegfile, _mode) # stdio is in text mode by default on windows elif eegfile in STDIO: if msvcrt and self._binary: msvcrt.setmode(eegfile.fileno(), os.O_BINARY) # Don't attempt to change mode if not STDIO elif self._binary and 'b' not in eegfile.mode: raise IOError("File not opened in binary mode") # Check if file object is a pipe st = os.fstat(eegfile.fileno()) if st.st_mode & stat.S_IFIFO: seekable = False filesize = -1 else: seekable = True filesize = st.st_size # Store relevant data self.__file = eegfile self.__fp = 0 self.mode = mode self.seekable = seekable self.filesize = filesize # Store here just as in EEGFile EEGFile.__init__(self, eegfile)
def __init__(self, *args, **kwargs): EEGFile.__init__(self, *args, **kwargs) self._blocksegments = [] self._blockrefs = {} self._last_block = 0
def __init__(self, eegfile, n1, n2): self._n1 = max(n1, 0) self._n2 = n2 EEGFile.__init__(self, eegfile)