make softcal more tolerant reading .340 files

accept tab instead of space in 'Data Format' header keyword

Change-Id: I77e5500da5eaed6fd1097723533bc86207fa73d8
This commit is contained in:
zolliker 2021-03-05 08:57:23 +01:00
parent bec3359069
commit 9b71d3621d

View File

@ -74,13 +74,18 @@ class Parser340(StdParser):
def parse(self, line):
"""scan header for data format"""
if self.header:
if line.startswith("Data Format"):
dataformat = line.split(":")[1].strip()[0]
if dataformat == '4':
self.logx, self.logy = True, False # logOhm
elif dataformat == '5':
self.logx, self.logy = True, True # logOhm, logK
elif line.startswith("No."):
key, _, value = line.partition(':')
if value: # this is a header line, as it contains ':'
value = value.split()[0]
key = ''.join(key.split()).lower()
if key == 'dataformat':
if value == '4':
self.logx, self.logy = True, False # logOhm
elif value == '5':
self.logx, self.logy = True, True # logOhm, logK
elif value not in ('1', '2', '3'):
raise ValueError('invalid Data Format')
elif line.contains('No.'):
self.header = False
return
super().parse(line)
@ -140,7 +145,10 @@ class CalCurve:
parser.parse(line)
self.convert_x = nplog if parser.logx else linear
self.convert_y = npexp if parser.logy else linear
self.spline = splrep(np.asarray(parser.xdata), np.asarray(parser.ydata), s=0)
try:
self.spline = splrep(np.asarray(parser.xdata), np.asarray(parser.ydata), s=0)
except:
raise ValueError('invalid curve, may be not monotonic?')
def __call__(self, value):
"""convert value