cleanup of text reader
This commit is contained in:
parent
a4950839d0
commit
2ed390ccae
@ -1,7 +1,7 @@
|
|||||||
from nmreval.io.asciireader import AsciiReader
|
from nmreval.io.asciireader import AsciiReader
|
||||||
|
|
||||||
from gui_qt.Qt import QtGui, QtCore, QtWidgets
|
from ..Qt import QtGui, QtCore, QtWidgets
|
||||||
from gui_qt._py.asciidialog import Ui_ascii_reader
|
from .._py.asciidialog import Ui_ascii_reader
|
||||||
|
|
||||||
|
|
||||||
class QAsciiReader(QtWidgets.QDialog, 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):
|
def skip_next_dial(self, _: int):
|
||||||
print('skippy das buschkänguru', _)
|
print('skippy das buschkänguru', _)
|
||||||
self.skip = self.skippy_checkbox.isChecked()
|
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()
|
|
||||||
|
@ -70,10 +70,10 @@ class Points:
|
|||||||
|
|
||||||
if x.shape != y.shape:
|
if x.shape != y.shape:
|
||||||
# remove ugly 1-length dims
|
# remove ugly 1-length dims
|
||||||
x = np.squeeze(x)
|
try:
|
||||||
y = np.squeeze(y)
|
y = y.reshape(x.shape)
|
||||||
if x.shape != y.shape:
|
except ValueError as e:
|
||||||
raise ValueError(f'x ({x.shape}) and y ({y.shape}) have different shapes')
|
raise ValueError(f'x ({x.shape}) and y ({y.shape}) have different shapes') from e
|
||||||
|
|
||||||
mask = np.ones_like(x, dtype=bool)
|
mask = np.ones_like(x, dtype=bool)
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class Points:
|
|||||||
y_err = np.atleast_1d(y_err)
|
y_err = np.atleast_1d(y_err)
|
||||||
if y_err.shape != y.shape:
|
if y_err.shape != y.shape:
|
||||||
raise ValueError(f'y_err ({y_err.shape}) and y ({y.shape}) have different shapes')
|
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
|
return x, y, y_err, mask
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
from itertools import islice
|
||||||
from itertools import islice, zip_longest
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@ -30,36 +29,6 @@ class AsciiReader:
|
|||||||
self.make_preview(10)
|
self.make_preview(10)
|
||||||
self.look_for_delay()
|
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='#'):
|
def read_header(self, comments='#'):
|
||||||
with self.fname.open('r') as f:
|
with self.fname.open('r') as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
|
Loading…
Reference in New Issue
Block a user