예제 #1
0
    def __init__(self, filename):
        self.filename = filename
        self.first, self.ext = os.path.splitext(filename)
        if not self.ext:
            # No extension: Assume this is a book number
            from . import bookno
            file_bookno = bookno.file_bookno(filename)
            self.filename = dcache.find(rawfile_paths, file_bookno)
            if self.filename:
                self.first, self.ext = os.path.splitext(self.filename)
            else:
                raise Exception('Can\'t locate raw file for book number %s' %
                                filename)
        self.addmethods = None
        self.f = avg_q_file(self.filename)
        self.fileformat = self.f.fileformat
        self.epoched = False
        if self.fileformat == 'freiburg':
            from . import freiburg_setup
            from .. import channelnames2channelpos
            a = avg_q.avg_q()
            nr_of_channels = a.get_description(self.f, 'nr_of_channels')
            del a
            self.setup = channelnames2channelpos.channelnames2channelpos(
                freiburg_setup.sleep_channels(self.first, nr_of_channels))
        elif self.fileformat == 'rec':
            a = avg_q.avg_q()
            comment, channelnames = a.get_description(
                self.f, ('comment', 'channelnames'))
            del a
            if comment is not None and ('Somnoscreen' in comment
                                        or 'Somnodcreen' in comment):
                # Recording reference for Somnoscreen is Cz, makes no sense to analyze the channels like this
                # M1 is the more common name but there are some recordings with A1 instead
                channelnames = set(channelnames)
                # Exclude NonEEGChannels from rereferencing and also channels containing a colon, since they
                # should keep the indicated reference (eg 'C3:M2')
                exclude_channelnames = channelnames.intersection(
                    avg_q.Channeltypes.NonEEGChannels).union(
                        [x for x in channelnames if ':' in x])
                p, fname = os.path.split(self.first)
                fname = fname.lower()
                if fname in bad_channels:
                    channelnames = channelnames.difference(bad_channels[fname])
                reference = channelnames.intersection(
                    set(['M1', 'M2', 'A1', 'A2']))
                self.addmethods = '''
>add_zerochannel Cz 0 0 0
>set_channelposition =grid
>rereference -e %(exclude_channelnames)s %(reference)s
''' % {
                    'exclude_channelnames':
                    channel_list2arg(exclude_channelnames),
                    'reference': channel_list2arg(reference),
                }
        self.trigfile = None
예제 #2
0
 def __init__(self,filename):
  self.filename=filename
  self.first,self.ext=os.path.splitext(filename)
  if not self.ext:
   # No extension: Assume this is a book number
   from . import bookno
   file_bookno=bookno.file_bookno(filename)
   self.filename=None
   self.filename=dcache.find(rawfile_paths,file_bookno)
   if self.filename:
    self.first,self.ext=os.path.splitext(self.filename)
   else:
    raise Exception('Can\'t locate raw file for book number %s' % filename)
  self.addmethods=None
  self.f=avg_q_file(self.filename)
  self.fileformat=self.f.fileformat
  if self.fileformat=='freiburg':
   from . import freiburg_setup
   from .. import channelnames2channelpos
   a=avg_q.avg_q()
   nr_of_channels=a.get_description(self.f,'nr_of_channels')
   del a
   self.setup=channelnames2channelpos.channelnames2channelpos(freiburg_setup.sleep_channels(self.first,nr_of_channels))
  elif self.fileformat=='rec':
   a=avg_q.avg_q()
   comment,channelnames=a.get_description(self.f,('comment','channelnames'))
   del a
   if comment is not None and ('Somnoscreen' in comment or 'Somnodcreen' in comment):
    # Recording reference for Somnoscreen is Cz, makes no sense to analyze the channels like this
    # M1 is the more common name but there are some recordings with A1 instead
    channelnames=set(channelnames)
    # Exclude NonEEGChannels from rereferencing and also channels containing a colon, since they
    # should keep the indicated reference (eg 'C3:M2')
    exclude_channelnames=channelnames.intersection(avg_q.Channeltypes.NonEEGChannels).union([x for x in channelnames if ':' in x])
    p,fname=os.path.split(self.first)
    fname=fname.lower()
    if fname in bad_channels:
     channelnames=channelnames.difference(bad_channels[fname])
    reference=channelnames.intersection(set(['M1','M2','A1','A2']))
    self.addmethods='''
>add_zerochannel Cz 0 0 0
>set_channelposition =grid
>rereference -e %(exclude_channelnames)s %(reference)s
''' % {
     'exclude_channelnames': channel_list2arg(exclude_channelnames),
     'reference': channel_list2arg(reference),
    }
  self.trigfile=None
예제 #3
0
#!/usr/bin/env python

# Set the path to the avg_q python installation here if you
# didn't add it to the global python path
import sys
sys.path.append("R:/avg_q/python")

import avg_q

# The avg_q_ui.exe binary will be found automatically in the directory
# above python/
a = avg_q.avg_q(avg_q='avg_q_ui')

import glob
# Iterate over all files with extension .edf
for infile in glob.glob('N:/*.edf'):
    # avg_q.Epochsource normally takes an avg_q_file() descriptor as first
    # argument but for convenience also a file name with type inferred
    # from the extension
    # Read a single 2-s epoch from the start of the file
    epochsource = avg_q.Epochsource(infile,
                                    '1s',
                                    '1s',
                                    continuous=True,
                                    epochs=1)
    script = avg_q.Script(a)
    script.add_Epochsource(epochsource)
    script.add_transform('''
query -N sfreq stdout
query -N nr_of_points stdout
posplot''')
예제 #4
0
#!/usr/bin/env python

# Set the path to the avg_q python installation here if you
# didn't add it to the global python path
import sys
sys.path.append("R:/avg_q/python")

import avg_q

# The avg_q_ui.exe binary will be found automatically in the directory
# above python/
a=avg_q.avg_q(avg_q='avg_q_ui')

import glob
# Iterate over all files with extension .edf
for infile in glob.glob('N:/*.edf'):
 # avg_q.Epochsource normally takes an avg_q_file() descriptor as first
 # argument but for convenience also a file name with type inferred 
 # from the extension
 # Read a single 2-s epoch from the start of the file
 epochsource=avg_q.Epochsource(infile,'1s','1s',continuous=True,epochs=1)
 script=avg_q.Script(a)
 script.add_Epochsource(epochsource)
 script.add_transform('''
query -N sfreq stdout
query -N nr_of_points stdout
posplot''')
 # avg_q.Script() sets the collect method to null_sink automatically
 script.run()

a.close()