Skip to content

Commit

Permalink
Version 0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
armwal committed May 19, 2022
2 parents 8d47821 + 0bfab6b commit 3d2a863
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 35 deletions.
12 changes: 2 additions & 10 deletions McsPyDataTools/McsPy/McsCMOSMEA.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,22 +581,14 @@ def validate_mcs_hdf5_version(mcs_h5_file_obj):
mcs_hdf5_protocol_type = root_grp.attrs['McsHdf5ProtocolType'].decode('UTF-8')
if mcs_hdf5_protocol_type == "RawData":
mcs_hdf5_protocol_type_version = root_grp.attrs['McsHdf5ProtocolVersion']
supported_versions = McsHdf5Protocols.SUPPORTED_PROTOCOLS[mcs_hdf5_protocol_type]
if ((mcs_hdf5_protocol_type_version < supported_versions[0]) or
(supported_versions[1] < mcs_hdf5_protocol_type_version)):
raise IOError('Given HDF5 file has MCS-HDF5 RawData protocol version %s and supported are all versions from %s to %s' %
(mcs_hdf5_protocol_type_version, supported_versions[0], supported_versions[1]))
McsHdf5Protocols.check_hdf5_protocol_version(mcs_hdf5_protocol_type, mcs_hdf5_protocol_type_version)
else:
raise IOError("The root group of this HDF5 file has no 'McsHdf5ProtocolVersion' attribute -> so it could't be checked if the version is supported!")
elif 'ID.Type' in root_grp.attrs: #check for CMOS MEA file type
mcs_hdf5_protocol_type = "CMOS_MEA"
if 'FileVersion' in root_grp.attrs:
mcs_hdf5_protocol_type_version = root_grp.attrs['FileVersion']
supported_versions = McsHdf5Protocols.SUPPORTED_PROTOCOLS[mcs_hdf5_protocol_type]
if ((mcs_hdf5_protocol_type_version[0] < supported_versions[0]) or
(supported_versions[1] < mcs_hdf5_protocol_type_version[0])):
raise IOError('Given HDF5 file has MCS-HDF5 CMOS-MEA version %s and supported are all versions from %s to %s' %
(mcs_hdf5_protocol_type_version, supported_versions[0], supported_versions[1]))
McsHdf5Protocols.check_hdf5_protocol_version(mcs_hdf5_protocol_type, mcs_hdf5_protocol_type_version)
else:
raise IOError("The root group of this HDF5 file has no 'FileID' attribute -> so it could't be checked if the version is supported!")
else:
Expand Down
6 changes: 1 addition & 5 deletions McsPyDataTools/McsPy/McsData.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ def __validate_mcs_hdf5_version(self):
self.mcs_hdf5_protocol_type = root_grp.attrs['McsHdf5ProtocolType'].decode('UTF-8')
if self.mcs_hdf5_protocol_type == "RawData":
self.mcs_hdf5_protocol_type_version = root_grp.attrs['McsHdf5ProtocolVersion']
supported_versions = McsHdf5Protocols.SUPPORTED_PROTOCOLS[self.mcs_hdf5_protocol_type]
if ((self.mcs_hdf5_protocol_type_version < supported_versions[0]) or
(supported_versions[1] < self.mcs_hdf5_protocol_type_version)):
raise IOError('Given HDF5 file has MCS-HDF5 RawData protocol version %s and supported are all versions from %s to %s' %
(self.mcs_hdf5_protocol_type_version, supported_versions[0], supported_versions[1]))
McsHdf5Protocols.check_hdf5_protocol_version(self.mcs_hdf5_protocol_type, self.mcs_hdf5_protocol_type_version)
else:
raise IOError("The root group of this HDF5 file has no 'McsHdf5ProtocolVersion' attribute -> so it could't be checked if the version is supported!")
else:
Expand Down
61 changes: 45 additions & 16 deletions McsPyDataTools/McsPy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
:license: see LICENSE for more details
"""

#print("McsPy init!")
version = "0.4.2"
version = "0.4.3"

#__all__ = ["CMOSData", "CMOSConvProxy", "RawData", "Recording", "Stream", "AnalogStream",
# "Info", "InfoSampledData", "ChannelInfo", "FrameStream", "FrameEntity", "Frame",
Expand All @@ -25,18 +24,18 @@ class McsHdf5Protocols:
Entry: (Protocol Type Name => Tuple of supported version range from (including) the first version entry up to (including) the second version entry)
"""
SUPPORTED_PROTOCOLS = {"RawData" : (1, 3), # from first to second version number and including this versions
"CMOS_MEA" : (1, 1), #from first to first version
"InfoChannel" : (1, 2), # Info-Object Versions
"FrameEntityInfo" : (1, 1),
"EventEntityInfo" : (1, 1),
"SegmentEntityInfo" : (1, 4),
"TimeStampEntityInfo" : (1, 1),
"AnalogStreamInfoVersion" : (1, 1), # StreamInfo-Object Versions
"FrameStreamInfoVersion" : (1, 1),
"EventStreamInfoVersion" : (1, 1),
"SegmentStreamInfoVersion" : (1, 1),
"TimeStampStreamInfoVersion" : (1, 1)}
SUPPORTED_PROTOCOLS = {"RawData" : (1, -1), # from first to second version number and including this versions. If second version number is -1, accept all later versions
"CMOS_MEA" : (1, -1),
"InfoChannel" : (1, -1), # Info-Object Versions
"FrameEntityInfo" : (1, -1),
"EventEntityInfo" : (1, -1),
"SegmentEntityInfo" : (1, -1),
"TimeStampEntityInfo" : (1, -1),
"AnalogStreamInfoVersion" : (1, -1), # StreamInfo-Object Versions
"FrameStreamInfoVersion" : (1, -1),
"EventStreamInfoVersion" : (1, -1),
"SegmentStreamInfoVersion" : (1, -1),
"TimeStampStreamInfoVersion" : (1, -1)}

@classmethod
def check_protocol_type_version(self, protocol_type_name, version):
Expand All @@ -49,13 +48,43 @@ def check_protocol_type_version(self, protocol_type_name, version):
"""
if protocol_type_name in McsHdf5Protocols.SUPPORTED_PROTOCOLS:
supported_versions = McsHdf5Protocols.SUPPORTED_PROTOCOLS[protocol_type_name]
if (version < supported_versions[0]) or (supported_versions[1] < version):
raise IOError('Given HDF5 file contains \'%s\' type of version %s and supported are only all versions from %s up to %s' %
if not McsHdf5Protocols.check_version(version, supported_versions):
if (supported_versions[1] == -1):
raise IOError('Given HDF5 file contains \'%s\' type of version %s and supported are only versions from %s and later' %
(protocol_type_name, version, supported_versions[0]))
else:
raise IOError('Given HDF5 file contains \'%s\' type of version %s and supported are all versions from %s up to %s' %
(protocol_type_name, version, supported_versions[0], supported_versions[1]))
else:
raise IOError("The given HDF5 contains a type \'%s\' that is unknown in this implementation!" % protocol_type_name)
return True

@classmethod
def check_hdf5_protocol_version(self, protocol_name, version):
"""
Check if the given version of the HDF5 protocol is supported
:param protocol_name: name of the protocol that is tested
:param version: version number that should be checked
:returns: is true if the given protocol and version is supported
"""
if protocol_name in McsHdf5Protocols.SUPPORTED_PROTOCOLS:
supported_versions = McsHdf5Protocols.SUPPORTED_PROTOCOLS[protocol_name]
if not McsHdf5Protocols.check_version(version, supported_versions):
if (supported_versions[1] == -1):
raise IOError('Given HDF5 file has MCS-HDF5 %s protocol version %s and supported are all versions from %s and later' %
(protocol_name, version, supported_versions[0]))
else:
raise IOError('Given HDF5 file has MCS-HDF5 %s protocol version %s and supported are all versions from %s up to %s' %
(protocol_name, version, supported_versions[0], supported_versions[1]))
else:
raise IOError("The given HDF5 contains a HDF5 protocol \'%s\' that is unknown in this implementation!" % protocol_name)
return True

@classmethod
def check_version(self, version, supported_versions):
return version >= supported_versions[0] and (supported_versions[1] == -1 or version <= supported_versions[1])

# Supported MCS-HDF5 file structure types and versions:
class McsHdf5Types:
"""
Expand Down
5 changes: 2 additions & 3 deletions McsPyDataTools/McsPy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
McsPy is a Python module/package to read, handle and operate on HDF5-based raw data
files converted from recordings of devices of the Multi Channel Systems MCS GmbH.
:copyright: (c) 2018 by Multi Channel Systems MCS GmbH
:copyright: (c) 2022 by Multi Channel Systems MCS GmbH
:license: see LICENSE for more details
"""

#print("McsPy init!")
version = "0.4.1"
version = "0.4.3"

from pint import UnitRegistry
ureg = UnitRegistry()
Expand Down
2 changes: 1 addition & 1 deletion McsPyDataTools/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Feature list
============

* Read HDF5 data files that are compliant to the MCS-HDF5 Raw-Data protocol v. 3 (usually generated by the HDF5 export function of the Multi Channel DataManager)
* Read data files that are compliant to the HDF5 based MCS-CMOS-MEA RawData format CMOS-MEA RawData protocol v. 1 (generated by CMOS-MEA-Control) and ProcessedData format CMOS-MEA ProcessedData v. 1 (generated by CMOS-MEA-Tools)
* Read data files that are compliant to the HDF5 based MCS-CMOS-MEA RawData format CMOS-MEA RawData protocol v. 1 and v. 2 (generated by CMOS-MEA-Control) and ProcessedData format CMOS-MEA ProcessedData v. 1 (generated by CMOS-MEA-Tools)
* Provides structures to get the recorded raw ADC integer values and the meta data of every stream
* Provides methods to get the measured values and timestamps in the correct context of the recording (scale, physical unit, ... etc.)

Expand Down

0 comments on commit 3d2a863

Please sign in to comment.