From 2ed390ccaea6e4093e782887983cbe69f6c7853d Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Fri, 30 Dec 2022 16:32:32 +0100 Subject: [PATCH] cleanup of text reader --- src/gui_qt/io/asciireader.py | 15 ++------------- src/nmreval/data/points.py | 10 +++++----- src/nmreval/io/asciireader.py | 33 +-------------------------------- 3 files changed, 8 insertions(+), 50 deletions(-) diff --git a/src/gui_qt/io/asciireader.py b/src/gui_qt/io/asciireader.py index d4bf67f..543654a 100644 --- a/src/gui_qt/io/asciireader.py +++ b/src/gui_qt/io/asciireader.py @@ -1,7 +1,7 @@ from nmreval.io.asciireader import AsciiReader -from gui_qt.Qt import QtGui, QtCore, QtWidgets -from gui_qt._py.asciidialog import Ui_ascii_reader +from ..Qt import QtGui, QtCore, QtWidgets +from .._py.asciidialog import Ui_ascii_reader class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): @@ -208,14 +208,3 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader): def skip_next_dial(self, _: int): print('skippy das buschkänguru', _) self.skip = self.skippy_checkbox.isChecked() - - -if __name__ == '__main__': - app = QtWidgets.QApplication([]) - # w = QAsciiReader(fname='/autohome/dominik/nmreval/testdata/T_1_omega/250.dat') - # w = QAsciiReader(fname='/autohome/dominik/nmreval/testdata/alter_fit_fitparameter.dat') - w = QAsciiReader(fname='/autohome/dominik/nmreval/testdata/alter_fit_fitparameter2.dat') - # w = QAsciiReader(fname='/autohome/dominik/nmreval/testdata/alter_fit_fit_200.dat') - - w.show() - app.exec() diff --git a/src/nmreval/data/points.py b/src/nmreval/data/points.py index f118a97..05854f4 100644 --- a/src/nmreval/data/points.py +++ b/src/nmreval/data/points.py @@ -70,10 +70,10 @@ class Points: if x.shape != y.shape: # remove ugly 1-length dims - x = np.squeeze(x) - y = np.squeeze(y) - if x.shape != y.shape: - raise ValueError(f'x ({x.shape}) and y ({y.shape}) have different shapes') + try: + y = y.reshape(x.shape) + except ValueError as e: + raise ValueError(f'x ({x.shape}) and y ({y.shape}) have different shapes') from e mask = np.ones_like(x, dtype=bool) @@ -86,7 +86,7 @@ class Points: y_err = np.atleast_1d(y_err) if y_err.shape != y.shape: raise ValueError(f'y_err ({y_err.shape}) and y ({y.shape}) have different shapes') - + print(x, x.shape, x.ndim) return x, y, y_err, mask @property diff --git a/src/nmreval/io/asciireader.py b/src/nmreval/io/asciireader.py index 7265ad6..979c560 100644 --- a/src/nmreval/io/asciireader.py +++ b/src/nmreval/io/asciireader.py @@ -1,7 +1,6 @@ import pathlib import re -from collections import OrderedDict -from itertools import islice, zip_longest +from itertools import islice import numpy as np @@ -30,36 +29,6 @@ class AsciiReader: self.make_preview(10) self.look_for_delay() - def load_file(self, comments='#'): - i = 0 - with self.fname.open('r') as f: - for line in f: - line = line.rstrip('\n\t\r, ') - - if line.startswith(comments): - self.header.append(line.replace(comments, '').strip()) - - else: - if line == '': - continue - line = re.split('[\s,;]', line) - try: - comment_start = line.index('#') - self.line_comment.append(' '.join(line[comment_start:])) - line = line[:comment_start] - except ValueError: - self.line_comment.append('') - - self.width = max(self.width, len(line)) - self.data.append(line) - - i += 1 - if i == self.maxcount: - break - - if all(l == '' for l in self.line_comment): - self.line_comment = [] - def read_header(self, comments='#'): with self.fname.open('r') as f: for line in f.readlines():