From 1fb2d87c42ccef2231a595076db7cbf6c57dbd00 Mon Sep 17 00:00:00 2001 From: zorba Date: Thu, 18 Oct 2018 10:45:24 -0500 Subject: [PATCH] add .ch 181 support --- PyExpLabSys/file_parsers/chemstation.py | 48 +++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/PyExpLabSys/file_parsers/chemstation.py b/PyExpLabSys/file_parsers/chemstation.py index a1ef060f..bbf77a1c 100644 --- a/PyExpLabSys/file_parsers/chemstation.py +++ b/PyExpLabSys/file_parsers/chemstation.py @@ -379,6 +379,7 @@ def __repr__(self): UINT16 = ENDIAN + 'H' INT16 = ENDIAN + 'h' INT32 = ENDIAN + 'i' +UINT32 = ENDIAN + 'I' def parse_utf16_string(file_, encoding='UTF16'): @@ -435,10 +436,13 @@ class CHFile(object): ('detector', 4213, 'utf16'), ('yscaling', 4732, ENDIAN + 'd') ) + # Fields in version file version 181 are different for software info + fields_revtwo = tuple(filter(lambda x: x[1] not in [3601,3089,3802], fields)) + # The start position of the data data_start = 6144 # The versions of the file format supported by this implementation - supported_versions = {179} + supported_versions = {179, 181} def __init__(self, filepath): """Instantiate object @@ -450,7 +454,10 @@ def __init__(self, filepath): self.metadata = {} with open(self.filepath, 'rb') as file_: self._parse_header(file_) - self.values = self._parse_data(file_) + if self.metadata['magic_number_version'] == 179: + self.values = self._parse_data(file_) + elif self.metadata['magic_number_version'] == 181: + self.values = self._parse_data_decompress(file_) def _parse_header(self, file_): """Parse the header""" @@ -461,6 +468,8 @@ def _parse_header(self, file_): if version not in self.supported_versions: raise ValueError('Unsupported file version {}'.format(version)) self.metadata['magic_number_version'] = version + if version == 181: + self.fields = self.fields_revtwo # Parse all metadata fields for name, offset, type_ in self.fields: @@ -548,6 +557,41 @@ def _parse_data(self, file_): file_.seek(self.data_start) return numpy.fromfile(file_, dtype='