__init__.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. McsPy
  3. ~~~~~
  4. McsPy is a Python module/package to read, handle and operate on HDF5-based raw data
  5. files converted from recordings of devices of the Multi Channel Systems MCS GmbH.
  6. :copyright: (c) 2015 by Multi Channel Systems MCS GmbH
  7. :license: see LICENSE for more details
  8. """
  9. #print("McsPy init!")
  10. version = 0.02
  11. # Supported MCS-HDF5 protocol types and versions:
  12. class McsHdf5Protocols:
  13. """
  14. Class of supported MCS-HDF5 protocol types and version ranges
  15. Entry: (Protocol Type Name => Tuple of supported version range from (including) the first version entry up to (including) the second version entry)
  16. """
  17. SUPPORTED_PROTOCOLS = {"RawData" : (1, 3), # from first to second version number and including this versions
  18. "InfoChannel" : (1, 1), # Info-Object Versions
  19. "FrameEntityInfo" : (1, 1),
  20. "EventEntityInfo" : (1, 1),
  21. "SegmentEntityInfo" : (1, 1),
  22. "TimeStampEntityInfo" : (1, 1),
  23. "AnalogStreamInfoVersion" : (1, 1), # StreamInfo-Object Versions
  24. "FrameStreamInfoVersion" : (1, 1),
  25. "EventStreamInfoVersion" : (1, 1),
  26. "SegmentStreamInfoVersion" : (1, 1),
  27. "TimeStampStreamInfoVersion" : (1, 1)}
  28. @classmethod
  29. def check_protocol_type_version(self, protocol_type_name, version):
  30. """
  31. Check if the given version of a protocol is supported by the implementation
  32. :param protocol_type_name: name of the protocol that is tested
  33. :param version: version number that should be checked
  34. :returns: is true if the given protocol and version is supported
  35. """
  36. if McsHdf5Protocols.SUPPORTED_PROTOCOLS.has_key(protocol_type_name):
  37. supported_versions = McsHdf5Protocols.SUPPORTED_PROTOCOLS[protocol_type_name]
  38. if (version < supported_versions[0]) or (supported_versions[1] < version):
  39. raise IOError('Given HDF5 file contains \'%s\' type of version %s and supported are only all versions from %s up to %s' %
  40. (protocol_type_name, version, supported_versions[0], supported_versions[1]))
  41. else:
  42. raise IOError("The given HDF5 contains a type \'%s\' that is unknown in this implementation!" % protocol_type_name)
  43. return True
  44. from pint import UnitRegistry
  45. ureg = UnitRegistry()
  46. Q_ = ureg.Quantity