# -*- 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()
# -*- 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")
# 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']),
# -*- 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
# -*- 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,
# 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']),
#!/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',
# -*- 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):
# -*- 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):
# -*- 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={}):
#!/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,
# -*- 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()