add "index" keyword to ascii reader to use row number; part of #135
This commit is contained in:
parent
8772fa9e7a
commit
aff9cd31a7
@ -312,7 +312,23 @@ class Ui_ascii_reader(object):
|
||||
self.tabWidget.setCurrentIndex(0)
|
||||
self.buttonbox.rejected.connect(ascii_reader.close) # type: ignore
|
||||
QtCore.QMetaObject.connectSlotsByName(ascii_reader)
|
||||
ascii_reader.setTabOrder(self.tabWidget, self.ascii_table)
|
||||
ascii_reader.setTabOrder(self.tabWidget, self.column_checkBox)
|
||||
ascii_reader.setTabOrder(self.column_checkBox, self.line_spinBox)
|
||||
ascii_reader.setTabOrder(self.line_spinBox, self.preview_spinBox)
|
||||
ascii_reader.setTabOrder(self.preview_spinBox, self.pts_radioButton)
|
||||
ascii_reader.setTabOrder(self.pts_radioButton, self.dsc_radioButton)
|
||||
ascii_reader.setTabOrder(self.dsc_radioButton, self.FID_radioButton)
|
||||
ascii_reader.setTabOrder(self.FID_radioButton, self.spectrum_radioButton)
|
||||
ascii_reader.setTabOrder(self.spectrum_radioButton, self.bds_radioButton)
|
||||
ascii_reader.setTabOrder(self.bds_radioButton, self.x_lineedit)
|
||||
ascii_reader.setTabOrder(self.x_lineedit, self.y_lineedit)
|
||||
ascii_reader.setTabOrder(self.y_lineedit, self.deltay_lineEdit)
|
||||
ascii_reader.setTabOrder(self.deltay_lineEdit, self.re_button)
|
||||
ascii_reader.setTabOrder(self.re_button, self.regex_input)
|
||||
ascii_reader.setTabOrder(self.regex_input, self.re_match_index)
|
||||
ascii_reader.setTabOrder(self.re_match_index, self.custom_button)
|
||||
ascii_reader.setTabOrder(self.custom_button, self.custom_input)
|
||||
ascii_reader.setTabOrder(self.custom_input, self.ascii_table)
|
||||
ascii_reader.setTabOrder(self.ascii_table, self.delay_textfield)
|
||||
ascii_reader.setTabOrder(self.delay_textfield, self.delay_lineedit)
|
||||
ascii_reader.setTabOrder(self.delay_lineedit, self.start_lineedit)
|
||||
@ -321,6 +337,7 @@ class Ui_ascii_reader(object):
|
||||
ascii_reader.setTabOrder(self.log_checkBox, self.staggered_checkBox)
|
||||
ascii_reader.setTabOrder(self.staggered_checkBox, self.stag_lineEdit)
|
||||
ascii_reader.setTabOrder(self.stag_lineEdit, self.pushButton)
|
||||
ascii_reader.setTabOrder(self.pushButton, self.skippy_checkbox)
|
||||
|
||||
def retranslateUi(self, ascii_reader):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
@ -336,9 +353,9 @@ class Ui_ascii_reader(object):
|
||||
self.spectrum_radioButton.setText(_translate("ascii_reader", "Spectrum"))
|
||||
self.bds_radioButton.setText(_translate("ascii_reader", "BDS"))
|
||||
self.label_7.setText(_translate("ascii_reader", "Use columns as"))
|
||||
self.y_lineedit.setToolTip(_translate("ascii_reader", "<html><head/><body><p>Specify which columns are read for y-values. (\'Points\': Every number creates a new data set;\'FID\'/\'Spectrum\': Numbers at even positions are used for real parts, at odd positions for imaginary parts.)</p></body></html>"))
|
||||
self.y_lineedit.setToolTip(_translate("ascii_reader", "<html><head/><body><p>Specify which columns are used for y values.</p><p>- \'Points\': Every number creates a new data set;<br/>- \'FID\'/\'Spectrum\': Numbers at even positions are used for real parts, at odd positions for imaginary parts.</p></body></html>"))
|
||||
self.y_label.setText(_translate("ascii_reader", "y"))
|
||||
self.x_lineedit.setToolTip(_translate("ascii_reader", "<html><head/><body><p>Specify which column is used as x-value.</p></body></html>"))
|
||||
self.x_lineedit.setToolTip(_translate("ascii_reader", "<html><head/><body><p>Specify which column is used for x values, write <span style=\" font-style:italic;\">index</span> to use row numbers (starting with 0). </p></body></html>"))
|
||||
self.label_5.setText(_translate("ascii_reader", "<html><head/><body><p>Δy</p></body></html>"))
|
||||
self.x_label.setText(_translate("ascii_reader", "x"))
|
||||
self.dsdfsf.setText(_translate("ascii_reader", "Numerical value"))
|
||||
|
@ -179,9 +179,13 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
|
||||
|
||||
def apply(self):
|
||||
# default row for x is the first row, it will be superseded if an integer number is given.
|
||||
try:
|
||||
x = int(self.x_lineedit.text())-1
|
||||
except ValueError:
|
||||
x = self.x_lineedit.text()
|
||||
if x:
|
||||
try:
|
||||
x = int(x)-1
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
x = None
|
||||
|
||||
try:
|
||||
|
@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pathlib
|
||||
import re
|
||||
from io import BytesIO
|
||||
@ -87,7 +89,7 @@ class AsciiReader:
|
||||
|
||||
def export(
|
||||
self: 'AsciiReader',
|
||||
x: int = None,
|
||||
x: int | str = None,
|
||||
y: list = None,
|
||||
yerr: list = None,
|
||||
mode: str = 'points',
|
||||
@ -104,18 +106,20 @@ class AsciiReader:
|
||||
elif y is None:
|
||||
raise ValueError('y is None and yerr is not None')
|
||||
|
||||
if (x is None) ^ (y is None):
|
||||
raise ValueError(f'x is {type(x)} and y is {type(y)}, should be both None or both defined')
|
||||
# if (x is None) ^ (y is None):
|
||||
# raise ValueError(f'x is {type(x)} and y is {type(y)}, should be both None or both defined')
|
||||
|
||||
if x is None:
|
||||
x = [0]
|
||||
elif isinstance(x, int):
|
||||
x = [x]
|
||||
elif isinstance(x, str) and x == 'index':
|
||||
x = []
|
||||
else:
|
||||
raise ValueError(f'x is {type(x)} not int')
|
||||
raise ValueError(f'type of x is {type(x)} not `int` or `str`')
|
||||
|
||||
if y is None:
|
||||
y = list(range(1, max(self.width)))
|
||||
y = list(range(int(len(x) != 0), max(self.width)))
|
||||
|
||||
cols = x + y + yerr
|
||||
with self.fname.open('rb') as fh:
|
||||
@ -138,6 +142,17 @@ class AsciiReader:
|
||||
else:
|
||||
raw_data = raw_data.reshape((1, *raw_data.shape))
|
||||
|
||||
if len(x) == 0 or raw_data.shape[2] == 1:
|
||||
_temp = np.zeros((raw_data.shape[0], raw_data.shape[1], raw_data.shape[2]+1))
|
||||
_temp[:, :, 0] = np.arange(raw_data.shape[1])
|
||||
_temp[:, :, 1:] = raw_data
|
||||
raw_data = _temp
|
||||
|
||||
if y:
|
||||
y = [i+1 for i in y]
|
||||
else:
|
||||
y = [1]
|
||||
|
||||
filename = self.fname.stem
|
||||
|
||||
if self.delays:
|
||||
|
@ -236,7 +236,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Specify which columns are read for y-values. ('Points': Every number creates a new data set;'FID'/'Spectrum': Numbers at even positions are used for real parts, at odd positions for imaginary parts.)</p></body></html></string>
|
||||
<string><html><head/><body><p>Specify which columns are used for y values.</p><p>- 'Points': Every number creates a new data set;<br/>- 'FID'/'Spectrum': Numbers at even positions are used for real parts, at odd positions for imaginary parts.</p></body></html></string>
|
||||
</property>
|
||||
<property name="inputMethodHints">
|
||||
<set>Qt::ImhFormattedNumbersOnly|Qt::ImhPreferNumbers</set>
|
||||
@ -259,7 +259,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Specify which column is used as x-value.</p></body></html></string>
|
||||
<string><html><head/><body><p>Specify which column is used for x values, write <span style=" font-style:italic;">index</span> to use row numbers (starting with 0). </p></body></html></string>
|
||||
</property>
|
||||
<property name="inputMethodHints">
|
||||
<set>Qt::ImhFormattedNumbersOnly|Qt::ImhPreferNumbers</set>
|
||||
@ -620,6 +620,22 @@
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>column_checkBox</tabstop>
|
||||
<tabstop>line_spinBox</tabstop>
|
||||
<tabstop>preview_spinBox</tabstop>
|
||||
<tabstop>pts_radioButton</tabstop>
|
||||
<tabstop>dsc_radioButton</tabstop>
|
||||
<tabstop>FID_radioButton</tabstop>
|
||||
<tabstop>spectrum_radioButton</tabstop>
|
||||
<tabstop>bds_radioButton</tabstop>
|
||||
<tabstop>x_lineedit</tabstop>
|
||||
<tabstop>y_lineedit</tabstop>
|
||||
<tabstop>deltay_lineEdit</tabstop>
|
||||
<tabstop>re_button</tabstop>
|
||||
<tabstop>regex_input</tabstop>
|
||||
<tabstop>re_match_index</tabstop>
|
||||
<tabstop>custom_button</tabstop>
|
||||
<tabstop>custom_input</tabstop>
|
||||
<tabstop>ascii_table</tabstop>
|
||||
<tabstop>delay_textfield</tabstop>
|
||||
<tabstop>delay_lineedit</tabstop>
|
||||
@ -629,6 +645,7 @@
|
||||
<tabstop>staggered_checkBox</tabstop>
|
||||
<tabstop>stag_lineEdit</tabstop>
|
||||
<tabstop>pushButton</tabstop>
|
||||
<tabstop>skippy_checkbox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
@ -650,7 +667,7 @@
|
||||
</connection>
|
||||
</connections>
|
||||
<buttongroups>
|
||||
<buttongroup name="buttonGroup_2"/>
|
||||
<buttongroup name="buttonGroup"/>
|
||||
<buttongroup name="buttonGroup_2"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user