Commit 99ea3f00 authored by Aleksiej Chrabrow's avatar Aleksiej Chrabrow Committed by Joanna Duda

refactor tests

parent 47b6a39f
<?xml version="1.0" encoding="utf-8"?><rs:rawSignal xmlns:rs="http://signalml.org/rawsignal"><rs:exportFileName>name</rs:exportFileName><rs:sourceFileName>PILOT_KASIA3_23_06_2010.obci.dat</rs:sourceFileName><rs:sourceFileFormat><rs:rawSignalInfo></rs:rawSignalInfo></rs:sourceFileFormat><rs:samplingFrequency>128</rs:samplingFrequency><rs:channelCount>25</rs:channelCount><rs:sampleCount>2810175</rs:sampleCount><rs:calibration>1.0</rs:calibration><rs:sampleType>DOUBLE</rs:sampleType><rs:byteOrder>LITTLE_ENDIAN</rs:byteOrder><rs:pageSize>20.0</rs:pageSize><rs:blocksPerPage>5</rs:blocksPerPage><rs:channelLabels><rs:label>Fp1</rs:label><rs:label>Fpz</rs:label><rs:label>Fp2</rs:label><rs:label>F7</rs:label><rs:label>F3</rs:label><rs:label>Fz</rs:label><rs:label>F4</rs:label><rs:label>F8</rs:label><rs:label>M1</rs:label><rs:label>C7</rs:label><rs:label>C3</rs:label><rs:label>Cz</rs:label><rs:label>C4</rs:label><rs:label>T8</rs:label><rs:label>M2</rs:label><rs:label>P7</rs:label><rs:label>P3</rs:label><rs:label>Pz</rs:label><rs:label>P4</rs:label><rs:label>P8</rs:label><rs:label>O1</rs:label><rs:label>Oz</rs:label><rs:label>O2</rs:label><rs:label>NIC</rs:label><rs:label>OKO_GORA_DOL</rs:label></rs:channelLabels>
<rs:calibrationGain>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
<rs:calibrationParam>1.0</rs:calibrationParam>
</rs:calibrationGain>
<rs:calibrationOffset>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
<rs:calibrationParam>0.0</rs:calibrationParam>
</rs:calibrationOffset>
<rs:exportDate>2010-04-26T11:02:51</rs:exportDate></rs:rawSignal>
<?xml version="1.0" encoding="utf-8"?><tagFile formatVersion="1.0"><paging blocks_per_page="5" page_size="20.0"/><tagData><tags><tag channelNumber="-1" length="1.0046250820159912" name="trigger" position="0.36085605621337891"><value>1</value></tag><tag channelNumber="-1" length="1.9283778667449951" name="trigger" position="1.3654811382293701"><value>0</value></tag><tag channelNumber="-1" length="1.5430161952972412" name="trigger" position="3.2938590049743652"><value>1</value></tag><tag channelNumber="-1" length="1.7950088977813721" name="trigger" position="4.8368752002716064"><value>0</value></tag><tag channelNumber="-1" length="1.6539919376373291" name="trigger" position="6.6318840980529785"><value>1</value></tag><tag channelNumber="-1" length="1.6060090065002441" name="trigger" position="8.2858760356903076"><value>0</value></tag><tag channelNumber="-1" length="1.7079939842224121" name="trigger" position="9.8918850421905518"><value>1</value></tag><tag channelNumber="-1" length="1.5549831390380859" name="trigger" position="11.599879026412964"><value>0</value></tag><tag channelNumber="-1" length="1.5930259227752686" name="trigger" position="13.15486216545105"><value>1</value></tag><tag channelNumber="-1" length="1.0129780769348145" name="trigger" position="14.747888088226318"><value>0</value></tag><tag channelNumber="-1" length="1.7710130214691162" name="trigger" position="15.760866165161133"><value>1</value></tag><tag channelNumber="-1" length="1.6369898319244385" name="trigger" position="17.531879186630249"><value>0</value></tag><tag channelNumber="-1" length="1.8520011901855469" name="trigger" position="19.168869018554688"><value>1</value></tag><tag channelNumber="-1" length="1.6960029602050781" name="trigger" position="21.020870208740234"><value>0</value></tag><tag channelNumber="-1" length="1.8960099220275879" name="trigger" position="22.716873168945312"><value>1</value></tag><tag channelNumber="-1" length="1.799976110458374" name="trigger" position="24.6128830909729"><value>0</value></tag><tag channelNumber="-1" length="1.9080259799957275" name="trigger" position="26.412859201431274"><value>1</value></tag><tag channelNumber="-1" length="1.0279920101165771" name="trigger" position="28.320885181427002"><value>0</value></tag><tag channelNumber="-1" length="1.3869879245758057" name="trigger" position="29.348877191543579"><value>1</value></tag><tag channelNumber="-1" length="1.1030158996582031" name="trigger" position="30.735865116119385"><value>0</value></tag><tag channelNumber="-1" length="1.6669991016387939" name="trigger" position="31.838881015777588"><value>1</value></tag><tag channelNumber="-1" length="1.0890018939971924" name="trigger" position="33.505880117416382"><value>0</value></tag><tag channelNumber="-1" length="1.9470040798187256" name="trigger" position="34.594882011413574"><value>1</value></tag><tag channelNumber="-1" length="1.1589961051940918" name="trigger" position="36.5418860912323"><value>0</value></tag><tag channelNumber="-1" length="1.0949859619140625" name="trigger" position="37.700882196426392"><value>1</value></tag><tag channelNumber="-1" length="1.389995813369751" name="trigger" position="38.795868158340454"><value>0</value></tag><tag channelNumber="-1" length="1.7900252342224121" name="trigger" position="40.185863971710205"><value>1</value></tag><tag channelNumber="-1" length="1.6329929828643799" name="trigger" position="41.975889205932617"><value>0</value></tag><tag channelNumber="-1" length="1.0870018005371094" name="trigger" position="43.608882188796997"><value>1</value></tag><tag channelNumber="-1" length="1.217008113861084" name="trigger" position="44.695883989334106"><value>0</value></tag><tag channelNumber="-1" length="1.7229928970336914" name="trigger" position="45.91289210319519"><value>1</value></tag><tag channelNumber="-1" length="1.7080001831054688" name="trigger" position="47.635885000228882"><value>0</value></tag><tag channelNumber="-1" length="1.3120009899139404" name="trigger" position="49.343885183334351"><value>1</value></tag><tag channelNumber="-1" length="1.8303978443145752" name="trigger" position="50.655886173248291"><value>0</value></tag><tag channelNumber="-1" length="1.077592134475708" name="trigger" position="52.486284017562866"><value>1</value></tag><tag channelNumber="-1" length="1.9700009822845459" name="trigger" position="53.563876152038574"><value>0</value></tag><tag channelNumber="-1" length="1.8099980354309082" name="trigger" position="55.53387713432312"><value>1</value></tag><tag channelNumber="-1" length="1.9740610122680664" name="trigger" position="57.343875169754028"><value>0</value></tag><tag channelNumber="-1" length="1.7009468078613281" name="trigger" position="59.317936182022095"><value>1</value></tag><tag channelNumber="-1" length="1.2930071353912354" name="trigger" position="61.018882989883423"><value>0</value></tag><tag channelNumber="-1" length="1.4469950199127197" name="trigger" position="62.311890125274658"><value>1</value></tag><tag channelNumber="-1" length="1.8379850387573242" name="trigger" position="63.758885145187378"><value>0</value></tag><tag channelNumber="-1" length="1.9000129699707031" name="trigger" position="65.596870183944702"><value>1</value></tag><tag channelNumber="-1" length="1.3319909572601318" name="trigger" position="67.496883153915405"><value>0</value></tag><tag channelNumber="-1" length="1.8179960250854492" name="trigger" position="68.828874111175537"><value>1</value></tag><tag channelNumber="-1" length="1.2369940280914307" name="trigger" position="70.646870136260986"><value>0</value></tag><tag channelNumber="-1" length="1.4687058925628662" name="trigger" position="71.883864164352417"><value>1</value></tag><tag channelNumber="-1" length="2.0003170967102051" name="trigger" position="73.352570056915283"><value>0</value></tag><tag channelNumber="-1" length="1.9999959468841553" name="trigger" position="75.352887153625488"><value>1</value></tag><tag channelNumber="-1" length="1.6439969539642334" name="trigger" position="77.352883100509644"><value>0</value></tag><tag channelNumber="-1" length="1.0243129730224609" name="trigger" position="78.996880054473877"><value>1</value></tag></tags></tagData></tagFile>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><rs:rawSignal xmlns:rs="http://signalml.org/rawsignal"><rs:exportFileName>name</rs:exportFileName><rs:sourceFileName>MATI_FULL_EXP_28_10_2010_2.obci.dat</rs:sourceFileName><rs:sourceFileFormat><rs:rawSignalInfo></rs:rawSignalInfo></rs:sourceFileFormat><rs:samplingFrequency>256</rs:samplingFrequency><rs:channelCount>23</rs:channelCount><rs:sampleCount>454986</rs:sampleCount><rs:calibration>1.0</rs:calibration><rs:sampleType>DOUBLE</rs:sampleType><rs:byteOrder>LITTLE_ENDIAN</rs:byteOrder><rs:pageSize>20.0</rs:pageSize><rs:blocksPerPage>5</rs:blocksPerPage><rs:channelLabels><rs:label>Fp1</rs:label><rs:label>Fpz</rs:label><rs:label>Fp2</rs:label><rs:label>F7</rs:label><rs:label>F3</rs:label><rs:label>Fz</rs:label><rs:label>F4</rs:label><rs:label>F8</rs:label><rs:label>M1</rs:label><rs:label>C7</rs:label><rs:label>C3</rs:label><rs:label>Cz</rs:label><rs:label>C4</rs:label><rs:label>T8</rs:label><rs:label>M2</rs:label><rs:label>P7</rs:label><rs:label>P3</rs:label><rs:label>Pz</rs:label><rs:label>P4</rs:label><rs:label>P8</rs:label><rs:label>O1</rs:label><rs:label>Oz</rs:label><rs:label>O2</rs:label></rs:channelLabels><rs:exportDate>2010-04-26T11:02:51</rs:exportDate></rs:rawSignal>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><tagFile formatVersion="1.0"><paging blocks_per_page="5" page_size="20.0"/><tagData><tags><tag channelNumber="-1" length="1.0046250820159912" name="trigger" position="0.36085605621337891"><value>1</value></tag><tag channelNumber="-1" length="1.9283778667449951" name="trigger" position="1.3654811382293701"><value>0</value></tag><tag channelNumber="-1" length="1.5430161952972412" name="trigger" position="3.2938590049743652"><value>1</value></tag><tag channelNumber="-1" length="1.7950088977813721" name="trigger" position="4.8368752002716064"><value>0</value></tag><tag channelNumber="-1" length="1.6539919376373291" name="trigger" position="6.6318840980529785"><value>1</value></tag><tag channelNumber="-1" length="1.6060090065002441" name="trigger" position="8.2858760356903076"><value>0</value></tag><tag channelNumber="-1" length="1.7079939842224121" name="trigger" position="9.8918850421905518"><value>1</value></tag><tag channelNumber="-1" length="1.5549831390380859" name="trigger" position="11.599879026412964"><value>0</value></tag><tag channelNumber="-1" length="1.5930259227752686" name="trigger" position="13.15486216545105"><value>1</value></tag><tag channelNumber="-1" length="1.0129780769348145" name="trigger" position="14.747888088226318"><value>0</value></tag><tag channelNumber="-1" length="1.7710130214691162" name="trigger" position="15.760866165161133"><value>1</value></tag><tag channelNumber="-1" length="1.6369898319244385" name="trigger" position="17.531879186630249"><value>0</value></tag><tag channelNumber="-1" length="1.8520011901855469" name="trigger" position="19.168869018554688"><value>1</value></tag><tag channelNumber="-1" length="1.6960029602050781" name="trigger" position="21.020870208740234"><value>0</value></tag><tag channelNumber="-1" length="1.8960099220275879" name="trigger" position="22.716873168945312"><value>1</value></tag><tag channelNumber="-1" length="1.799976110458374" name="trigger" position="24.6128830909729"><value>0</value></tag><tag channelNumber="-1" length="1.9080259799957275" name="trigger" position="26.412859201431274"><value>1</value></tag><tag channelNumber="-1" length="1.0279920101165771" name="trigger" position="28.320885181427002"><value>0</value></tag><tag channelNumber="-1" length="1.3869879245758057" name="trigger" position="29.348877191543579"><value>1</value></tag><tag channelNumber="-1" length="1.1030158996582031" name="trigger" position="30.735865116119385"><value>0</value></tag><tag channelNumber="-1" length="1.6669991016387939" name="trigger" position="31.838881015777588"><value>1</value></tag><tag channelNumber="-1" length="1.0890018939971924" name="trigger" position="33.505880117416382"><value>0</value></tag><tag channelNumber="-1" length="1.9470040798187256" name="trigger" position="34.594882011413574"><value>1</value></tag><tag channelNumber="-1" length="1.1589961051940918" name="trigger" position="36.5418860912323"><value>0</value></tag><tag channelNumber="-1" length="1.0949859619140625" name="trigger" position="37.700882196426392"><value>1</value></tag><tag channelNumber="-1" length="1.389995813369751" name="trigger" position="38.795868158340454"><value>0</value></tag><tag channelNumber="-1" length="1.7900252342224121" name="trigger" position="40.185863971710205"><value>1</value></tag><tag channelNumber="-1" length="1.6329929828643799" name="trigger" position="41.975889205932617"><value>0</value></tag><tag channelNumber="-1" length="1.0870018005371094" name="trigger" position="43.608882188796997"><value>1</value></tag><tag channelNumber="-1" length="1.217008113861084" name="trigger" position="44.695883989334106"><value>0</value></tag><tag channelNumber="-1" length="1.7229928970336914" name="trigger" position="45.91289210319519"><value>1</value></tag><tag channelNumber="-1" length="1.7080001831054688" name="trigger" position="47.635885000228882"><value>0</value></tag><tag channelNumber="-1" length="1.3120009899139404" name="trigger" position="49.343885183334351"><value>1</value></tag><tag channelNumber="-1" length="1.8303978443145752" name="trigger" position="50.655886173248291"><value>0</value></tag><tag channelNumber="-1" length="1.077592134475708" name="trigger" position="52.486284017562866"><value>1</value></tag><tag channelNumber="-1" length="1.9700009822845459" name="trigger" position="53.563876152038574"><value>0</value></tag><tag channelNumber="-1" length="1.8099980354309082" name="trigger" position="55.53387713432312"><value>1</value></tag><tag channelNumber="-1" length="1.9740610122680664" name="trigger" position="57.343875169754028"><value>0</value></tag><tag channelNumber="-1" length="1.7009468078613281" name="trigger" position="59.317936182022095"><value>1</value></tag><tag channelNumber="-1" length="1.2930071353912354" name="trigger" position="61.018882989883423"><value>0</value></tag><tag channelNumber="-1" length="1.4469950199127197" name="trigger" position="62.311890125274658"><value>1</value></tag><tag channelNumber="-1" length="1.8379850387573242" name="trigger" position="63.758885145187378"><value>0</value></tag><tag channelNumber="-1" length="1.9000129699707031" name="trigger" position="65.596870183944702"><value>1</value></tag><tag channelNumber="-1" length="1.3319909572601318" name="trigger" position="67.496883153915405"><value>0</value></tag><tag channelNumber="-1" length="1.8179960250854492" name="trigger" position="68.828874111175537"><value>1</value></tag><tag channelNumber="-1" length="1.2369940280914307" name="trigger" position="70.646870136260986"><value>0</value></tag><tag channelNumber="-1" length="1.4687058925628662" name="trigger" position="71.883864164352417"><value>1</value></tag><tag channelNumber="-1" length="2.0003170967102051" name="trigger" position="73.352570056915283"><value>0</value></tag><tag channelNumber="-1" length="1.9999959468841553" name="trigger" position="75.352887153625488"><value>1</value></tag><tag channelNumber="-1" length="1.6439969539642334" name="trigger" position="77.352883100509644"><value>0</value></tag><tag channelNumber="-1" length="1.0243129730224609" name="trigger" position="78.996880054473877"><value>1</value></tag></tags></tagData></tagFile>
\ No newline at end of file
#!/usr/bin/env python3
#
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
#
"""
>>> from obci.signal_processing.signal.data_read_proxy import DataReadProxy
>>> from obci.signal_processing.signal.data_raw_write_proxy import DataRawWriteProxy
>>> import os.path, os
>>> px = DataRawWriteProxy('./tescik.obci.dat')
>>> px.set_data_len(1, 1)
>>> px.data_received(1.2)
>>> px.data_received(0.0023)
>>> px.data_received(-123.456)
>>> px.data_received(3.3)
>>> px.data_received(5.0)
>>> nic = px.finish_saving()
>>> f = './tescik.obci.dat'
>>> py = DataReadProxy(f)
>>> abs(1.2 - py.get_next_value()) < 0.0001
True
>>> abs(0.0023-py.get_next_value()) < 0.000000001
True
>>> abs(-123.456-py.get_next_value()) < 0.00001
True
>>> py.goto_value(1)
>>> abs(0.0023-py.get_next_value()) < 0.000000001
True
>>> py.goto_value(4)
>>> abs(5.0-py.get_next_value()) < 0.0001
True
>>> py.goto_value(6)
>>> py.get_next_value()
Traceback (most recent call last):
...
obci.signal_processing.signal.signal_exceptions.NoNextValue
>>> py.finish_reading()
>>> py.start_reading()
>>> vs = py.get_next_values(3)
>>> abs(vs[0]-1.20000000e+00)+abs(vs[1]-2.30000000e-03)+abs(vs[2]+1.23456000e+02)<3*0.0001
True
>>> py.get_next_values(3)
Traceback (most recent call last):
...
obci.signal_processing.signal.signal_exceptions.NoNextValue
>>> #warning here
>>> py.finish_reading()
>>> os.remove(f)
"""
def run():
import doctest
import sys
res = doctest.testmod(sys.modules[__name__])
if res.failed == 0:
print("All tests succeeded!")
# def test_data_file_proxy():
# run()
if __name__ == '__main__':
run()
#!/usr/bin/env python3
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
#
"""
>>> from obci.signal_processing.tags import tags_file_writer as p
>>> from obci.signal_processing.tags import tags_file_reader as t
>>> px = p.TagsFileWriter('./tescik.obci.tags')
>>> px.tag_received({'start_timestamp':1001.0, 'end_timestamp':1002.0, 'name': 'nic', 'channels':'A B C',\
'desc': {'x':123, 'y':456, 'z': 789}})
>>> px.tag_received({'start_timestamp':1003.0, 'end_timestamp':1004.0, 'name': 'nic2', 'channels':'A B C',\
'desc': {'x':1234, 'y':4567, 'z': 789}})
>>> px.tag_received({'start_timestamp':1005.0, 'end_timestamp':1006.0, 'name': 'nic3', 'channels':'A B C',\
'desc': {'x':12345, 'y':45678, 'z': 789}})
>>> px.finish_saving(1000.0)
'./tescik.obci.tags'
>>> py = t.TagsFileReader('tescik.obci.tags')
>>> g = py.get_tags()[0]
>>> print(g['start_timestamp'])
1.0
>>> print(g['end_timestamp'])
2.0
>>> print(g['name'])
nic
>>> print(g['desc']['y'])
456
>>> print([int(t['start_timestamp']) for t in py.get_tags()])
[1, 3, 5]
>>> #REORDER AND TEST ORDERING AGAIN ....
>>> px = p.TagsFileWriter('./tescik.obci.tags')
>>> px.tag_received({'start_timestamp':1003.0, 'end_timestamp':1004.0, 'name': 'nic2', 'channels':'A B C',\
'desc': {'x':1234, 'y':4567, 'z': 789}})
>>> px.tag_received({'start_timestamp':1005.0, 'end_timestamp':1006.0, 'name': 'nic3', 'channels':'A B C',\
'desc': {'x':12345, 'y':45678, 'z': 789}})
>>> px.tag_received({'start_timestamp':1001.0, 'end_timestamp':1002.0, 'name': 'nic', 'channels':'A B C',\
'desc': {'x':123, 'y':456, 'z': 789}})
>>> print([int(t['start_timestamp']) for t in py.get_tags()])
[1, 3, 5]
>>> import os
>>> import glob
>>> for fl in glob.glob('tescik*'): os.remove(fl)
"""
def run():
import doctest
import sys
res = doctest.testmod(sys.modules[__name__])
if res.failed == 0:
print("All tests succeeded!")
if __name__ == '__main__':
run()
#!/usr/bin/env python3
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
#
"""
>>> import os
>>> from obci.signal_processing.signal import info_file_proxy as p
>>> px = p.InfoFileWriteProxy('./tescik.obci.svarog.info')
>>> px.set_attributes({'number_of_channels':2, 'sampling_frequency':128, 'channels_names': ['1','2'],\
'video_file_name':'film.mp4', 'video_file_offset':3.5,\
'file':'soufce.obci.dat', 'number_of_samples':3\
}\
)\
>>> px.finish_saving()
'./tescik.obci.svarog.info'
>>> py = p.InfoFileReadProxy('./tescik.obci.svarog.info')
>>> print(py.get_param('number_of_channels'))
2
>>> print(py.get_param('channels_names')[0])
1
>>> print(py.get_param('video_file_name'))
film.mp4
>>> print(py.get_param('video_file_offset'))
3.5
>>> os.remove('./tescik.obci.svarog.info')
"""
def run():
import doctest
import sys
res = doctest.testmod(sys.modules[__name__])
if res.failed == 0:
print("All tests succeeded!")
if __name__ == '__main__':
run()
#!/usr/bin/env python3
#
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
#
"""
>>> from obci.signal_processing.signal.data_raw_write_proxy import DataRawWriteProxy
>>> import os.path, os
>>> # PREPARE SOME SAMPLE FILE *************************************************
>>> px = DataRawWriteProxy('./tescik.obci.dat')
>>> px.data_received(1.2)
>>> px.data_received(0.0023)
>>> px.data_received(-123.456)
>>> px.data_received(3.3)
>>> px.data_received(5.0)
>>> px.data_received(0.0)
>>> nic = px.finish_saving()
>>> f = './tescik.obci.dat'
>>> from obci.signal_processing.signal import read_data_source as s
>>> # TEST MEMORY DATA SOURCE **************************************************
>>> import numpy
>>> import numpy as np
>>> py = s.MemoryDataSource(numpy.zeros((2,3)))
>>> py.set_sample(0, [1.0, 2.0])
>>> py.set_sample(1, [3.0, 4.0])
>>> py.set_sample(2, [5.0, 6.0])
>>> [i for i in py.iter_samples()]
[array([ 1., 2.]), array([ 3., 4.]), array([ 5., 6.])]
>>> [i for i in py.iter_samples()]
[array([ 1., 2.]), array([ 3., 4.]), array([ 5., 6.])]
>>> py.get_samples(0, 1)
array([[ 1.],
[ 2.]])
>>> py.set_sample(3, [3.0, 4.0])
Traceback (most recent call last):
...
IndexError: index 3 is out of bounds for axis 1 with size 3
>>> py.set_sample(2, [1.0, 2.0, 3.0])
Traceback (most recent call last):
...
ValueError: cannot copy sequence with size 3 to array axis with dimension 2
>>> # TEST FILE DATA SOURCE ****************************************************
>>> py = s.FileDataSource(f, 2)
>>> py.get_samples(0, 0)
array([], shape=(2, 0), dtype=float64)
>>> np.abs(np.array([[ 1.20000000e+00, -1.23456000e+02],\
[ 2.30000000e-03, 3.30000000e+00]]) - py.get_samples(0, 2)) < 0.001
array([[ True, True],
[ True, True]], dtype=bool)
>>> py.get_samples(0, 10)
Traceback (most recent call last):
...
obci.signal_processing.signal.signal_exceptions.NoNextValue
>>> np.abs(np.array([[ 1.20000000e+00, -1.23456000e+02, 5.00000000e+00],\
[ 2.30000000e-03, 3.30000000e+00, 0.00000000e+00]]) - py.get_samples(0, 3)) < 0.001
array([[ True, True, True],
[ True, True, True]], dtype=bool)
>>> py.get_samples(1, 3)
Traceback (most recent call last):
...
obci.signal_processing.signal.signal_exceptions.NoNextValue
>>> np.abs(np.array([[ 1.20000000e+00, -1.23456000e+02, 5.00000000e+00],\
[ 2.30000000e-03, 3.30000000e+00, 0.00000000e+00]]) - py.get_samples()) < 0.001
array([[ True, True, True],
[ True, True, True]], dtype=bool)
>>> py = s.FileDataSource(f, 2)
>>> from numpy import array
>>> np.abs(array([[ 1.20000000e+00, -1.23456000e+02, 5.00000000e+00],\
[ 2.30000000e-03, 3.30000000e+00, 0.00000000e+00]]) - py.get_samples()) < 0.001
array([[ True, True, True],
[ True, True, True]], dtype=bool)
>>> py = s.FileDataSource(f, 2)
>>> np.abs(array([[ 1.20000000e+00, -1.23456000e+02, 5.00000000e+00],\
[ 2.30000000e-03, 3.30000000e+00, 0.00000000e+00]]) - py.get_samples()) < 0.001
array([[ True, True, True],
[ True, True, True]], dtype=bool)
>>> np.abs(array([[ 1.20000000e+00, -1.23456000e+02, 5.00000000e+00],\
[ 2.30000000e-03, 3.30000000e+00, 0.00000000e+00]]) - py.get_samples()) < 0.001
array([[ True, True, True],
[ True, True, True]], dtype=bool)
>>> [max(abs(i-y))<0.0001 for i,y in zip(py.iter_samples(),\
[array([ 1.2 , 0.0023]), array([-123.456, 3.3 ]), array([ 5., 0.])])]
[True, True, True]
>>> py = s.FileDataSource(f, 2)
>>> [max(abs(i-y))<0.0001 for i,y in zip(py.iter_samples(),\
[array([ 1.2 , 0.0023]), array([-123.456, 3.3 ]), array([ 5., 0.])])]
[True, True, True]
>>> [max(abs(i-y))<0.0001 for i,y in zip(py.iter_samples(),\
[array([ 1.2 , 0.0023]), array([-123.456, 3.3 ]), array([ 5., 0.])])]
[True, True, True]
>>> os.remove(f)
"""
def run():
import doctest
import sys
res = doctest.testmod(sys.modules[__name__])
if res.failed == 0:
print("All tests succeeded!")
if __name__ == '__main__':
run()
#!/usr/bin/env python3
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
#
"""
>>> from obci.signal_processing import read_manager
>>> import os, os.path, sys
>>> pth = os.path.abspath(__file__)
>>> f = os.path.join(pth[:-len(os.path.basename(pth))], 'data', 'data')
>>> mgr = read_manager.ReadManager(f+'.obci.info', f+'.obci.dat', f+'.obci.tags')
>>> mgr.get_samples(0, 1)[0,0]
-27075.0
>>> mgr.get_samples(0, 1)[1,0]
39641.0
>>> ch = mgr.get_samples()
>>> ch[0][0]
-27075.0
>>> ch[1][0]
39641.0
>>> [len(x) for x in ch]
[112407, 112407, 112407, 112407, 112407, 112407, 112407, 112407, 112407,\
112407, 112407, 112407, 112407, 112407, 112407, 112407, 112407, 112407,\
112407, 112407, 112407, 112407, 112407, 112407, 112407]
>>> mgr.get_param(u'number_of_samples')
'2810175'
>>> mgr.get_param(u'sampling_frequency')
'128'
>>> mgr.get_param(u'number_of_channels')
'25'
>>> mgr.get_param('channels_names')
['Fp1', 'Fpz', 'Fp2', 'F7', 'F3', 'Fz', 'F4', 'F8', 'M1', 'C7', 'C3',\
'Cz', 'C4', 'T8', 'M2', 'P7', 'P3', 'Pz', 'P4', 'P8', 'O1', 'Oz', 'O2',\
'NIC', 'OKO_GORA_DOL']
>>> mgr.get_param('im_not_there')
Traceback (most recent call last):
...
obci.signal_processing.signal.signal_exceptions.NoParameter:\
No parameter 'im_not_there' was found in info source!
>>> import numpy as np
>>> np.sum([np.abs(t['start_timestamp']-et)<0.0001 for t,et in zip(mgr.iter_tags(), [0.36085605621337891,\
1.3654811382293701, 3.2938590049743652, 4.8368752002716064, 6.6318840980529785,\
8.2858760356903076, 9.8918850421905518, 11.599879026412964, 13.15486216545105, 14.747888088226318, 15.760866165161133,\
17.531879186630249, 19.168869018554688, 21.020870208740234, 22.716873168945312, 24.6128830909729, 26.412859201431274,\
28.320885181427002, 29.348877191543579, 30.735865116119385, 31.838881015777588, 33.505880117416382, 34.594882011413574,\
36.5418860912323, 37.700882196426392, 38.795868158340454, 40.185863971710205, 41.975889205932617, 43.608882188796997,\
44.695883989334106, 45.91289210319519, 47.635885000228882, 49.343885183334351, 50.655886173248291, 52.486284017562866,\
53.563876152038574, 55.53387713432312, 57.343875169754028, 59.317936182022095, 61.018882989883423, 62.311890125274658,\
63.758885145187378, 65.596870183944702, 67.496883153915405, 68.828874111175537, 70.646870136260986, 71.883864164352417,\
73.352570056915283, 75.352887153625488, 77.352883100509644, 78.996880054473877])])
51
>>> i = mgr.iter_tags()
>>> next(i)=={'channels': '', 'start_timestamp': 0.36085605621337891, 'desc': {u'value': u'1'}, 'name': u'trigger',\
'end_timestamp': 1.3654811382293701}
True
>>> next(i)=={'channels': '', 'start_timestamp': 1.3654811382293701, 'desc': {u'value': u'0'}, 'name': u'trigger',\
'end_timestamp': 3.2938590049743652}
True
"""
def run():
import doctest
import sys
res = doctest.testmod(sys.modules[__name__])
if res.failed == 0:
print("All tests succeeded!")
if __name__ == '__main__':
run()
#!/usr/bin/env python3
#
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
#
"""
>>> tags = []
>>> tags.append({'start_timestamp':1001.0, 'end_timestamp':1002.0, 'name': 'nic', 'channels':'A B C',\
'desc': {'x':123, 'y':456, 'z': 789}})
>>> tags.append({'start_timestamp':1003.0, 'end_timestamp':1004.0, 'name': 'nic2', 'channels':'A B C',\
'desc': {'x':1234, 'y':4567, 'z': 789}})
>>> tags.append({'start_timestamp':1005.0, 'end_timestamp':1006.0, 'name': 'nic3', 'channels':'A B C',\
'desc': {'x':12345, 'y':45678, 'z': 789}})
>>> tags.append({'start_timestamp':1005.5, 'end_timestamp':1007.0, 'name': 'nic2', 'channels':'A B C',\
'desc': {'x':12345, 'y':45678, 'z': 789}})
>>> tags.append({'start_timestamp':1008.0, 'end_timestamp':1009.0, 'name': 'nic3', 'channels':'A B C',\
'desc': {'x':12345, 'y':45678, 'z': 789}})
>>> from obci.signal_processing.tags import read_tags_source
>>> s = read_tags_source.MemoryTagsSource(tags)
>>> s.get_tags()==\
[{'channels': 'A B C', 'start_timestamp': 1001.0, 'desc': {'y': 456, 'x': 123, 'z': 789}, 'name': 'nic',\
'end_timestamp': 1002.0}, {'channels': 'A B C', 'start_timestamp': 1003.0, 'desc': {'y': 4567, 'x': 1234, 'z': 789},\
'name': 'nic2', 'end_timestamp': 1004.0}, {'channels': 'A B C', 'start_timestamp': 1005.0,\
'desc': {'y': 45678, 'x': 12345, 'z': 789}, 'name': 'nic3', 'end_timestamp': 1006.0},\
{'channels': 'A B C', 'start_timestamp': 1005.5, 'desc': {'y': 45678, 'x': 12345, 'z': 789},\
'name': 'nic2', 'end_timestamp': 1007.0}, {'channels': 'A B C', 'start_timestamp': 1008.0,\
'desc': {'y': 45678, 'x': 12345, 'z': 789}, 'name': 'nic3', 'end_timestamp': 1009.0}]
True
>>> s.get_tags('nic2')==\
[{'channels': 'A B C', 'start_timestamp': 1003.0, 'desc': {'y': 4567, 'x': 1234, 'z': 789}, 'name': 'nic2',\
'end_timestamp': 1004.0}, {'channels': 'A B C', 'start_timestamp': 1005.5,\
'desc': {'y': 45678, 'x': 12345, 'z': 789}, 'name': 'nic2', 'end_timestamp': 1007.0}]
True
>>> s.get_tags(None, 1005.0, 1.0)==\
[{'channels': 'A B C', 'start_timestamp': 1005.0, 'desc': {'y': 45678, 'x': 12345, 'z': 789},\
'name': 'nic3', 'end_timestamp': 1006.0}, {'channels': 'A B C', 'start_timestamp': 1005.5,\
'desc': {'y': 45678, 'x': 12345, 'z': 789}, 'name': 'nic2', 'end_timestamp': 1007.0}]
True
>>> s.get_tags('nic3', 1005.0, 1.0)==\
[{'channels': 'A B C', 'start_timestamp': 1005.0, 'desc': {'y': 45678, 'x': 12345, 'z': 789},\
'name': 'nic3', 'end_timestamp': 1006.0}]
True
>>> s.get_tags(None, None, None, lambda tag: tag['desc']['x'] == 12345)==\
[{'channels': 'A B C', 'start_timestamp': 1005.0, 'desc': {'y': 45678, 'x': 12345, 'z': 789},\
'name': 'nic3', 'end_timestamp': 1006.0}, {'channels': 'A B C', 'start_timestamp': 1005.5,\
'desc': {'y': 45678, 'x': 12345, 'z': 789}, 'name': 'nic2', 'end_timestamp': 1007.0},\
{'channels': 'A B C', 'start_timestamp': 1008.0,\
'desc': {'y': 45678, 'x': 12345, 'z': 789}, 'name': 'nic3', 'end_timestamp': 1009.0}]
True
"""
def run():
import doctest
import sys
res = doctest.testmod(sys.modules[__name__])
if res.failed == 0:
print("All tests succeeded!")
if __name__ == '__main__':
run()
#!/usr/bin/env python3
#
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
"""
>>> from obci.signal_processing.tags import smart_tag_definition as d
>>> x = d.SmartTagDurationDefinition(start_tag_name='x', start_offset=1, end_offset=0, duration=21)
>>> print(x.__dict__['start_tag_name'])
x
>>> print(x.__dict__['start_offset'])
1
>>> print(x.__dict__['end_offset'])
0
>>> print(x.__dict__['duration'])
21
"""
def run():
import doctest
import sys
doctest.testmod(sys.modules[__name__])
print("All tests succeeded!")
if __name__ == '__main__':
run()
#!/usr/bin/env python3
#
# Author:
# Mateusz Kruszyński <mateusz.kruszynski@gmail.com>
#
"""
>>> import os, os.path
>>> from obci.signal_processing import smart_tags_manager as mgr
>>> from obci.signal_processing.tags import smart_tag_definition as df
>>> d = df.SmartTagDurationDefinition(start_tag_name='trigger', start_offset=0, end_offset=0, duration=1.0)
>>> pth = __file__
>>> f = {'info': os.path.join(pth[:-len(os.path.basename(pth))], 'data', 'nic.obci.svarog.info'),\
'data':'nic.obci.dat', 'tags': os.path.join(pth[:-len(os.path.basename(pth))], 'data', 'nic.obci.svarog.tags')}
>>> fabricate_data_file(f['data'])
>>> m = mgr.SmartTagsManager(d, f['info'], f['data'], f['tags'])
>>> print(len(m._smart_tags))
51
>>> tags, num = iter_all_tags(m)
>>> print(num)
51
>>> abs(tags[0].get_start_timestamp()-0.36085605621337891)<0.0001
True
>>> abs(tags[50].get_end_timestamp()-79.996880054473877)<0.0001
True
>>> abs(tags[2].get_channel_samples('Fp1')[0]-19389.0)<0.0001
True
>>> print(tags_len_ok(tags))
True
>>> dd = df.SmartTagEndTagDefinition(start_tag_name='trigger', start_offset=0, end_offset=0, end_tags_names=['trigger'])
>>> mm = mgr.SmartTagsManager(dd, f['info'], f['data'], f['tags'])
>>> tags, num = iter_all_tags(mm)
>>> print(num)
50
>>> print(not_duration_tags_data_len(tags))
20131
>>> print(not_duration_tags_data_sub(tags))
True
>>> # Another test
>>> from obci.signal_processing.tags import tags_file_writer as p
>>> px = p.TagsFileWriter('./tescik.obci.tags')
>>> px.tag_received({'start_timestamp':1.0, 'end_timestamp':5.0, 'name': 'A', 'channels':'',\
'desc': {'x':123, 'y':456, 'z': 789}})
>>> px.tag_received({'start_timestamp':6.0, 'end_timestamp':10.0, 'name': 'A', 'channels':'',\
'desc': {'x':1234, 'y':4567, 'z': 789}})
>>> px.tag_received({'start_timestamp':6.1, 'end_timestamp':6.5, 'name': 'B', 'channels':'',\
'desc': {'x':123, 'y':456, 'z': 789}})
>>> px.tag_received({'start_timestamp':7.0, 'end_timestamp':7.0, 'name': 'B', 'channels':'',\
'desc': {'x':123, 'y':456, 'z': 789}})
>>> px.tag_received({'start_timestamp':7.5, 'end_timestamp':8.7, 'name': 'B', 'channels':'',\
'desc': {'x':123, 'y':456, 'z': 789}})
>>> px.tag_received({'start_timestamp':9.0, 'end_timestamp':15.0, 'name': 'A', 'channels':'',\
'desc': {'x':12345, 'y':45678, 'z': 789}})