From 8690cb222ea96b5721988d1b75e24baac3ede41e Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 16 Mar 2023 18:49:44 +0000 Subject: [PATCH] ignore errors due to wrong encoding in agr files (#22) Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/22 --- src/gui_qt/io/gracereader.py | 3 +++ src/nmreval/io/graceeditor.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui_qt/io/gracereader.py b/src/gui_qt/io/gracereader.py index f563239..26b15ff 100644 --- a/src/gui_qt/io/gracereader.py +++ b/src/gui_qt/io/gracereader.py @@ -1,3 +1,5 @@ +import numpy as np + from nmreval.lib.lines import LineStyle from nmreval.lib.symbols import SymbolStyle from nmreval.data.points import Points @@ -90,6 +92,7 @@ class QGraceReader(QtWidgets.QDialog, Ui_Dialog): label = self._reader.get_property(*key, 'legend').replace('"', '') # label = self._reader.graphs[key[0]].sets[key[1]]['legend'].replace('"', '') sd = s.data + sd = np.atleast_2d(sd) if s.type == 'xydy': data.append(Points(x=sd[:, 0], y=sd[:, 1], y_err=sd[:, 2], name=label)) else: diff --git a/src/nmreval/io/graceeditor.py b/src/nmreval/io/graceeditor.py index 61c27db..58a114e 100644 --- a/src/nmreval/io/graceeditor.py +++ b/src/nmreval/io/graceeditor.py @@ -1,5 +1,6 @@ from __future__ import annotations +import codecs import pathlib import re import warnings @@ -104,9 +105,8 @@ class GraceEditor: # we start always with the header current_pos = 'header' - with self.file.open('r') as f: + with self.file.open('r', errors='replace') as f: for line_nr, line in enumerate(f): - # lots of states to check # agr file order: header, drawing object, region, graph, set if current_pos == 'header':