From 45abe4c5605ddf2a3218ac24db9670c865ffc6d2 Mon Sep 17 00:00:00 2001 From: Stuart Prescott Date: Fri, 20 Dec 2024 17:57:06 +1100 Subject: [PATCH] Fix SyntaxWarning from tex/re strings --- src/sas/qtgui/Calculators/DensityPanel.py | 2 +- src/sas/qtgui/Calculators/KiessigPanel.py | 2 +- .../Calculators/ResolutionCalculatorPanel.py | 16 ++++++++-------- src/sas/qtgui/Calculators/SldPanel.py | 2 +- src/sas/qtgui/MainWindow/DataManager.py | 4 ++-- .../Perspectives/Corfunc/ExtractionCanvas.py | 2 +- src/sas/qtgui/Perspectives/Corfunc/IDFCanvas.py | 2 +- .../qtgui/Perspectives/Corfunc/QSpaceCanvas.py | 2 +- .../Perspectives/Corfunc/RealSpaceCanvas.py | 6 +++--- .../Perspectives/Fitting/FittingUtilities.py | 2 +- .../qtgui/Perspectives/Fitting/FittingWidget.py | 4 ++-- .../Perspectives/Inversion/InversionLogic.py | 2 +- .../ParticleEditor/syntax_highlight.py | 8 ++++---- src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py | 6 +++--- src/sas/qtgui/Plotting/Slicers/WedgeSlicer.py | 6 +++--- src/sas/qtgui/Utilities/PythonSyntax.py | 10 +++++----- .../qtgui/Utilities/UnitTesting/GuiUtilsTest.py | 8 ++++---- src/sas/sascalc/calculator/geni.py | 4 ++-- src/sas/sascalc/invariant/invariant.py | 2 +- 19 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/sas/qtgui/Calculators/DensityPanel.py b/src/sas/qtgui/Calculators/DensityPanel.py index 04622e02b3..608ed840b7 100644 --- a/src/sas/qtgui/Calculators/DensityPanel.py +++ b/src/sas/qtgui/Calculators/DensityPanel.py @@ -56,7 +56,7 @@ def setupUi(self): self.setFixedSize(self.minimumSizeHint()) - rx = QtCore.QRegularExpression("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") + rx = QtCore.QRegularExpression(r"[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") self.ui.editMolarVolume.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editMolarVolume)) self.ui.editMassDensity.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editMassDensity)) diff --git a/src/sas/qtgui/Calculators/KiessigPanel.py b/src/sas/qtgui/Calculators/KiessigPanel.py index fe00be1205..a9013498ef 100644 --- a/src/sas/qtgui/Calculators/KiessigPanel.py +++ b/src/sas/qtgui/Calculators/KiessigPanel.py @@ -19,7 +19,7 @@ def __init__(self, parent=None): self.manager = parent self.thickness = KiessigThicknessCalculator() - rx = QtCore.QRegularExpression("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") + rx = QtCore.QRegularExpression(r"[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") self.deltaq_in.setValidator(QtGui.QRegularExpressionValidator(rx, self.deltaq_in)) # signals diff --git a/src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py b/src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py index 89eacafd30..5df24ba9fd 100644 --- a/src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py +++ b/src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py @@ -128,7 +128,7 @@ def checkWavelength(self): text_edit.setStyleSheet(BG_WHITE) input_string = str(text_edit.text()) if self.cbWaveColor.currentText() != 'TOF': - input_wavelength = re.match('\d+\.?\d*', input_string) + input_wavelength = re.match(r'\d+\.?\d*', input_string) if input_wavelength is None: text_edit.setStyleSheet(BG_RED) self.cmdCompute.setEnabled(False) @@ -137,7 +137,7 @@ def checkWavelength(self): text_edit.setStyleSheet(BG_WHITE) self.cmdCompute.setEnabled(True) else: - interval_wavelength = re.match('^\d+\.?\d*\s*-\s*\d+\.?\d*$', + interval_wavelength = re.match(r'^\d+\.?\d*\s*-\s*\d+\.?\d*$', input_string) if interval_wavelength is None: @@ -148,7 +148,7 @@ def checkWavelength(self): else: # check on min < max [wavelength_min, wavelength_max] = \ - re.findall('\d+\.?\d*', interval_wavelength.group()) + re.findall(r'\d+\.?\d*', interval_wavelength.group()) if float(wavelength_min) >= float(wavelength_max): text_edit.setStyleSheet(BG_RED) @@ -167,7 +167,7 @@ def checkWavelengthSpread(self): if text_edit.isModified(): text_edit.setStyleSheet(BG_WHITE) if self.cbWaveColor.currentText() != 'TOF': - pattern = '^\d+\.?\d*(|;\s*\d+)$' + pattern = r'^\d+\.?\d*(|;\s*\d+)$' input_string = str(text_edit.text()) wavelength_spread_input = re.match(pattern, input_string) @@ -183,7 +183,7 @@ def checkWavelengthSpread(self): text_edit.setStyleSheet(BG_WHITE) self.cmdCompute.setEnabled(True) else: - pattern = '^\d+\.?\d*\s*-\s*\d+\.?\d*(|;\s*\d+)$' + pattern = r'^\d+\.?\d*\s*-\s*\d+\.?\d*(|;\s*\d+)$' input_string = str(text_edit.text()) wavelength_spread_input = re.match(pattern, input_string) @@ -208,7 +208,7 @@ def checkPixels(self): if text_edit.isModified(): text_edit.setStyleSheet(BG_WHITE) - pattern = '^\d+\.?\d*,\s*\d+\.?\d*$' + pattern = r'^\d+\.?\d*,\s*\d+\.?\d*$' input_string = str(text_edit.text()) pixels_input = re.match(pattern, input_string) @@ -226,7 +226,7 @@ def checkQx_y(self): """ Validator for qx and qy inputs """ Q_modified = [self.txtQx.isModified(), self.txtQy.isModified()] if any(Q_modified): - pattern = '^-?\d+\.?\d*(,\s*-?\d+\.?\d*)*$' + pattern = r'^-?\d+\.?\d*(,\s*-?\d+\.?\d*)*$' text_edit = self.txtQx if Q_modified[0] else self.txtQy input_string = str(text_edit.text()) q_input = re.match(pattern, input_string) @@ -265,7 +265,7 @@ def checkAperture(self): if text_edit.isModified(): text_edit.setStyleSheet(BG_WHITE) input_string = str(text_edit.text()) - pattern = '^\d+\.?\d*(|,\s*\d+)$' + pattern = r'^\d+\.?\d*(|,\s*\d+)$' aperture_input = re.match(pattern, input_string) if aperture_input is None: diff --git a/src/sas/qtgui/Calculators/SldPanel.py b/src/sas/qtgui/Calculators/SldPanel.py index 5ddf6ad931..e1de5f430a 100644 --- a/src/sas/qtgui/Calculators/SldPanel.py +++ b/src/sas/qtgui/Calculators/SldPanel.py @@ -119,7 +119,7 @@ def setupUi(self): # Chemical formula is checked via periodictable.formula module. self.ui.editMolecularFormula.setValidator(GuiUtils.FormulaValidator(self.ui.editMolecularFormula)) - rx = QtCore.QRegularExpression("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") + rx = QtCore.QRegularExpression(r"[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") self.ui.editMassDensity.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editMassDensity)) self.ui.editNeutronWavelength.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editNeutronWavelength)) self.ui.editXrayWavelength.setValidator(QtGui.QRegularExpressionValidator(rx, self.ui.editXrayWavelength)) diff --git a/src/sas/qtgui/MainWindow/DataManager.py b/src/sas/qtgui/MainWindow/DataManager.py index 94753ddcaf..a6a8a10ae8 100755 --- a/src/sas/qtgui/MainWindow/DataManager.py +++ b/src/sas/qtgui/MainWindow/DataManager.py @@ -145,7 +145,7 @@ def rename(self, name): return "" # Explicitly match [0-9]+ at the end of the name - result = re.split("\[[0-9]+\]$", name) + result = re.split(r"\[[0-9]+\]$", name) base_name = result[0].strip() # data_name_dict: {'baseName': [0, 1, .. n]} @@ -278,7 +278,7 @@ def remove_item_from_data_name_dict(self, name): Remove 'name' or 'name [n]' from data_name_dict """ # Split on whitespace - split 'name [n]' into list of len() == 2 - data_name_split = re.split("\[[0-9]+\]$", name) + data_name_split = re.split(r"\[[0-9]+\]$", name) base_name = data_name_split[0].strip() if name in self.data_name_dict: self.data_name_dict[name].remove(0) diff --git a/src/sas/qtgui/Perspectives/Corfunc/ExtractionCanvas.py b/src/sas/qtgui/Perspectives/Corfunc/ExtractionCanvas.py index 3e16465161..6028727632 100644 --- a/src/sas/qtgui/Perspectives/Corfunc/ExtractionCanvas.py +++ b/src/sas/qtgui/Perspectives/Corfunc/ExtractionCanvas.py @@ -34,7 +34,7 @@ def draw_data(self): self.axes = self.fig.add_subplot(111) self.axes.set_xscale("linear") self.axes.set_yscale("linear") - self.axes.set_xlabel("Z [$\AA$]") + self.axes.set_xlabel(r"Z [$\AA$]") self.axes.set_ylabel("Correlation") self.axes.set_title("Real Space Correlations") self.fig.tight_layout() diff --git a/src/sas/qtgui/Perspectives/Corfunc/IDFCanvas.py b/src/sas/qtgui/Perspectives/Corfunc/IDFCanvas.py index c5e99c619f..9d816b2c83 100644 --- a/src/sas/qtgui/Perspectives/Corfunc/IDFCanvas.py +++ b/src/sas/qtgui/Perspectives/Corfunc/IDFCanvas.py @@ -19,7 +19,7 @@ def draw_data(self): self.axes = self.fig.add_subplot(111) self.axes.set_xscale("linear") self.axes.set_yscale("linear") - self.axes.set_xlabel("Z [$\AA$]") + self.axes.set_xlabel(r"Z [$\AA$]") self.axes.set_ylabel("IDF") self.axes.set_title("Interface Distribution Function") self.fig.tight_layout() diff --git a/src/sas/qtgui/Perspectives/Corfunc/QSpaceCanvas.py b/src/sas/qtgui/Perspectives/Corfunc/QSpaceCanvas.py index afdb371a87..ea7828d779 100644 --- a/src/sas/qtgui/Perspectives/Corfunc/QSpaceCanvas.py +++ b/src/sas/qtgui/Perspectives/Corfunc/QSpaceCanvas.py @@ -73,7 +73,7 @@ def draw_data(self): self.axes = self.fig.add_subplot(111) self.axes.set_xscale("log") self.axes.set_yscale("log") - self.axes.set_xlabel("Q [$\AA^{-1}$]") + self.axes.set_xlabel(r"Q [$\AA^{-1}$]") self.axes.set_ylabel("I(Q) [cm$^{-1}$]") self.axes.set_title("Scattering data") self.fig.tight_layout() diff --git a/src/sas/qtgui/Perspectives/Corfunc/RealSpaceCanvas.py b/src/sas/qtgui/Perspectives/Corfunc/RealSpaceCanvas.py index 52fa4f7b1e..638c3d1af3 100644 --- a/src/sas/qtgui/Perspectives/Corfunc/RealSpaceCanvas.py +++ b/src/sas/qtgui/Perspectives/Corfunc/RealSpaceCanvas.py @@ -25,15 +25,15 @@ def draw_data(self): self.axes = self.fig.add_subplot(111) self.axes.set_xscale("linear") self.axes.set_yscale("linear") - self.axes.set_xlabel("Z [$\AA$]") + self.axes.set_xlabel(r"Z [$\AA$]") self.axes.set_ylabel("Correlation") self.axes.set_title("Real Space Correlations") self.fig.tight_layout() if self.data is not None and len(self.data) == 2: data1, data3 = self.data[0], self.data[1] - self.axes.plot(data1.x, data1.y, label="$\Gamma_1(z)$") - self.axes.plot(data3.x, data3.y, label="$\Gamma_3(z)$") + self.axes.plot(data1.x, data1.y, label=r"$\Gamma_1(z)$") + self.axes.plot(data3.x, data3.y, label=r"$\Gamma_3(z)$") self.axes.set_xlim(0, max(data1.x) / 4) self.legend = self.axes.legend() diff --git a/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py b/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py index fcee175c81..9516938716 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py +++ b/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py @@ -638,7 +638,7 @@ def plotPolydispersities(model): xunit = model.details[name][0] data1d.xtransform = 'x' data1d.ytransform = 'y' - data1d.xaxis(r'\rm{{{}}}'.format(name.replace('_', '\_')), xunit) + data1d.xaxis(r'\rm{{{}}}'.format(name.replace('_', r'\_')), xunit) data1d.yaxis(r'\rm{probability}', 'normalized') data1d.scale = 'linear' data1d.symbol = 'Line' diff --git a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py index a18088347e..0f9ac91ef0 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py +++ b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py @@ -3905,9 +3905,9 @@ def onShowSLDProfile(self): profile_data.symbol = 'Line' profile_data.hide_error = True profile_data._xaxis = "R" - profile_data._xunit = "\AA" + profile_data._xunit = r"\AA" profile_data._yaxis = "SLD" - profile_data._yunit = "10^{-6}\AA^{-2}" + profile_data._yunit = r"10^{-6}\AA^{-2}" profile_data.ytransform='y' profile_data.xtransform='x' diff --git a/src/sas/qtgui/Perspectives/Inversion/InversionLogic.py b/src/sas/qtgui/Perspectives/Inversion/InversionLogic.py index 6640feacdc..d18d9cd206 100644 --- a/src/sas/qtgui/Perspectives/Inversion/InversionLogic.py +++ b/src/sas/qtgui/Perspectives/Inversion/InversionLogic.py @@ -136,7 +136,7 @@ def newPRPlot(self, out, pr, cov=None): return new_plot def add_errors(self, sigma=0.05): - """ + r""" Adds errors to data set is they are not available. Uses $\Delta y = \sigma | y |$. """ diff --git a/src/sas/qtgui/Perspectives/ParticleEditor/syntax_highlight.py b/src/sas/qtgui/Perspectives/ParticleEditor/syntax_highlight.py index 84e15f3b46..361b9a1fc2 100644 --- a/src/sas/qtgui/Perspectives/ParticleEditor/syntax_highlight.py +++ b/src/sas/qtgui/Perspectives/ParticleEditor/syntax_highlight.py @@ -73,16 +73,16 @@ class PythonHighlighter(QSyntaxHighlighter): # Comparison '==', '!=', '<', '<=', '>', '>=', # Arithmetic - '\+', '-', '\*', '/', '//', '\%', '\*\*', + r'\+', '-', r'\*', '/', '//', r'\%', r'\*\*', # In-place - '\+=', '-=', '\*=', '/=', '\%=', + r'\+=', '-=', r'\*=', '/=', r'\%=', # Bitwise - '\^', '\|', '\&', '\~', '>>', '<<', + r'\^', r'\|', r'\&', r'\~', '>>', '<<', ] # Python braces braces = [ - '\{', '\}', '\(', '\)', '\[', '\]', + r'\{', r'\}', r'\(', r'\)', r'\[', r'\]', ] def __init__(self, document): diff --git a/src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py b/src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py index 6e2c1f07b0..8a3007ccab 100644 --- a/src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py +++ b/src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py @@ -131,12 +131,12 @@ def _post_data(self, nbins=None): new_plot.interactive = True new_plot.detector = self.data.detector # If the data file does not tell us what the axes are, just assume... - new_plot.xaxis("\\rm{\phi}", 'degrees') - new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") + new_plot.xaxis(r"\rm{\phi}", 'degrees') + new_plot.yaxis(r"\rm{Intensity} ", "cm^{-1}") if hasattr(data, "scale") and data.scale == 'linear' and \ self.data.name.count("Residuals") > 0: new_plot.ytransform = 'y' - new_plot.yaxis("\\rm{Residuals} ", "/") + new_plot.yaxis(r"\rm{Residuals} ", "/") new_plot.id = "AnnulusPhi" + self.data.name new_plot.type_id = "Slicer" + self.data.name # Used to remove plots after changing slicer so they don't keep showing up after closed diff --git a/src/sas/qtgui/Plotting/Slicers/WedgeSlicer.py b/src/sas/qtgui/Plotting/Slicers/WedgeSlicer.py index 6f75c6f850..d4abde4240 100644 --- a/src/sas/qtgui/Plotting/Slicers/WedgeSlicer.py +++ b/src/sas/qtgui/Plotting/Slicers/WedgeSlicer.py @@ -204,12 +204,12 @@ def _post_data(self, new_sector=None, nbins=None): if self.averager.__name__ == 'SectorPhi': # angular plots usually require a linear x scale and better with # a linear y scale as well. - new_plot.xaxis("\\rm{\phi}", "degrees") + new_plot.xaxis(r"\rm{\phi}", "degrees") new_plot.xtransform = 'x' new_plot.ytransform = 'y' else: - new_plot.xaxis("\\rm{Q}", 'A^{-1}') - new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") + new_plot.xaxis(r"\rm{Q}", 'A^{-1}') + new_plot.yaxis(r"\rm{Intensity} ", "cm^{-1}") new_plot.id = str(self.averager.__name__) + self.data.name new_plot.type_id = "Slicer" + self.data.name # Used to remove plots after changing slicer so they don't keep showing up after closed diff --git a/src/sas/qtgui/Utilities/PythonSyntax.py b/src/sas/qtgui/Utilities/PythonSyntax.py index b863d4d993..4bdd1cb3f7 100644 --- a/src/sas/qtgui/Utilities/PythonSyntax.py +++ b/src/sas/qtgui/Utilities/PythonSyntax.py @@ -62,16 +62,16 @@ class PythonHighlighter (QSyntaxHighlighter): # Comparison '==', '!=', '<', '<=', '>', '>=', # Arithmetic - '\+', '-', '\*', '/', '//', '\%', '\*\*', + r'\+', '-', r'\*', '/', '//', r'\%', r'\*\*', # In-place - '\+=', '-=', '\*=', '/=', '\%=', + r'\+=', '-=', r'\*=', '/=', r'\%=', # Bitwise - '\^', '\|', '\&', '\~', '>>', '<<', + r'\^', r'\|', r'\&', r'\~', '>>', '<<', ] # Python braces braces = [ - '\{', '\}', '\(', '\)', '\[', '\]', + r'\{', r'\}', r'\(', r'\)', r'\[', r'\]', ] def __init__(self, document, is_python=True): QSyntaxHighlighter.__init__(self, document) @@ -209,4 +209,4 @@ def match_multiline(self, text, delimiter, in_state, style): infile = open('PythonSyntax.py', 'r') editor.setPlainText(infile.read()) - app.exec_() \ No newline at end of file + app.exec_() diff --git a/src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py b/src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py index ca649cb915..53b4b51b14 100644 --- a/src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py +++ b/src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py @@ -515,11 +515,11 @@ def testrstToHtml(self): s = ".. |Ang| unicode:: U+212B" assert rstToHtml(s) == ('Ang', 'Å') - s = ".. |Ang^-1| replace:: |Ang|\ :sup:`-1`" + s = r".. |Ang^-1| replace:: |Ang|\ :sup:`-1`" assert rstToHtml(s) == ('Ang^-1', 'Å-1') - s = ".. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2`" + s = r".. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2`" assert rstToHtml(s) == ('1e-6Ang^-2', '10-6 Å-2') - s = ".. |cm^-1| replace:: cm\ :sup:`-1`" + s = r".. |cm^-1| replace:: cm\ :sup:`-1`" assert rstToHtml(s) == ('cm^-1', 'cm-1') s = ".. |deg| unicode:: U+00B0" assert rstToHtml(s) == ('deg', '°') @@ -532,7 +532,7 @@ def testrstToHtml(self): def testConvertUnitToHTML(self): ''' test unit string replacement''' s = None - assert convertUnitToHTML(s) is "" + assert convertUnitToHTML(s) == "" s = "" assert convertUnitToHTML(s) == s diff --git a/src/sas/sascalc/calculator/geni.py b/src/sas/sascalc/calculator/geni.py index b1b9e15d21..3cdb43bce7 100644 --- a/src/sas/sascalc/calculator/geni.py +++ b/src/sas/sascalc/calculator/geni.py @@ -148,7 +148,7 @@ def _calc_Iqxy(scale, x, y, qx, qy): Iq = [abs(np.sum(scale*np.exp(1j*(qx_k*x + qy_k*y))))**2 for qx_k, qy_k in zip(qx.flat, qy.flat)] return np.asarray(Iq).reshape(qx.shape) -_calc_Iqxy.__doc__ = """ +_calc_Iqxy.__doc__ = r""" Compute I(q) for a set of points (x, y). Uses: I(q) = \|sum V(r) rho(r) e^(1j q.r)\|^2 / sum V(r) @@ -176,7 +176,7 @@ def _calc_Iqxy_elements(sld, x, y, z, elements, vol, qx, qy): def _calc_Iqxy_magnetic( qx, qy, x, y, rho, vol, rho_m, up_frac_i=1, up_frac_f=1, up_theta=0., up_phi=0.): - """Compute I(q) for a set of points (x, y), with magnetism on each point. + r"""Compute I(q) for a set of points (x, y), with magnetism on each point. Uses: I(q) = sum_xs w_xs \|sum V(r) rho(q, r, xs) e^(1j q.r)\|^2 / sum V(r) where rho is adjusted for the particular q and polarization cross section. diff --git a/src/sas/sascalc/invariant/invariant.py b/src/sas/sascalc/invariant/invariant.py index e3feecdecb..6c5e7ac65b 100644 --- a/src/sas/sascalc/invariant/invariant.py +++ b/src/sas/sascalc/invariant/invariant.py @@ -204,7 +204,7 @@ def __init__(self, scale=1, power=4): self.dpower = 0.0 def linearize_q_value(self, value): - """ + r""" Transform the input q-value for linearization :param value: q-value