diff --git a/secop_psi/softcal.py b/secop_psi/softcal.py index e7baf00..a56c865 100644 --- a/secop_psi/softcal.py +++ b/secop_psi/softcal.py @@ -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