Skip to content

Commit

Permalink
ENH/WIP: Alternative Constructor for getting new Raw instances from e…
Browse files Browse the repository at this point in the history
…xisting plus modified data

- use case #1 mixing of ica denoised data
- use case #2 other filtering operations
- use case #3 'ABC' for reading in externally processed data

I added assert statement that makes sure the dimensionality of the external data and the original fiff is compatible.

What do you think on this?
  • Loading branch information
dengemann committed Oct 8, 2012
1 parent ce029f6 commit 7b733ab
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions mne/fiff/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import numpy as np
from scipy.signal import hilbert
from copy import deepcopy

from .constants import FIFF
from .open import fiff_open
Expand Down Expand Up @@ -903,6 +904,58 @@ def _update_projector(self):
return False


class RawFromMerge(Raw):
""" Initializes new raw instance from exisiting raw and custom data
Paramerters
-----------
raw : instance of mne.fiff.Raw
existing raw instance
data : instance of numpy.core.ndarray
processed data matching the data contained by raw
Attributes
----------
See __doc__ of mne.fiff.Raw
"""
def __init__(self, raw, data, info=None):

print 'Initializing raw object from merge with custom data.'

ntsl = (raw.last_samp - raw.first_samp) + 1
nchan = len(raw.ch_names)
assert (nchan, ntsl) == data.shape

raw = deepcopy(raw)
if info == None:
info = raw.info

self.info = info
self._data = data
self.first_samp, self.last_samp = raw.first_samp, raw.last_samp
cals = np.zeros(info['nchan'])
for k in range(info['nchan']):
cals[k] = info['chs'][k]['range'] * \
info['chs'][k]['cal']

self.cals = raw.cals
self.rawdir = raw.rawdir
self.proj = raw.proj
self.comp = raw.comp

self.verbose = True
if self.verbose:
print ' Range : %d ... %d = %9.3f ... %9.3f secs' % (
self.first_samp, self.last_samp,
float(self.first_samp) / info['sfreq'],
float(self.last_samp) / info['sfreq'])
print 'Ready.'
self.fid = None
self._preloaded = True
self._times = np.arange(self.first_samp,
self.last_samp + 1) / info['sfreq']
del raw


class _RawShell():
"""Used for creating a temporary raw object"""
def __init__(self):
Expand Down

0 comments on commit 7b733ab

Please sign in to comment.