Skip to content

Commit

Permalink
loading improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dokato committed Aug 21, 2015
1 parent 8f9ab05 commit 90f9e84
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ python setup install

###Changelog

#### 0.36
* bug fixing
* data loading improved
* better plotting

#### 0.34
* short-time statistics
* documentation in sphinx ready on readthedocs
Expand Down
17 changes: 10 additions & 7 deletions connectivipy/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class Data(object):
other information about the data
'''
def __init__(self, data, fs=1., chan_names=[], data_info=''):
self.__data = self._load_file(data, data_info)
self.__fs = fs
self.__data = self._load_file(data, data_info)
if self.__data.shape[0]==len(chan_names):
self.__channames = chan_names
elif hasattr(self,'_Data__fs'):
pass
else:
self.__channames = ["x"+str(i) for i in range(self.__chans)]
self.data_info = data_info
Expand All @@ -46,9 +48,7 @@ def _load_file(self, data_what, data_info):
Args:
*data_what* : str/numpy.array
path to file with appropieate format or numpy data array
*dt_type* : str
file extension (mat,)
*dt_type* = '' : str
*data_info* = '' : str
additional file with data settings if needed
Returns:
*data* : np.array
Expand All @@ -57,15 +57,18 @@ def _load_file(self, data_what, data_info):
if dt_type == np.ndarray:
data = data_what
elif dt_type == str:
dt_type = data_what.split('.')[-1] # catch extension of file
if dt_type == 'mat':
mat_dict = si.loadmat(data_what)
if data_info:
key = data_info
else:
key = data.split('.')[0]
key = data_what[:-4].split('/')[-1]
data = mat_dict[key]
if data_info=='sml':
data, sml = signalml_loader(data_what.split('.')[0])
if dt_type=='raw' and data_info=='sml':
data, sml = signalml_loader(data_what[:-4])
self.__fs = sml['samplingFrequency']
self.__channames = sml['channelNames']
self.smldict = sml # here SignalML data is stored
else:
return False
Expand Down
1 change: 0 additions & 1 deletion connectivipy/load/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ def give_xml_info(path):
calibr_coef.append(float(calibr_gain.getElementsByTagName('rs:'+'calibrationParam')[j].childNodes[0].data))
xml_data['channelNames'] = chann_names
xml_data['calibrationCoef'] = calibr_coef

return xml_data
23 changes: 23 additions & 0 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ The easiest way is to use *GIT* and just execute:
$ cd connectivipy
$ python setup.py install
Loading data
########

.. code-block:: python
import connectivipy as cp
# for numpy.array simply put that array in the first argument
# fs means sampling frequency
# chan_names is a list with channel names (length of list must be
# the same as first dimension of data)
# data_info - additional infromation about the data
dt = Data(numpy_array_data, fs=32., chan_names=['Fp1','O1'], data_info='sml')
# Matlab data we can read giving a path to a matlab file
# and in data_info we put variable name as a string
dd = Data('adata.mat' ,data_info='bdata')
# similarly for SignalML data, but in data_info you need to point out
# that you want to read 'sml' data from *.raw and *.xml files of the
# same name
dt = Data('cdata.raw',data_info='sml')
Data class example
########

Expand Down
14 changes: 12 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@
Ains[3, 4, 2] = 0.6

class DataTest(unittest.TestCase):
"test data class"
"test Data class"
#def test_loading(self):
#dt = cp.Data('test_data/testsml.raw',data_info='sml')
#self.assertEquals(dt.fs,256)
#self.assertEquals(len(dt.channelnames),2)
#dd = cp.Data('test_data/m.mat' ,data_info='m')
#self.assertEquals(dd.data.shape[0],3)
#self.assertEquals(dd.data.shape[1],5)

def test_resample(self):
do = cp.Data(np.random.randn(3,100, 4), fs=10)
do.resample(5)
Expand All @@ -65,7 +73,7 @@ def test_conn2(self):

class MvarTest(unittest.TestCase):
def test_fitting(self):
"test mvar fitting"
"test MVAR fitting"
ys = mvar_gen(A,10**4)
avm,vvm = vieiramorf(ys,2)
ans,vns = nutallstrand(ys,2)
Expand All @@ -90,6 +98,8 @@ def test_orders(self):
self.assertEqual(crmin, 2)

class ConnTest(unittest.TestCase):
"test connectivity class Conn"

def test_spectrum(self):
ys = mvar_gen(A,10**4)
avm,vvm = vieiramorf(ys,2)
Expand Down

0 comments on commit 90f9e84

Please sign in to comment.