From a300182153af917f26efff1dbe039f4d79e90664 Mon Sep 17 00:00:00 2001 From: dominik Date: Thu, 24 Mar 2022 20:24:28 +0100 Subject: [PATCH] removed __name__ == __main__ --- nmreval/data/points.py | 18 ++++--- nmreval/distributions/base.py | 3 +- nmreval/distributions/coledavidson.py | 16 ------- nmreval/distributions/energy.py | 25 ---------- nmreval/distributions/intermolecular.py | 16 ------- nmreval/distributions/kww.py | 24 +--------- nmreval/distributions/loggaussian.py | 18 +------ nmreval/gui_qt/data/container.py | 48 ++++++++++++++----- nmreval/gui_qt/data/conversion.py | 21 +------- nmreval/gui_qt/data/datawidget/datawidget.py | 3 ++ nmreval/gui_qt/data/plot_dialog.py | 9 ---- nmreval/gui_qt/data/shift_graphs.py | 14 ------ nmreval/gui_qt/fit/fitfunction.py | 25 ++-------- nmreval/gui_qt/fit/fitwindow.py | 29 ++--------- .../gui_qt/fit/function_creation_dialog.py | 13 +---- nmreval/gui_qt/graphs/guide_lines.py | 19 -------- nmreval/gui_qt/graphs/movedialog.py | 14 ------ nmreval/gui_qt/io/bdsreader.py | 19 ++------ nmreval/gui_qt/io/dscreader.py | 20 ++------ nmreval/gui_qt/io/fcbatchreader.py | 9 ---- nmreval/gui_qt/io/filereaders.py | 4 -- nmreval/gui_qt/io/gracereader.py | 10 ---- nmreval/gui_qt/io/hdfreader.py | 12 ----- nmreval/gui_qt/io/save_fitparameter.py | 13 ----- nmreval/gui_qt/lib/color_dialog.py | 17 ++----- nmreval/gui_qt/lib/gol.py | 7 --- nmreval/gui_qt/lib/randpok.py | 9 ---- nmreval/gui_qt/lib/stuff.py | 11 +---- nmreval/gui_qt/lib/usermodeleditor.py | 11 ----- nmreval/gui_qt/main/management.py | 11 +++-- nmreval/gui_qt/math/evaluation.py | 18 ------- nmreval/gui_qt/math/interpol.py | 18 ------- nmreval/gui_qt/math/smooth.py | 10 ---- nmreval/gui_qt/nmr/coupling_calc.py | 8 ---- nmreval/gui_qt/nmr/t1_from_tau.py | 14 +----- nmreval/io/fcbatchreader.py | 11 ----- nmreval/lib/logger.py | 2 +- nmreval/math/mittagleffler.py | 8 ---- nmreval/math/orientations.py | 32 ------------- nmreval/math/wideline.py | 26 ---------- nmreval/models/fieldcycling.py | 10 ---- nmreval/models/gengamma.py | 30 ------------ nmreval/nmr/relaxation.py | 10 ++-- 43 files changed, 97 insertions(+), 568 deletions(-) diff --git a/nmreval/data/points.py b/nmreval/data/points.py index 084f182..2388486 100644 --- a/nmreval/data/points.py +++ b/nmreval/data/points.py @@ -14,10 +14,6 @@ from ..utils import NUMBER_RE PointLike = TypeVar('PointLike', bound='Points') -""" -This is a test for all and everything -""" - class Points: """ @@ -514,11 +510,19 @@ class Points: return self - def cut(self, *limits): - if len(limits) != 2: + def cut(self, low_lim=None, high_lim=None): + """ + Cut + Args: + low_lim: + high_lim: + + Returns: + + """ + if low_lim is None and high_lim is None: raise ValueError('Two arguments are needed') - low_lim, high_lim = limits if low_lim is None: low_lim = np.min(self._x) diff --git a/nmreval/distributions/base.py b/nmreval/distributions/base.py index 7d3695f..fb6eda8 100644 --- a/nmreval/distributions/base.py +++ b/nmreval/distributions/base.py @@ -1,10 +1,9 @@ import abc from typing import Any, Union - import numpy as np -from nmreval.lib.utils import ArrayLike +from ..lib.utils import ArrayLike class Distribution(abc.ABC): diff --git a/nmreval/distributions/coledavidson.py b/nmreval/distributions/coledavidson.py index 827901e..f19bf57 100644 --- a/nmreval/distributions/coledavidson.py +++ b/nmreval/distributions/coledavidson.py @@ -163,19 +163,3 @@ class ColeDavidson(Distribution): """ return gammaincc(gamma, t / tau) - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - - x = np.logspace(-3, 3, num=61) - - fig, ax = plt.subplots(2, 2) - - for g in [0.4, 0.6, 0.8]: - ax[0, 0].loglog(x, ColeDavidson.distribution(x, 1, g)) - ax[0, 1].semilogx(x, ColeDavidson.correlation(x, 1, g)) - ax[1, 0].loglog(x, ColeDavidson.specdens(x, 1, g)) - gr = ax[1, 1].loglog(x, ColeDavidson.susceptibility(x, 1, g).imag) - ax[1, 1].loglog(x, ColeDavidson.susceptibility(x, 1, g).real, '--', color=gr[0].get_color()) - plt.show() diff --git a/nmreval/distributions/energy.py b/nmreval/distributions/energy.py index 41e9d53..33653cc 100644 --- a/nmreval/distributions/energy.py +++ b/nmreval/distributions/energy.py @@ -97,28 +97,3 @@ class EnergyBarriers(Distribution): @staticmethod def max(*args): return args[1] * np.exp(args[2] / (kB * args[0])) - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - - x = np.logspace(-12, 12, num=601) - - fig, ax = plt.subplots(2, 2) - ax[0, 0].set_title('Distribution') - ax[0, 1].set_title('Correlation func.') - ax[1, 0].set_title('Spectral density') - ax[1, 1].set_title('Susceptibility') - - p = [1e-12, 0.3, 0.02] - - for a in [100, 150, 300]: - ax[0, 0].semilogx(x, EnergyBarriers.distribution(x, a, *p)) - ax[0, 1].semilogx(x, EnergyBarriers.correlation(x, a, *p)) - ax[1, 0].loglog(x, EnergyBarriers.specdens(x, a, *p)) - g = ax[1, 1].loglog(x, -EnergyBarriers.susceptibility(x, a, *p).imag) - ax[1, 1].loglog(x, EnergyBarriers.susceptibility(x, a, *p).real, '--', color=g[0].get_color()) - - fig.tight_layout() - - plt.show() diff --git a/nmreval/distributions/intermolecular.py b/nmreval/distributions/intermolecular.py index 8a20ce4..e736320 100644 --- a/nmreval/distributions/intermolecular.py +++ b/nmreval/distributions/intermolecular.py @@ -81,19 +81,3 @@ class FFHS(Distribution): # ret_val = np.array([simps(integrand(logaxis, o), logaxis) for o in omega]) # # return ret_val - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - - x = np.logspace(-3, 3, num=61) - - fig, ax = plt.subplots(2, 2) - - ax[0, 0].loglog(x, FFHS.distribution(x, 1)) - ax[0, 1].semilogx(x, FFHS.correlation(x, 1)) - ax[1, 0].loglog(x, FFHS.specdens(x, 1)) - ax[1, 1].loglog(x, FFHS.susceptibility(x, 1).real, - x, -FFHS.susceptibility(x, 1).imag) - fig.tight_layout() - plt.show() diff --git a/nmreval/distributions/kww.py b/nmreval/distributions/kww.py index 77132b4..aaa1e87 100644 --- a/nmreval/distributions/kww.py +++ b/nmreval/distributions/kww.py @@ -2,8 +2,8 @@ import numpy as np from scipy.interpolate import interp1d from scipy.special import gamma -from nmreval.lib.decorator import adjust_dims from .base import Distribution +from ..lib.decorator import adjust_dims from ..math.kww import kww_cos, kww_sin from ..utils.constants import Eu @@ -61,25 +61,3 @@ class KWW(Distribution): @staticmethod def max(tau, beta): return (1.7851 - 0.87052*beta - 0.028836*beta**2 + 0.11391*beta**3) * tau - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - - x = np.logspace(-3, 3, num=61) - - fig, ax = plt.subplots(2, 2) - ax[0, 0].set_title('Distribution') - ax[0, 1].set_title('Correlation func.') - ax[1, 0].set_title('Spectral density') - ax[1, 1].set_title('Susceptibility') - - for g in [0.3, 0.5, 0.7, 0.9]: - ax[0, 0].semilogx(x, KWW.distribution(x, 1, g)) - ax[0, 1].semilogx(x, KWW.correlation(x, 1, g)) - ax[1, 0].loglog(x, KWW.specdens(x, 1, g)) - a = ax[1, 1].loglog(x, KWW.susceptibility(x, 1, g).imag) - ax[1, 1].loglog(x, KWW.susceptibility(x, 1, g).real, '--', color=a[0].get_color()) - - fig.tight_layout() - plt.show() diff --git a/nmreval/distributions/loggaussian.py b/nmreval/distributions/loggaussian.py index bcaa7db..5aa3664 100644 --- a/nmreval/distributions/loggaussian.py +++ b/nmreval/distributions/loggaussian.py @@ -3,7 +3,7 @@ from itertools import product import numpy as np -from nmreval.lib.decorator import adjust_dims +from ..lib.decorator import adjust_dims try: from scipy.integrate import simpson @@ -122,19 +122,3 @@ def _integrand_freq_real_low(u, omega, tau, sigma): def _integrand_freq_real_high(u, omega, tau, sigma): uu = np.exp(-2*u) return LogGaussian.distribution(np.exp(u), tau, sigma) * uu / (uu + omega**2) - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - - x = np.logspace(-3, 3, num=61) - - fig, ax = plt.subplots(2, 2) - - for g in [1, 2, 5]: - ax[0, 0].loglog(x, LogGaussian.distribution(x, 1, g)) - ax[0, 1].semilogx(x, LogGaussian.correlation(x, 1, g)) - ax[1, 0].loglog(x, LogGaussian.specdens(1, x, g)) - gr = ax[1, 1].loglog(x, -LogGaussian.susceptibility(x, 1, g).imag) - ax[1, 1].loglog(x, LogGaussian.susceptibility(x, 1, g).real, '--', color=gr[0].get_color()) - plt.show() diff --git a/nmreval/gui_qt/data/container.py b/nmreval/gui_qt/data/container.py index 40b2267..e9302e7 100644 --- a/nmreval/gui_qt/data/container.py +++ b/nmreval/gui_qt/data/container.py @@ -49,7 +49,7 @@ class ExperimentContainer(QtCore.QObject): try: return self._data[item] except KeyError: - raise KeyError('Unknown key %s' % str(item)) + raise KeyError('Unknown key %s' % str(item)) from None def __del__(self): del self._data @@ -65,13 +65,23 @@ class ExperimentContainer(QtCore.QObject): def copy(self, full: bool = False): if full: + # pen_dict = { + # 'symbol': self.plot_real.symbol, + # 'symbolcolor': self.plot_real.symbolcolor, + # 'symbolsize': self.plot_real.symbolsize, + # 'linestyle': self.plot_real.linestyle, + # 'linecolor': self.plot_real.linecolor, + # 'linewidth': self.plot_real.linewidth, + # } + new_data = type(self)(str(self.id), self._data.copy(), manager=self._manager) new_data.mode = self.mode - for src, dest in [(self.plot_real, new_data.plot_real), (self.plot_imag, new_data.plot_imag)]: - if src is not None: - dest.set_symbol(symbol=src.symbol, size=src.symbolsize, color=src.symbolcolor) - dest.set_line(style=src.linestyle, width=src.linewidth, color=src.linecolor) + # if self.plot_imag is not None: + # new_data.plot_imag.set_symbol(symbol=self.plot_imag.symbol, size=self.plot_imag.symbolsize, + # color=self.plot_imag.symbolcolor) + # new_data.plot_imag.set_line(style=self.plot_imag.linestyle, width=self.plot_imag.linewidth, + # color=self.plot_imag.linecolor) return new_data @@ -86,16 +96,28 @@ class ExperimentContainer(QtCore.QObject): else: raise TypeError('Unknown data type') + # pen_dict = { + # 'symbol': self.plot_real.symbol, + # 'symbolcolor': self.plot_real.symbolcolor, + # 'symbolsize': self.plot_real.symbolsize, + # 'linestyle': self.plot_real.linestyle, + # 'linecolor': self.plot_real.linecolor, + # 'linewidth': self.plot_real.linewidth, + # } + new_data = new_type(str(self.id), data, manager=self._manager) - for src, dest in [(self.plot_real, new_data.plot_real), (self.plot_imag, new_data.plot_imag)]: - if dest is not None: - if src is not None: - dest.set_symbol(symbol=src.symbol, size=src.symbolsize, color=src.symbolcolor) - dest.set_line(style=src.linestyle, width=src.linewidth, color=src.linecolor) - else: - dest.set_symbol(symbol=self.plot_real.symbol, size=self.plot_real.symbolsize, color=self.plot_real.symbolcolor) - dest.set_line(style=self.plot_real.linestyle, width=self.plot_real.linewidth, color=self.plot_real.linecolor) + # if new_data.plot_imag is not None: + # if self.plot_imag is not None: + # new_data.plot_imag.set_symbol(symbol=self.plot_imag.symbol, size=self.plot_imag.symbolsize, + # color=self.plot_imag.symbolcolor) + # new_data.plot_imag.set_line(style=self.plot_imag.linestyle, width=self.plot_imag.linewidth, + # color=self.plot_imag.linecolor) + # else: + # new_data.plot_imag.set_symbol(symbol=self.plot_real.symbol, size=self.plot_real.symbolsize, + # color=self.plot_real.symbolcolor) + # new_data.plot_imag.set_line(style=self.plot_real.linestyle, width=self.plot_real.linewidth, + # color=self.plot_real.linecolor) return new_data diff --git a/nmreval/gui_qt/data/conversion.py b/nmreval/gui_qt/data/conversion.py index 2f8392b..ac1f38f 100644 --- a/nmreval/gui_qt/data/conversion.py +++ b/nmreval/gui_qt/data/conversion.py @@ -1,5 +1,5 @@ -from nmreval.gui_qt.Qt import QtWidgets, QtCore, QtGui -from nmreval.gui_qt._py.typeconversion import Ui_Dialog +from ..Qt import QtWidgets, QtCore, QtGui +from .._py.typeconversion import Ui_Dialog class ConversionDialog(QtWidgets.QDialog, Ui_Dialog): @@ -150,20 +150,3 @@ class ConversionDialog(QtWidgets.QDialog, Ui_Dialog): else: self.collect_args() self.accept() - - -if __name__ == '__main__': - import sys - from collections import OrderedDict - - app = QtWidgets.QApplication(sys.argv) - d = ConversionDialog() - - data = OrderedDict([ - (('1', 'Graph 0'), [('a', 'Das Sein und das Nichts'), ('b', 'b'), ('c', 'c'), ('d', 'd')]), - (('2', 'Graph 2'), [('e', 'e'), ('f', 'f'), ('g', 'g'), ('h', 'h')])]) - - d.set_graphs(data) - d.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/data/datawidget/datawidget.py b/nmreval/gui_qt/data/datawidget/datawidget.py index 61311bf..98c8440 100644 --- a/nmreval/gui_qt/data/datawidget/datawidget.py +++ b/nmreval/gui_qt/data/datawidget/datawidget.py @@ -324,6 +324,9 @@ class DataTree(QtWidgets.QTreeWidget): idx = {} has_fits = False for i in self.selectedIndexes(): + if i.column() == 0: + continue + item = self.itemFromIndex(i) parent = item.parent() if parent is None: diff --git a/nmreval/gui_qt/data/plot_dialog.py b/nmreval/gui_qt/data/plot_dialog.py index a49102a..9291bcc 100644 --- a/nmreval/gui_qt/data/plot_dialog.py +++ b/nmreval/gui_qt/data/plot_dialog.py @@ -112,12 +112,3 @@ class QPlotDialog(QtWidgets.QDialog, Ui_NewCurveDialog): lw = self.doubleSpinBox.value() sw = self.spinBox.value() - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication(sys.argv) - win = QPlotDialog() - win.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/data/shift_graphs.py b/nmreval/gui_qt/data/shift_graphs.py index 0fa7f32..fc49332 100644 --- a/nmreval/gui_qt/data/shift_graphs.py +++ b/nmreval/gui_qt/data/shift_graphs.py @@ -174,17 +174,3 @@ class SpinBoxDelegate(QtWidgets.QStyledItemDelegate): # geht bestimmt besser... table = self.sender().parent().parent() self.valueChanged.emit(table.currentRow(), table.currentColumn(), val) - - -if __name__ == '__main__': - import sys - - app = QtWidgets.QApplication(sys.argv) - mplQt = QShift() - xx = np.geomspace(1, 100) - mplQt.add_item('aa', 'a', xx, xx/(1+xx**2)*10) - mplQt.add_item('bb', 'b', xx, xx/(1+(0.1*xx)**2)) - mplQt.add_item('cc', 'c', xx, xx/(1+(0.01*xx)**2)/10) - mplQt.set_graphs([('123', 'zyx'), ('456', 'wvu')]) - mplQt.show() - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/fit/fitfunction.py b/nmreval/gui_qt/fit/fitfunction.py index bff72d2..32612b3 100644 --- a/nmreval/gui_qt/fit/fitfunction.py +++ b/nmreval/gui_qt/fit/fitfunction.py @@ -1,15 +1,15 @@ from itertools import cycle, count from typing import List, Tuple, Union -from nmreval.configs import config_paths +from .fit_forms import FitModelTree +from ..lib import get_icon +from .._py.fitfunctionwidget import Ui_Form +from ..Qt import QtWidgets, QtCore, QtGui +from ...configs import config_paths from ... import models from ...lib.importer import find_models from ...lib.colors import BaseColor, Tab10 from ...utils.text import convert -from ..Qt import QtWidgets, QtCore, QtGui -from .._py.fitfunctionwidget import Ui_Form -from .fit_forms import FitModelTree -from ..lib import get_icon class QFunctionWidget(QtWidgets.QWidget, Ui_Form): @@ -223,18 +223,3 @@ class QFunctionWidget(QtWidgets.QWidget, Ui_Form): self.complex_comboBox.setCurrentIndex(0) self.complex_widget.hide() - - -if __name__ == '__main__': - import sys - from numpy.random import choice - - app = QtWidgets.QApplication(sys.argv) - qw = choice(QtWidgets.QStyleFactory.keys()) - - app.setStyle(QtWidgets.QStyleFactory.create(qw)) - - fd = QFunctionWidget() - fd.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/fit/fitwindow.py b/nmreval/gui_qt/fit/fitwindow.py index 55099a9..c895c60 100644 --- a/nmreval/gui_qt/fit/fitwindow.py +++ b/nmreval/gui_qt/fit/fitwindow.py @@ -1,14 +1,14 @@ from itertools import count, cycle from string import ascii_letters -from pyqtgraph import PlotDataItem, mkPen +from pyqtgraph import mkPen -from nmreval.gui_qt.lib.pg_objects import PlotItem -from ...fit._meta import MultiModel, ModelFactory -from ..Qt import QtGui, QtCore, QtWidgets -from .._py.fitdialog import Ui_FitDialog from .fit_forms import FitTableWidget from .fit_parameter import QFitParameterWidget +from ..lib.pg_objects import PlotItem +from ..Qt import QtGui, QtCore, QtWidgets +from .._py.fitdialog import Ui_FitDialog +from ...fit._meta import MultiModel, ModelFactory class QFitDialog(QtWidgets.QWidget, Ui_FitDialog): @@ -434,22 +434,3 @@ class QFitDialog(QtWidgets.QWidget, Ui_FitDialog): self.preview_lines = [] super().closeEvent(evt) - - -if __name__ == '__main__': - import sys - from numpy.random import choice - - app = QtWidgets.QApplication(sys.argv) - # while qw == 'QtCurve': - qw = choice(QtWidgets.QStyleFactory.keys()) - app.setStyle(QtWidgets.QStyleFactory.create(qw)) - - fd = QFitDialog() - - fd.load([('fff', 'testtesttesttest'), - ('ggg', 'testtesttesttesttest'), - ('hhh', 'testtesttesttesttesttest')]) - fd.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/fit/function_creation_dialog.py b/nmreval/gui_qt/fit/function_creation_dialog.py index 0a9f07b..492e8ad 100644 --- a/nmreval/gui_qt/fit/function_creation_dialog.py +++ b/nmreval/gui_qt/fit/function_creation_dialog.py @@ -3,8 +3,8 @@ import re import numexpr as ne import numpy as np -from nmreval.gui_qt.Qt import QtCore, QtWidgets -from nmreval.gui_qt._py.fitcreationdialog import Ui_Dialog +from ..Qt import QtCore, QtWidgets +from .._py.fitcreationdialog import Ui_Dialog _numexpr_funcs = [] @@ -236,12 +236,3 @@ def func_decorator(f_string): return ne.evaluate(f_string, local_dict=namespace) return wrapped_f - - -if __name__ == '__main__': - import sys - - app = QtWidgets.QApplication([]) - w = QUserFitCreator() - w.show() - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/graphs/guide_lines.py b/nmreval/gui_qt/graphs/guide_lines.py index e821f55..b4b95fc 100644 --- a/nmreval/gui_qt/graphs/guide_lines.py +++ b/nmreval/gui_qt/graphs/guide_lines.py @@ -145,22 +145,3 @@ class LineWidget(QtWidgets.QWidget, Ui_Form): pos = line.value() text_item = self.tableWidget.item(i, 0) text_item.setText(text_item.text()[:4]+f'{pos:.4g}') - - -if __name__ == '__main__': - import sys - from numpy.random import choice - - app = QtWidgets.QApplication([]) - - qw = 'QtCurve' - while qw == 'QtCurve': - qw = choice(QtWidgets.QStyleFactory.keys()) - print(qw) - app.setStyle(QtWidgets.QStyleFactory.create(qw)) - - mplQt = LineWidget() - mplQt.show() - mplQt.set_graphs([('a', 'a'), ('b', 'b')]) - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/graphs/movedialog.py b/nmreval/gui_qt/graphs/movedialog.py index 5b7378b..21ad24a 100644 --- a/nmreval/gui_qt/graphs/movedialog.py +++ b/nmreval/gui_qt/graphs/movedialog.py @@ -73,17 +73,3 @@ class QMover(QtWidgets.QDialog, Ui_MoveDialog): self.entries = {} super().close() - - -if __name__ == '__main__': - import sys - global propData - - app = QtWidgets.QApplication([]) - - m = QMover() - m.setup({('a', '1'): ('z', '100'), ('b', '2'): ('y', '99'), ('c', '3'): ('x', '98')}) - - m.show() - - sys.exit(app.exec()) \ No newline at end of file diff --git a/nmreval/gui_qt/io/bdsreader.py b/nmreval/gui_qt/io/bdsreader.py index 7eaf259..5f3af5a 100644 --- a/nmreval/gui_qt/io/bdsreader.py +++ b/nmreval/gui_qt/io/bdsreader.py @@ -1,6 +1,6 @@ -from nmreval.io.bds_reader import BDSReader -from nmreval.gui_qt.Qt import QtCore, QtWidgets -from nmreval.gui_qt._py.bdsdialog import Ui_Dialog +from ...io.bds_reader import BDSReader +from ..Qt import QtCore, QtWidgets +from .._py.bdsdialog import Ui_Dialog class QBDSReader(QtWidgets.QDialog, Ui_Dialog): @@ -75,16 +75,3 @@ class QBDSReader(QtWidgets.QDialog, Ui_Dialog): self.data_read.emit(data) super().accept() - - -if __name__ == '__main__': - import sys - - app = QtWidgets.QApplication(sys.argv) - - reader = QBDSReader() - # reader('/autohome/dominik/nmreval/testdata/ZWEITECHANCE_EGD4H2O.EPS') - # reader('/autohome/dominik/nmreval/testdata/MZ-ME/CHLOROFORM_2017-02-06.EPS') - reader('/autohome/dominik/nmreval/testdata/SBA_5P4NM_ISOCHRON_150-300K_18-03-22.EPS') - reader.show() - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/io/dscreader.py b/nmreval/gui_qt/io/dscreader.py index e11eae5..42a4444 100644 --- a/nmreval/gui_qt/io/dscreader.py +++ b/nmreval/gui_qt/io/dscreader.py @@ -4,11 +4,10 @@ from typing import Union import numpy as np from pyqtgraph import PlotDataItem -from nmreval.data.points import Points -from nmreval.io.dsc import Cyclohexane, DSCCalibrator, DSCSample - -from nmreval.gui_qt.Qt import QtWidgets, QtCore -from nmreval.gui_qt._py.dscfile_dialog import Ui_Dialog +from ..Qt import QtWidgets, QtCore +from .._py.dscfile_dialog import Ui_Dialog +from ...data.points import Points +from ...io.dsc import Cyclohexane, DSCCalibrator, DSCSample class QDSCReader(QtWidgets.QDialog, Ui_Dialog): @@ -260,14 +259,3 @@ class ReferenceComboBox(QtWidgets.QComboBox): def get_reference(self): return self.references[self.currentIndex()] - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication(sys.argv) - - reader = QDSCReader(sample='/autohome/dominik/nmreval/testdata/dsc/20m_LiTFSI_H2O.txt', - empty='/autohome/dominik/nmreval/testdata/dsc/leer.txt', - reference='/autohome/dominik/nmreval/testdata/dsc/cyclohexan_10K-min.txt') - reader.show() - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/io/fcbatchreader.py b/nmreval/gui_qt/io/fcbatchreader.py index e94a750..40bf518 100644 --- a/nmreval/gui_qt/io/fcbatchreader.py +++ b/nmreval/gui_qt/io/fcbatchreader.py @@ -105,12 +105,3 @@ class QFCReader(QtWidgets.QDialog, Ui_FCEval_dialog): grp = self.graph_comboBox.currentData(QtCore.Qt.UserRole) self.data_read.emit(ret_vals, grp) - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication([]) - qfc = QFCReader() - qfc.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/io/filereaders.py b/nmreval/gui_qt/io/filereaders.py index 27d54ec..b2c3db5 100755 --- a/nmreval/gui_qt/io/filereaders.py +++ b/nmreval/gui_qt/io/filereaders.py @@ -127,7 +127,3 @@ class QFileReader(QtCore.QObject): # nothing matched, text file is best guess return 'txt' - - -if __name__ == '__main__': - pass diff --git a/nmreval/gui_qt/io/gracereader.py b/nmreval/gui_qt/io/gracereader.py index 7261571..57435f2 100644 --- a/nmreval/gui_qt/io/gracereader.py +++ b/nmreval/gui_qt/io/gracereader.py @@ -98,13 +98,3 @@ class QGraceReader(QtWidgets.QDialog, Ui_Dialog): def close(self): self._reader.clear() super().close() - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication(sys.argv) - - reader = QGraceReader() - reader.read('/autohome/dominik/nmreval/testdata/02_relax_2.agr') - reader.show() - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/io/hdfreader.py b/nmreval/gui_qt/io/hdfreader.py index e0c673c..9a042c2 100644 --- a/nmreval/gui_qt/io/hdfreader.py +++ b/nmreval/gui_qt/io/hdfreader.py @@ -182,15 +182,3 @@ class HDFTreeWidget(QtWidgets.QTreeWidget): for i in range(item.childCount()): child = item.child(i) child.setCheckState(column, state) - - -if __name__ == '__main__': - import sys - - app = QtWidgets.QApplication([]) - # w = QHdfViewer('/autohome/dominik/nmreval/testdata/fc_test/abc.h5') - w = QHdfViewer('/autohome/dominik/nmreval/testdata/L8_313K_17O_GG_KG_2020-12-02_1535.h5') - - w.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/io/save_fitparameter.py b/nmreval/gui_qt/io/save_fitparameter.py index 4c7b63a..44769dc 100644 --- a/nmreval/gui_qt/io/save_fitparameter.py +++ b/nmreval/gui_qt/io/save_fitparameter.py @@ -63,16 +63,3 @@ class QSaveFit(QtWidgets.QDialog, Ui_fitparameter_save_dialog): def accept(self): super().accept() - - -if __name__ == '__main__': - import sys - - app = QtWidgets.QApplication([]) - - dialog = QSaveFit() - dialog.set_parameter({'fit1': ['p1', 'p2'], 'fit2': ['p2', 'p3']}) - - dialog.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/lib/color_dialog.py b/nmreval/gui_qt/lib/color_dialog.py index 0c51f64..c85e334 100644 --- a/nmreval/gui_qt/lib/color_dialog.py +++ b/nmreval/gui_qt/lib/color_dialog.py @@ -1,7 +1,7 @@ -from nmreval.configs import config_paths -from nmreval.gui_qt.Qt import QtWidgets, QtCore, QtGui -from nmreval.gui_qt._py.color_palette import Ui_Dialog -from nmreval.lib.colors import Colors, get_palettes +from ...configs import config_paths +from ..Qt import QtWidgets, QtCore, QtGui +from .._py.color_palette import Ui_Dialog +from ...lib.colors import Colors, get_palettes class PaletteDialog(QtWidgets.QDialog, Ui_Dialog): @@ -78,12 +78,3 @@ class PaletteDialog(QtWidgets.QDialog, Ui_Dialog): if idx != -1: self.palette_combobox.setCurrentIndex(idx) self.set_palette(clear=True) - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication([]) - d = PaletteDialog() - d.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/lib/gol.py b/nmreval/gui_qt/lib/gol.py index 4212e71..603d56a 100644 --- a/nmreval/gui_qt/lib/gol.py +++ b/nmreval/gui_qt/lib/gol.py @@ -381,10 +381,3 @@ class QSliderText(QtWidgets.QWidget): def setValue(self, value: int): self.slider.setValue(value) self.value.setText(f'{value} %') - - -if __name__ == "__main__": - application = QtWidgets.QApplication(sys.argv) - qGameOfLife = QGameOfLife() - qGameOfLife.show() - sys.exit(application.exec()) diff --git a/nmreval/gui_qt/lib/randpok.py b/nmreval/gui_qt/lib/randpok.py index 55de7de..1cbfcf8 100644 --- a/nmreval/gui_qt/lib/randpok.py +++ b/nmreval/gui_qt/lib/randpok.py @@ -1,4 +1,3 @@ -import sys import os.path import json import urllib.request @@ -109,11 +108,3 @@ class QPokemon(QtWidgets.QDialog, Ui_Dialog): new_number = len(self._js) self._id = new_number self.show_pokemon(f'{new_number:03d}') - - -if __name__ == '__main__': - app = QtWidgets.QApplication(sys.argv) - w = QPokemon(number=807) - w.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/lib/stuff.py b/nmreval/gui_qt/lib/stuff.py index 59a1207..3c2440c 100644 --- a/nmreval/gui_qt/lib/stuff.py +++ b/nmreval/gui_qt/lib/stuff.py @@ -1,8 +1,8 @@ import random -import sys + import numpy as np -from nmreval.gui_qt.Qt import QtWidgets, QtCore, QtGui +from ..Qt import QtWidgets, QtCore, QtGui __all__ = ['Game'] @@ -493,10 +493,3 @@ class MirrorL(Tetromino): SHAPE = np.array([[1, 0, 0, 0], [-1, -1, 0, 1]]) color = 'lightGray' - - -if __name__ == '__main__': - app = QtWidgets.QApplication([]) - tetris = Game('snake') - tetris.show() - sys.exit(app.exec_()) diff --git a/nmreval/gui_qt/lib/usermodeleditor.py b/nmreval/gui_qt/lib/usermodeleditor.py index ab02c45..7fe0742 100644 --- a/nmreval/gui_qt/lib/usermodeleditor.py +++ b/nmreval/gui_qt/lib/usermodeleditor.py @@ -130,14 +130,3 @@ class QUsermodelEditor(QtWidgets.QMainWindow): evt.ignore() else: super().closeEvent(evt) - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication([]) - - win = QUsermodelEditor('/autohome/dominik/.nmreval/myfitmodels.py') - win.show() - - sys.exit(app.exec()) - diff --git a/nmreval/gui_qt/main/management.py b/nmreval/gui_qt/main/management.py index 2aee980..9fc83d7 100644 --- a/nmreval/gui_qt/main/management.py +++ b/nmreval/gui_qt/main/management.py @@ -289,7 +289,11 @@ class UpperManagement(QtCore.QObject): value_set = set() if src_sets is None: - src_sets = self.graphs[self.current_graph].active + if self.current_graph: + src_sets = self.graphs[self.current_graph].active + else: + return + for sid in src_sets: data_i = self.data[sid] if joined is None: @@ -355,8 +359,9 @@ class UpperManagement(QtCore.QObject): self.undostack.endMacro() def cut(self): - xlim, _ = self.graphs[self.current_graph].ranges - self.apply('cut', xlim) + if self.current_graph: + xlim, _ = self.graphs[self.current_graph].ranges + self.apply('cut', xlim) @QtCore.pyqtSlot() def unmask(self): diff --git a/nmreval/gui_qt/math/evaluation.py b/nmreval/gui_qt/math/evaluation.py index 3031dff..112b5fb 100644 --- a/nmreval/gui_qt/math/evaluation.py +++ b/nmreval/gui_qt/math/evaluation.py @@ -100,21 +100,3 @@ class QEvalDialog(QtWidgets.QDialog, Ui_CalcDialog): else: # keine Ahnung, warum man hier landen sollte ... self.success = False - - -if __name__ == '__main__': - import sys - - app = QtWidgets.QApplication([]) - names = Namespace(basic=True) - names.add_namespace({'g[0].s[0].x': (1,), 'g[0].s[0].y': (4,)}, parents=('Data', 'S0 (G0)')) - names.add_namespace({'g[0].s[1].x': (2,), 'g[0].s[1].y': (5,)}, parents=('Data', 'S1 (G0)')) - names.add_namespace({'g[1].s[2].x': (3,), 'g[1].s[2].y': (6,), - "g[1].s[2].fit['C']": (7,), "g[1].s[2].fit['D_0']": (8,)}, - parents=('Data', 'S0 (G1)')) - - dialog = QEvalDialog(mode='c') - dialog.set_namespace(names) - dialog.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/math/interpol.py b/nmreval/gui_qt/math/interpol.py index ad3957f..c58d03c 100644 --- a/nmreval/gui_qt/math/interpol.py +++ b/nmreval/gui_qt/math/interpol.py @@ -89,21 +89,3 @@ class InterpolDialog(QtWidgets.QDialog, Ui_Dialog): success = self.collect_parameter() if success: super().accept() - - -if __name__ == '__main__': - import sys - - app = QtWidgets.QApplication([]) - from numpy.random import choice - - qw = 'QtCurve' - while qw == 'QtCurve': - qw = choice(QtWidgets.QStyleFactory.keys()) - print(qw) - app.setStyle(QtWidgets.QStyleFactory.create(qw)) - - mplQt = InterpolDialog() - mplQt.show() - - sys.exit(app.exec()) \ No newline at end of file diff --git a/nmreval/gui_qt/math/smooth.py b/nmreval/gui_qt/math/smooth.py index 6d547a1..387865d 100644 --- a/nmreval/gui_qt/math/smooth.py +++ b/nmreval/gui_qt/math/smooth.py @@ -45,13 +45,3 @@ class QSmooth(QtWidgets.QDialog, Ui_SmoothDialog): def close(self): self.disconnect() super().close() - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication([]) - - w = QSmooth() - w.show() - - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/nmr/coupling_calc.py b/nmreval/gui_qt/nmr/coupling_calc.py index 2743efa..ecd0632 100644 --- a/nmreval/gui_qt/nmr/coupling_calc.py +++ b/nmreval/gui_qt/nmr/coupling_calc.py @@ -67,11 +67,3 @@ class QCoupCalcDialog(QtWidgets.QDialog, Ui_coupling_calc_dialog): kw.update(pp.value) self.label.setText('Coupling constant: %.8g' % self.cp[self.comboBox.currentIndex()].relax(*p)) - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication(sys.argv) - w = QCoupCalcDialog() - w.show() - sys.exit(app.exec()) diff --git a/nmreval/gui_qt/nmr/t1_from_tau.py b/nmreval/gui_qt/nmr/t1_from_tau.py index 71fed17..f7f3557 100644 --- a/nmreval/gui_qt/nmr/t1_from_tau.py +++ b/nmreval/gui_qt/nmr/t1_from_tau.py @@ -1,7 +1,7 @@ from typing import List, Tuple from ...nmr.coupling import * -from ...distributions import ColeCole, ColeDavidson, HavriliakNegami, KWW +from ...distributions import ColeCole, ColeDavidson, HavriliakNegami, KWW, LogGaussian from ...utils import pi from ...utils.text import convert @@ -20,7 +20,7 @@ class QRelaxCalc(QtWidgets.QDialog, Ui_Dialog): self.graphs = {} self.specdens = [ColeCole, ColeDavidson, HavriliakNegami, KWW] - self.coupling = [Quadrupolar, Czjzek, HomoDipolar] + self.coupling = [Quadrupolar, HomoDipolar, Czjzek] self.tau_parameter = [] for line_edit in [self.ea_lineEdit, self.tau0_lineEdit, self.start_lineEdit, self.stop_lineEdit, @@ -199,13 +199,3 @@ class QRelaxCalc(QtWidgets.QDialog, Ui_Dialog): def accept(self): self.calc_relaxation() super().accept() - - -if __name__ == '__main__': - import sys - app = QtWidgets.QApplication(sys.argv) - - w = QRelaxCalc() - w.show() - - sys.exit(app.exec()) diff --git a/nmreval/io/fcbatchreader.py b/nmreval/io/fcbatchreader.py index 8252821..6e0c1ee 100644 --- a/nmreval/io/fcbatchreader.py +++ b/nmreval/io/fcbatchreader.py @@ -386,14 +386,3 @@ class FCReader: @staticmethod def kww(x, m0, off, t1, beta): return m0 * np.exp(-(x/t1)**beta) + off - - -if __name__ == '__main__': - test = ['/autohome/dominik/nmreval/testdata/fc_test/abc298K.h5', - '/autohome/dominik/nmreval/testdata/fc_test/abc.h5'] - - fc_reader = FCReader(test) - fc_reader.load_magnetization(region=(90e-6, 120e-6), overwrite=True) - fc_reader.fit(save_fits=True, save_fig=True) - fc_reader.get_parameter(path='/autohome/dominik/nmreval/testdata/fc_test', kind='temp', write=True, plot=True) - fc_reader.get_parameter(path='/autohome/dominik/nmreval/testdata/fc_test', kind='freq', write=True, plot=True) diff --git a/nmreval/lib/logger.py b/nmreval/lib/logger.py index 4e101ea..e920f8b 100644 --- a/nmreval/lib/logger.py +++ b/nmreval/lib/logger.py @@ -1,7 +1,7 @@ import sys import logging.handlers -from nmreval.configs import config_paths +from ..configs import config_paths ERROR_LOG = config_paths() / 'errors.log' # initialize logger stuff diff --git a/nmreval/math/mittagleffler.py b/nmreval/math/mittagleffler.py index 1964045..874382d 100644 --- a/nmreval/math/mittagleffler.py +++ b/nmreval/math/mittagleffler.py @@ -256,11 +256,3 @@ def optimum_unbounded_region(phi_s_j, pj, log_epsilon): h_j = 0 return mu_j, h_j, n_j - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - xvalue = np.geomspace(1e-3, 100, num=20) # np.array([1+1j]) - # plt.semilogx(xvalue, mlf(-xvalue, a=0.8, b=0.3, flag=False)) - plt.semilogx(xvalue, mlf(-xvalue, a=0.8, b=0.3)) - plt.show() diff --git a/nmreval/math/orientations.py b/nmreval/math/orientations.py index 4a67b04..8390bec 100755 --- a/nmreval/math/orientations.py +++ b/nmreval/math/orientations.py @@ -139,35 +139,3 @@ def xyz_to_spherical(x, y, z): ph = np.arctan2(y, x) return r, th, ph - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - from mpl_toolkits.mplot3d import Axes3D - - if True: - fig2, (ax2, ax3, ax4) = plt.subplots(3, 1, sharex=True) - for i in [alderman]: # sophe, grid_planar, grid_spherical, random_planar, random_spherical, zcw_planar, zcw_spherical - fig = plt.figure(str(i)) - ax = fig.add_subplot(211, projection='3d') - - ax5 = fig.add_subplot(212) - - a, b, wt = i(150) - x, y, z = spherical_to_xyz(a, b) - ax.scatter(xs=x, ys=y, zs=z) - ax2.plot(np.linspace(0, 1, num=len(a)), a) - ax3.plot(np.linspace(0, 1, num=len(a)), b) - ax4.plot(np.linspace(0, 1, num=len(a)), wt) - - ax5.plot(a*180/pi, b*180/pi, 'o') - - ax5.set_xticks([0., 90, 180, 270, 360]) - ax5.set_xticklabels(['0', '90', '180', '270', '360']) - ax5.set_yticks([0., 90, 180]) - ax5.set_yticklabels(['0', '90', '180']) - - ax5.set_xlim([0, 360]) - ax5.set_ylim([0, 180]) - - plt.show() diff --git a/nmreval/math/wideline.py b/nmreval/math/wideline.py index de8ec95..f996392 100644 --- a/nmreval/math/wideline.py +++ b/nmreval/math/wideline.py @@ -355,29 +355,3 @@ def sec_order(p, x, spin=2.5): ret_val = s return ret_val / trapz(ret_val, x) - - -if __name__ == '__main__': - # pass - import matplotlib.pyplot as plt - - fig, ax = plt.subplots() - - dw0 = 4e-6 - xxx = np.arange(0, 8192) * dw0 - - freq = np.fft.fftshift(np.fft.fftfreq(len(xxx), d=dw0))[500:-1000] - - p0 = [6.66e6, 0.935, 2e3, 50e6, 1/dw0] - spec = sec_order(p0, freq) - ax.plot(freq, spec) - - p1 = [20e3, 0.2, 2e3, 1/dw0] - spec1 = pake(p1, freq) - ax.plot(freq, spec1) - - p2 = [20e3, 0.2, 20e3, 2e3, 1/dw0] - spec2 = csa(p2, freq) - ax.plot(freq, spec2) - - plt.show() diff --git a/nmreval/models/fieldcycling.py b/nmreval/models/fieldcycling.py index 550ea01..ed59cf7 100644 --- a/nmreval/models/fieldcycling.py +++ b/nmreval/models/fieldcycling.py @@ -112,13 +112,3 @@ class KWWDipolar(_AbstractFCDipolar): params = _AbstractFCDipolar.params + [r'\beta'] bounds = _AbstractFCDipolar.bounds + [(0, 1)] relax = Relaxation(distribution=KWW) - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - - w = np.logspace(-3, 3, num=31) - - plt.loglog(w, FFHSFC.func(w, 10, 1, xaxis='omega'), '-') - - plt.show() \ No newline at end of file diff --git a/nmreval/models/gengamma.py b/nmreval/models/gengamma.py index a21eef9..0d332ef 100644 --- a/nmreval/models/gengamma.py +++ b/nmreval/models/gengamma.py @@ -1,4 +1,3 @@ - import numpy as np from scipy.special import gammaln from ..math.logfourier import logft @@ -267,32 +266,3 @@ def g1(p, x): fkt2 = glnbeta_td(xval, p[5], p[6], p[7]) ret_val[i] = p[0] * (fkt1 * ((1 - p[4]) + p[4] * fkt2)) + np.abs(p[8]) * np.exp(-(xval / p[9]) ** p[10]) return ret_val - - -if __name__ == '__main__': - import matplotlib.pyplot as plt - import time - - x = np.logspace(-5, 5, num=260) - tau0 = 100 - alpha = 2 - beta = 0.7 - gamma = 0.1 - sigma = 1000 - tau1 = 1 - a = 0.8 - b = 0.6 - r = 0 - start = time.time() - y = GeneralGamma.ggaew_b(x, tau0, alpha, beta, sigma, gamma, tau1, a, b, r) - print('gg_time', time.time()-start) - start = time.time() - yy = g2([r, tau0, alpha, beta, sigma, gamma, tau1, a, b], x) - print('g2', time.time()-start) - - plt.semilogx(x, y) - plt.semilogx(x, yy, 'x') - plt.show() - - - diff --git a/nmreval/nmr/relaxation.py b/nmreval/nmr/relaxation.py index 8580997..042c9d9 100755 --- a/nmreval/nmr/relaxation.py +++ b/nmreval/nmr/relaxation.py @@ -14,8 +14,8 @@ import numpy as np from scipy.interpolate import interp1d, Akima1DInterpolator from scipy.optimize import minimize -from nmreval.lib.utils import ArrayLike from .coupling import Coupling +from ..lib.utils import ArrayLike from ..distributions.base import Distribution from ..distributions.debye import Debye as Debye from ..utils import gamma_full @@ -29,7 +29,7 @@ class Relaxation: def __init__(self, distribution: Type[Distribution] = None): self.distribution = distribution self.dist_parameter = () - self._dist_kw = {} + self.dist_kw = {} self.coupling = None self.coup_parameter = [] @@ -67,9 +67,13 @@ class Relaxation: if parameter is not None: self.dist_parameter = parameter + else: + self.dist_parameter = () if keywords is not None: - self._dist_kw = keywords + self.dist_kw = keywords + else: + self.dist_kw = {} def t1(self, omega: ArrayLike, tau: ArrayLike, *specdens_args: Any, mode: str = 'bpp', **kwargs) -> np.ndarray | float: