Package mvpa :: Package tests :: Module test_eepdataset

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.tests.test_eepdataset

     1  # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
     2  # vi: set ft=python sts=4 ts=4 sw=4 et:
     3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
     4  #
     5  #   See COPYING file distributed along with the PyMVPA package for the
     6  #   copyright and license terms.
     7  #
     8  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
     9  """Unit tests for PyMVPA EEP dataset"""
    10
    11  import unittest
    12  import os.path
    13  import numpy as N
    14
    15  from mvpa import pymvpa_dataroot
    16  from mvpa.base import externals
    17  from mvpa.datasets.eep import EEPDataset
    18  from mvpa.misc.io.eepbin import EEPBin
    19
    20
    21 -class EEPDatasetTests(unittest.TestCase):
    22
    23 -    def testLoad(self):
    24          eb = EEPBin(os.path.join(pymvpa_dataroot, 'eep.bin'))
    25
    26          ds = [ EEPDataset(source, labels=[1, 2]) for source in
    27                  (eb, os.path.join(pymvpa_dataroot, 'eep.bin')) ]
    28
    29          for d in ds:
    30              self.failUnless(d.nsamples == 2)
    31              self.failUnless(d.nfeatures == 128)
    32              self.failUnless(d.channelids[23] == 'Pz')
    33              self.failUnless(N.round(d.t0 + 0.002, decimals=3) == 0)
    34              self.failUnless(N.round(d.dt - 0.002, decimals=3) == 0)
    35              self.failUnless(N.round(d.samplingrate) == 500)
    36
    37
    38 -    def testEEPBin(self):
    39          eb = EEPBin(os.path.join(pymvpa_dataroot, 'eep.bin'))
    40
    41          self.failUnless(eb.nchannels == 32)
    42          self.failUnless(eb.nsamples == 2)
    43          self.failUnless(eb.ntimepoints == 4)
    44          self.failUnless(eb.t0 - eb.dt < 0.00000001)
    45          self.failUnless(len(eb.channels) == 32)
    46          self.failUnless(eb.data.shape == (2, 32, 4))
    47
    48
    49 -    def testResampling(self):
    50          ds = EEPDataset(os.path.join(pymvpa_dataroot, 'eep.bin'),
    51                          labels=[1, 2], labels_map={1:100, 2:101})
    52          channelids = N.array(ds.channelids).copy()
    53          self.failUnless(N.round(ds.samplingrate) == 500.0)
    54
    55          if not externals.exists('scipy'):
    56              return
    57
    58          # should puke when called with nothing
    59          self.failUnlessRaises(ValueError, ds.resample)
    60
    61          # now for real -- should divide nsamples into half
    62          rds = ds.resample(sr=250, inplace=False)
    63          # We should have not changed anything
    64          self.failUnless(N.round(ds.samplingrate) == 500.0)
    65
    66          # by default do 'inplace' resampling
    67          ds.resample(sr=250)
    68          for d in [rds, ds]:
    69              self.failUnless(N.round(d.samplingrate) == 250)
    70              self.failUnless(d.nsamples == 2)
    71              self.failUnless(N.abs((d.dt - 1.0/250)/d.dt)<1e-5)
    72              self.failUnless(N.all(d.channelids == channelids))
    73              # lets now see if we still have a mapper
    74              self.failUnless(d.O.shape == (2, len(channelids), 2))
    75              # and labels_map
    76              self.failUnlessEqual(d.labels_map, {1:100, 2:101})
    77              #self.failUnless(d.labels_map)
    78
    79 -def suite():
    80      return unittest.makeSuite(EEPDatasetTests)
    81
    82
    83  if __name__ == '__main__':
    84      import runner
    85