コード例 #1
0
ファイル: data_read_proxy.py プロジェクト: BrainTech/openbci
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import scipy, struct
import os.path, sys
import signal_exceptions
import signal_constants
import signal_logging as logger
LOGGER = logger.get_logger("data_read_proxy", 'info')
SAMPLE_SIZES = signal_constants.SAMPLE_SIZES
SAMPLE_STRUCT_TYPES = signal_constants.SAMPLE_STRUCT_TYPES

class DataReadProxy(object):
    def __init__(self, p_file_path, sample_type='FLOAT'):
        self._file_path = p_file_path
        self._sample_size = SAMPLE_SIZES[sample_type]
        self._sample_struct_type = '<'+SAMPLE_STRUCT_TYPES[sample_type]
        self.start_reading()
        
    def start_reading(self):
        try:
            self._data_file = open(self._file_path, 'rb')
        except IOError, e:
            LOGGER.error("An error occured while opening the data file!")
            raise(e)

    def finish_reading(self):
        self._data_file.close()
コード例 #2
0
ファイル: read_info_source.py プロジェクト: magdalena1/sleep
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import copy
import info_file_proxy
import signal_logging as logger
import signal_exceptions
LOGGER = logger.get_logger("read_info_source", "info")


class InfoSource(object):
    def get_param(self, p_key):
        LOGGER.error("The method must be subclassed")

    def get_params(self):
        LOGGER.error("The method must be subclassed")

    def set_params(self, p_params):
        LOGGER.error("The method must be subclassed")

    def update_params(self, p_params):
        LOGGER.error("The method must be subclassed")

    def set_param(self, k, v):
        LOGGER.error("The method must be subclassed")

    def reset_params(self):
        LOGGER.error("The method must be subclassed")
コード例 #3
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import os.path
import xml.dom.minidom
import signal_logging as logger
import signal_exceptions
from .. import types_utils
LOGGER = logger.get_logger("generic_info_file_proxy")


"""Below we have tags definitions - for every tag we have entry in format:
'tag_universal_name': (tag_type('list' or 'simple'), 
                       list of tag translations (one element for 'simple'
                                                 two elemenso for 'list')
                       )
"""
TAGS_DEFINITIONS = {
            'channels_names':
                ('list', ['channelLabels', 'label']),
            'channels_numbers':
                ('list', ['channelNumbers', 'number']),
            'channels_gains':
                ('list', ['calibrationGain', 'calibrationParam']),
コード例 #4
0
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#

import struct
import sys, os.path
from obci.configs import variables_pb2

import signal_exceptions
import signal_constants
import signal_logging as logger
LOGGER = logger.get_logger("data_generic_write_proxy", 'info')

SAMPLE_STRUCT_TYPES = signal_constants.SAMPLE_STRUCT_TYPES

class DataGenericWriteProxy(object):
    """
    A class representing data file. 
    It should be an abstraction for saving raw data into a file. 
    Decision whether save signal to one or few separate files should be made here 
    and should be transparent regarding below interface - the interface should remain untouched.
    Public interface:
    - finish_saving() - closes data file and return its path,
    - data_received(p_data_sample) - gets and saves next sample of signal
    """
    def __init__(self, p_file_path, p_unpack_later=False, p_append_ts=False, p_sample_type='FLOAT'):
        """Open p_file_name file in p_dir_path directory."""
        self._number_of_samples = 0
        self._unpack_later = p_unpack_later
コード例 #5
0
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#

import struct
import sys, os.path
from obci.configs import variables_pb2

import signal_exceptions
import signal_constants
import signal_logging as logger
LOGGER = logger.get_logger("data_generic_write_proxy", 'info')

SAMPLE_STRUCT_TYPES = signal_constants.SAMPLE_STRUCT_TYPES


class DataGenericWriteProxy(object):
    """
    A class representing data file. 
    It should be an abstraction for saving raw data into a file. 
    Decision whether save signal to one or few separate files should be made here 
    and should be transparent regarding below interface - the interface should remain untouched.
    Public interface:
    - finish_saving() - closes data file and return its path,
    - data_received(p_data_sample) - gets and saves next sample of signal
    """
    def __init__(self,
                 p_file_path,
                 p_unpack_later=False,
コード例 #6
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import os.path
import xml.dom.minidom
import signal_logging as logger
import signal_exceptions
from .. import types_utils
LOGGER = logger.get_logger("generic_info_file_proxy")
"""Below we have tags definitions - for every tag we have entry in format:
'tag_universal_name': (tag_type('list' or 'simple'), 
                       list of tag translations (one element for 'simple'
                                                 two elemenso for 'list')
                       )
"""
TAGS_DEFINITIONS = {
    'channels_names': ('list', ['channelLabels', 'label']),
    'channels_numbers': ('list', ['channelNumbers', 'number']),
    'channels_gains': ('list', ['calibrationGain', 'calibrationParam']),
    'channels_offsets': ('list', ['calibrationOffset', 'calibrationParam']),
    'number_of_samples': ('simple', ['sampleCount']),
    'number_of_channels': ('simple', ['channelCount']),
    'sampling_frequency': ('simple', ['samplingFrequency']),
    'first_sample_timestamp': ('simple', ['firstSampleTimestamp']),
コード例 #7
0
ファイル: info_file_proxy.py プロジェクト: BrainTech/openbci
#!/usr/bin/env python
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
"""Module implements specific info file manifest for svarog.
What is different from info_file_proxy:
- root name (here we haver rs:rawSignal and xmlns)
- tags namespace (here every tag has rs: previx)
- tags ordering (svarog requires specific tags ordering)
- additional tags (svarog requires only and only tags described in
  SvarogFileWriteProxy.ORDER)
"""

import generic_info_file_proxy
import signal_logging as logger
LOGGER = logger.get_logger("info_file_proxy")

class InfoDocument(generic_info_file_proxy.OpenBciDocument):
    """Subclass xml_document, so that we can add rs: prefix before every
    tag name."""
    prefix = 'rs:'
    def createElement(self, tagName):
        """Redefine the method so that every added tag has 'rs:' prefix."""
        return super(InfoDocument, self).createElement(
            ''.join([InfoDocument.prefix, tagName]))

class InfoFileWriteProxy(generic_info_file_proxy.GenericInfoFileWriteProxy):
    """Subclass write proxy - ensure that every element has rs: prefix,
    ensure tags ordering, ensure tags required by svarog."""
    ORDER = [
        'rs:exportFileName',
コード例 #8
0
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import numpy, copy
import data_read_proxy
import signal_logging as logger
import signal_exceptions
LOGGER = logger.get_logger("data_source", "info")

class DataSource(object):
    def get_samples(self, p_from=None, p_len=None):
        LOGGER.error("The method must be subclassed")

    def iter_samples(self):
        LOGGER.error("The method must be subclassed") 
    def __deepcopy(self, memo):
        return MemoryDataSource(copy.deepcopy(self.get_samples()))



class MemoryDataSource(DataSource):
    def __init__(self, p_data=None, p_copy=True, p_sample_source='FLOAT'):
        self._data = None

        if not (p_data is None):
            self.set_samples(p_data, p_copy)

    def set_samples(self, p_data, p_copy=True):
コード例 #9
0
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import numpy, copy
import data_read_proxy
import signal_logging as logger
import signal_exceptions
LOGGER = logger.get_logger("data_source", "info")

class DataSource(object):
    def get_samples(self, p_from=None, p_len=None):
        LOGGER.error("The method must be subclassed")

    def iter_samples(self):
        LOGGER.error("The method must be subclassed") 
    def __deepcopy(self, memo):
        return MemoryDataSource(copy.deepcopy(self.get_samples()))



class MemoryDataSource(DataSource):
    def __init__(self, p_data=None, p_copy=True, p_sample_source='DOUBLE'):
        self._data = None

        if not (p_data is None):
            self.set_samples(p_data, p_copy)

    def set_samples(self, p_data, p_copy=True):
コード例 #10
0
ファイル: read_info_source.py プロジェクト: BrainTech/openbci
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import copy
import info_file_proxy
import signal_logging as logger
import signal_exceptions
LOGGER = logger.get_logger("read_info_source", "info")

class InfoSource(object):
    def get_param(self, p_key):
        LOGGER.error("The method must be subclassed")
    def get_params(self):
        LOGGER.error("The method must be subclassed")
    def set_params(self, p_params):
        LOGGER.error("The method must be subclassed")
    def update_params(self, p_params):
        LOGGER.error("The method must be subclassed")
    def set_param(self, k, v):
        LOGGER.error("The method must be subclassed")
    def reset_params(self):
        LOGGER.error("The method must be subclassed")        
    def __deepcopy__(self, memo):
        return MemoryInfoSource(copy.deepcopy(self.get_params()))


class MemoryInfoSource(InfoSource):
    def __init__(self, p_params={}):
コード例 #11
0
ファイル: info_file_proxy.py プロジェクト: magdalena1/sleep
#!/usr/bin/env python
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
"""Module implements specific info file manifest for svarog.
What is different from info_file_proxy:
- root name (here we haver rs:rawSignal and xmlns)
- tags namespace (here every tag has rs: previx)
- tags ordering (svarog requires specific tags ordering)
- additional tags (svarog requires only and only tags described in
  SvarogFileWriteProxy.ORDER)
"""

import generic_info_file_proxy
import signal_logging as logger
LOGGER = logger.get_logger("info_file_proxy")


class InfoDocument(generic_info_file_proxy.OpenBciDocument):
    """Subclass xml_document, so that we can add rs: prefix before every
    tag name."""
    prefix = 'rs:'

    def createElement(self, tagName):
        """Redefine the method so that every added tag has 'rs:' prefix."""
        return super(InfoDocument, self).createElement(''.join(
            [InfoDocument.prefix, tagName]))


class InfoFileWriteProxy(generic_info_file_proxy.GenericInfoFileWriteProxy):
    """Subclass write proxy - ensure that every element has rs: prefix,
コード例 #12
0
ファイル: data_read_proxy.py プロジェクト: magdalena1/sleep
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# Author:
#     Mateusz Kruszyński <*****@*****.**>
#
import scipy, struct
import os.path, sys
import signal_exceptions
import signal_constants
import signal_logging as logger
LOGGER = logger.get_logger("data_read_proxy", 'info')
SAMPLE_SIZES = signal_constants.SAMPLE_SIZES
SAMPLE_STRUCT_TYPES = signal_constants.SAMPLE_STRUCT_TYPES


class DataReadProxy(object):
    def __init__(self, p_file_path, sample_type='FLOAT'):
        self._file_path = p_file_path
        self._sample_size = SAMPLE_SIZES[sample_type]
        self._sample_struct_type = '<' + SAMPLE_STRUCT_TYPES[sample_type]
        self.start_reading()

    def start_reading(self):
        try:
            self._data_file = open(self._file_path, 'rb')
        except IOError, e:
            LOGGER.error("An error occured while opening the data file!")
            raise (e)

    def finish_reading(self):
        self._data_file.close()