Added code to parse the date string in the module headers

This commit is contained in:
Chris Kerr
2013-12-04 23:20:26 +00:00
parent 3aa3716788
commit 7d0f1e0172
2 changed files with 16 additions and 1 deletions

View File

@@ -6,6 +6,8 @@ __all__ = ['MPTfileCSV', 'MPTfile']
import re
import csv
from os import SEEK_SET, SEEK_CUR
import time
from datetime import date
import numpy as np
@@ -181,6 +183,8 @@ class MPRfile:
of which the file is composed.
data - numpy record array of type VMPdata_dtype containing the main data
array of the file.
startdate - The date when the experiment started
enddate - The date when the experiment finished
"""
def __init__(self, file_or_path):
@@ -196,8 +200,16 @@ class MPRfile:
modules = list(read_VMP_modules(mpr_file))
self.modules = modules
settings_mod, = (m for m in modules if m['shortname'] == b'VMP Set ')
data_module, = (m for m in modules if m['shortname'] == b'VMP data ')
log_module, = (m for m in modules if m['shortname'] == b'VMP LOG ')
## There is 100 bytes of data before the main array starts
self.data = np.frombuffer(data_module['data'], dtype=VMPdata_dtype,
offset=100)
tm = time.strptime(str(settings_mod['date'], encoding='ascii'),
'%m/%d/%y')
self.startdate = date(tm.tm_year, tm.tm_mon, tm.tm_mday)
tm = time.strptime(str(log_module['date'], encoding='ascii'),
'%m/%d/%y')
self.enddate = date(tm.tm_year, tm.tm_mon, tm.tm_mday)

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import os.path
from datetime import date
import numpy as np
from numpy.testing import assert_array_almost_equal, assert_array_equal
@@ -40,8 +41,10 @@ def test_open_MPT_csv_fails_for_bad_file():
mpt1 = MPTfileCSV(os.path.join(testdata_dir, 'bio-logic1.mpr'))
def test_open_MPR():
def test_MPR_read_dates():
mpr1 = MPRfile(os.path.join(testdata_dir, 'bio-logic1.mpr'))
eq_(mpr1.startdate, date(2011, 10, 29))
eq_(mpr1.enddate, date(2011, 10, 31))
@raises(ValueError)