From cadcc2d523702b449dc653ab09b0292d036119c6 Mon Sep 17 00:00:00 2001 From: PhD Date: Thu, 9 Jul 2026 11:17:59 -0700 Subject: [PATCH] ci: replace ruff with docformatter and updates pre-commit hook versions --- .pre-commit-config.yaml | 26 ++++----- docs/examples/multimodel-known-dG1.py | 39 +++++++------- docs/examples/multimodel-known-dG2.py | 41 +++++++------- docs/examples/multimodel-unknown-dG1.py | 37 ++++++------- docs/examples/multimodel-unknown-dG2.py | 53 ++++++++++--------- docs/examples/query-results.py | 4 +- news/precommit-hook-update.rst | 23 ++++++++ pyproject.toml | 9 ++-- src/diffpy/srmise/__init__.py | 3 +- src/diffpy/srmise/applications/extract.py | 2 +- src/diffpy/srmise/applications/plot.py | 4 +- src/diffpy/srmise/basefunction.py | 3 +- src/diffpy/srmise/baselines/base.py | 3 +- src/diffpy/srmise/baselines/polynomial.py | 3 +- src/diffpy/srmise/dataclusters.py | 14 ++--- src/diffpy/srmise/modelcluster.py | 8 +-- src/diffpy/srmise/modelevaluators/base.py | 6 --- src/diffpy/srmise/multimodelselection.py | 8 ++- src/diffpy/srmise/pdfdataset.py | 29 +++++----- src/diffpy/srmise/pdfpeakextraction.py | 16 +++--- src/diffpy/srmise/peakextraction.py | 8 +-- src/diffpy/srmise/peaks/base.py | 6 +-- src/diffpy/srmise/peaks/gaussian.py | 3 +- src/diffpy/srmise/peaks/gaussianoverr.py | 3 +- src/diffpy/srmise/peaks/terminationripples.py | 11 ++-- src/diffpy/srmise/peakstability.py | 4 +- src/diffpy/srmise/srmiseerrors.py | 2 + src/diffpy/srmise/srmiselog.py | 2 - tests/test_version.py | 3 +- 29 files changed, 192 insertions(+), 181 deletions(-) create mode 100644 news/precommit-hook-update.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7df7325..37b5a36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ ci: submodules: false repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: check-yaml - id: end-of-file-fixer @@ -21,45 +21,45 @@ repos: - id: check-toml - id: check-added-large-files - repo: https://github.com/psf/black - rev: 24.4.2 + rev: 26.3.1 hooks: - id: black - repo: https://github.com/pycqa/flake8 - rev: 7.0.0 + rev: 7.3.0 hooks: - id: flake8 - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 9.0.0a3 hooks: - id: isort args: ["--profile", "black"] - repo: https://github.com/kynan/nbstripout - rev: 0.7.1 + rev: 0.9.1 hooks: - id: nbstripout - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: no-commit-to-branch name: Prevent Commit to Main Branch args: ["--branch", "main"] stages: [pre-commit] - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.2 hooks: - id: codespell additional_dependencies: - tomli # prettier - multi formatter for .json, .yml, and .md files - repo: https://github.com/pre-commit/mirrors-prettier - rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8 + rev: v4.0.0-alpha.8 hooks: - id: prettier additional_dependencies: - "prettier@^3.2.4" - # ruff - An extremely fast Python linter and code formatter, written in Rust. - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.12 + - repo: https://github.com/PyCQA/docformatter + rev: v1.7.8 hooks: - - id: ruff-check - args: [--fix] + - id: docformatter + additional_dependencies: [tomli] + args: [--in-place, --config, ./pyproject.toml] diff --git a/docs/examples/multimodel-known-dG1.py b/docs/examples/multimodel-known-dG1.py index a8eb04f..bf99928 100644 --- a/docs/examples/multimodel-known-dG1.py +++ b/docs/examples/multimodel-known-dG1.py @@ -13,25 +13,26 @@ """Extract multiple models from crystalline PDF with known uncertainties for use in later AIC-driven multimodeling analysis. -The multimodel approach generates many models of varying complexity by assuming -a range of experimental uncertainties are physically plausible. This example -shows how to generate multiple models from a crystalline silver PDF with -experimentally determined uncertainties. The Akaike Information Criterion (AIC) -will later be used to see which models are relatively more likely to describe -the experimental data. For complex PDFs, especially, there are many sets of -peaks which are physically distinct yet appear to fit the experimental data -similarly well. Multimodeling can help determine which models are worth -investigating first. - -NOTE: The multimodeling API used here is expected to change drastically in a -future version of diffpy.srmise. - -For more information on the multimodeling approach taken here see -[1] Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. - doi:10.1107/S2053273315005276 -The standard reference of AIC-based multimodel selection is -[2] Burnham and Anderson. (2002). Model Selection and Multimodel Inference. - New York, NY: Springer. doi:10.1007/b97636 +The multimodel approach generates many models of varying complexity by +assuming a range of experimental uncertainties are physically plausible. +This example shows how to generate multiple models from a crystalline +silver PDF with experimentally determined uncertainties. The Akaike +Information Criterion (AIC) will later be used to see which models are +relatively more likely to describe the experimental data. For complex +PDFs, especially, there are many sets of peaks which are physically +distinct yet appear to fit the experimental data similarly well. +Multimodeling can help determine which models are worth investigating +first. + +NOTE: The multimodeling API used here is expected to change drastically +in a future version of diffpy.srmise. + +For more information on the multimodeling approach taken here see [1] +Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. +doi:10.1107/S2053273315005276 The standard reference of AIC-based +multimodel selection is [2] Burnham and Anderson. (2002). Model +Selection and Multimodel Inference. New York, NY: Springer. +doi:10.1007/b97636 """ import numpy as np diff --git a/docs/examples/multimodel-known-dG2.py b/docs/examples/multimodel-known-dG2.py index b9c4a7d..c948237 100644 --- a/docs/examples/multimodel-known-dG2.py +++ b/docs/examples/multimodel-known-dG2.py @@ -13,25 +13,26 @@ """AIC-driven multimodel analysis of crystalline PDF with known uncertainties. -The multimodel approach generates many models of varying complexity by assuming -a range of experimental uncertainties are physically plausible. This example -shows how to analyze multiple models obtained (in the previous script) from a -crystalline silver PDF with experimentally determined uncertainties. This -involves calculating the Akaike probabilities, which are a measure of the -likelihood that a given model is the best model (in the sense of -Kullback-Leibler divergence) relative to all the other ones in the same -comparison. - -NOTE: The multimodeling API used here is expected to change drastically in a -future version of diffpy.srmise. - -For more information on the multimodeling approach taken here see -[1] Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. - doi:10.1107/S2053273315005276 -The standard reference of AIC-based multimodel selection is -[2] Burnham and Anderson. (2002). Model Selection and Multimodel Inference. - New York, NY: Springer. doi:10.1007/b97636 +The multimodel approach generates many models of varying complexity by +assuming a range of experimental uncertainties are physically plausible. +This example shows how to analyze multiple models obtained (in the +previous script) from a crystalline silver PDF with experimentally +determined uncertainties. This involves calculating the Akaike +probabilities, which are a measure of the likelihood that a given model +is the best model (in the sense of Kullback-Leibler divergence) relative +to all the other ones in the same comparison. + +NOTE: The multimodeling API used here is expected to change drastically +in a future version of diffpy.srmise. + +For more information on the multimodeling approach taken here see [1] +Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. +doi:10.1107/S2053273315005276 The standard reference of AIC-based +multimodel selection is [2] Burnham and Anderson. (2002). Model +Selection and Multimodel Inference. New York, NY: Springer. +doi:10.1007/b97636 """ + import matplotlib.pyplot as plt import numpy as np @@ -73,7 +74,7 @@ def run(plot=True): # Nyquist sampling minimizes correlations in the PDF, which is the closest # approximation to independence possible for the PDF. dr = np.pi / ms.ppe.qmax - (r, y, dr2, dy) = ms.ppe.resampledata(dr) + r, y, dr2, dy = ms.ppe.resampledata(dr) # Classify models # All models are placed into classes. Models in the same class @@ -133,7 +134,7 @@ def run(plot=True): # "prob" -> The AIC probability given uncertainty dG # These all have dedicated getter functions. For example, the model # index can also be obtained using get_model(dG, corder=i) - (model, cls, nfree, aic, prob) = ms.get(dG, "model", "class", "nfree", "aic", "prob", corder=i) + model, cls, nfree, aic, prob = ms.get(dG, "model", "class", "nfree", "aic", "prob", corder=i) filename_base = "output/known_dG_m" + str(model) diff --git a/docs/examples/multimodel-unknown-dG1.py b/docs/examples/multimodel-unknown-dG1.py index f5411c6..b662291 100644 --- a/docs/examples/multimodel-unknown-dG1.py +++ b/docs/examples/multimodel-unknown-dG1.py @@ -13,24 +13,25 @@ """Extract multiple models from nanoparticle PDF with unknown uncertainties for use in later AIC-driven multimodeling analysis. -The multimodel approach generates many models of varying complexity by assuming -a range of experimental uncertainties are physically plausible. This example -shows how to generate multiple models from a C60 nanoparticle PDF with -unreliable uncertainties. The Akaike Information Criterion (AIC) will later be -used to see which models are relatively more likely to describe the experimental -data. For complex PDFs, especially, there are many sets of peaks which are -physically distinct yet appear to fit the experimental data similarly well. -Multimodeling can help determine which models are worth investigating first. - -NOTE: The multimodeling API used here is expected to change drastically in a -future version of diffpy.srmise. - -For more information on the multimodeling approach taken here see -[1] Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. - doi:10.1107/S2053273315005276 -The standard reference of AIC-based multimodel selection is -[2] Burnham and Anderson. (2002). Model Selection and Multimodel Inference. - New York, NY: Springer. doi:10.1007/b97636 +The multimodel approach generates many models of varying complexity by +assuming a range of experimental uncertainties are physically plausible. +This example shows how to generate multiple models from a C60 +nanoparticle PDF with unreliable uncertainties. The Akaike Information +Criterion (AIC) will later be used to see which models are relatively +more likely to describe the experimental data. For complex PDFs, +especially, there are many sets of peaks which are physically distinct +yet appear to fit the experimental data similarly well. Multimodeling +can help determine which models are worth investigating first. + +NOTE: The multimodeling API used here is expected to change drastically +in a future version of diffpy.srmise. + +For more information on the multimodeling approach taken here see [1] +Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. +doi:10.1107/S2053273315005276 The standard reference of AIC-based +multimodel selection is [2] Burnham and Anderson. (2002). Model +Selection and Multimodel Inference. New York, NY: Springer. +doi:10.1007/b97636 """ import numpy as np diff --git a/docs/examples/multimodel-unknown-dG2.py b/docs/examples/multimodel-unknown-dG2.py index a45ff25..c393833 100644 --- a/docs/examples/multimodel-unknown-dG2.py +++ b/docs/examples/multimodel-unknown-dG2.py @@ -13,31 +13,34 @@ """AIC-driven multimodel analysis of nanoparticle PDF with unknown uncertainties. -The multimodel approach generates many models of varying complexity by assuming -a range of experimental uncertainties are physically plausible. This example -shows how to analyze multiple models obtained from a C60 nanoparticle PDF with -unreliable uncertainties. The Akaike Information Criterion (AIC) can be used to -see which models are relatively more likely to describe the experimental data. -For complex PDFs, especially, there are many sets of peaks which are physically -distinct yet appear to fit the experimental data similarly well. Here we -calculate the Akaike probabilities, which are a measure of the likelihood that a -given model is the best model (in the sense of Kullback-Leibler information +The multimodel approach generates many models of varying complexity by +assuming a range of experimental uncertainties are physically plausible. +This example shows how to analyze multiple models obtained from a C60 +nanoparticle PDF with unreliable uncertainties. The Akaike Information +Criterion (AIC) can be used to see which models are relatively more +likely to describe the experimental data. For complex PDFs, especially, +there are many sets of peaks which are physically distinct yet appear to +fit the experimental data similarly well. Here we calculate the Akaike +probabilities, which are a measure of the likelihood that a given model +is the best model (in the sense of Kullback-Leibler information divergence) relative to all the other ones in the same comparison. This -analysis reflects ignorance of the experimental uncertainties by evaluating -the Akaike probabilities for a range of assumed uncertainties, returning models -which are selected as best at least once. This is a weaker analysis than -possible when the uncertainties are known. - -NOTE: The multimodeling API used here is expected to change drastically in a -future version of diffpy.srmise. - -For more information on the multimodeling approach taken here see -[1] Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. - doi:10.1107/S2053273315005276 -The standard reference of AIC-based multimodel selection is -[2] Burnham and Anderson. (2002). Model Selection and Multimodel Inference. - New York, NY: Springer. doi:10.1007/b97636 +analysis reflects ignorance of the experimental uncertainties by +evaluating the Akaike probabilities for a range of assumed +uncertainties, returning models which are selected as best at least +once. This is a weaker analysis than possible when the uncertainties +are known. + +NOTE: The multimodeling API used here is expected to change drastically +in a future version of diffpy.srmise. + +For more information on the multimodeling approach taken here see [1] +Granlund, et al. (2015) Acta Crystallographica A, 71(4), 392-409. +doi:10.1107/S2053273315005276 The standard reference of AIC-based +multimodel selection is [2] Burnham and Anderson. (2002). Model +Selection and Multimodel Inference. New York, NY: Springer. +doi:10.1007/b97636 """ + import matplotlib.pyplot as plt import numpy as np @@ -88,7 +91,7 @@ def run(plot=True): # Nyquist sampling minimizes correlations in the PDF, which is the closest # approximation to independence possible for the PDF. dr = np.pi / ms.ppe.qmax - (r, y, dr2, dy) = ms.ppe.resampledata(dr) + r, y, dr2, dy = ms.ppe.resampledata(dr) # Classify models # All models are placed into classes. Models in the same class @@ -155,7 +158,7 @@ def run(plot=True): # "aic" -> The AIC for this model given uncertainty dG # "prob" -> The AIC probability given uncertainty dG # These all have dedicated getter functions. - (model, cls, nfree, aic, prob) = ms.get(dG, "model", "class", "nfree", "aic", "prob") + model, cls, nfree, aic, prob = ms.get(dG, "model", "class", "nfree", "aic", "prob") filename_base = "output/unknown_dG_m" + str(model) diff --git a/docs/examples/query-results.py b/docs/examples/query-results.py index b11ddf9..269c9af 100644 --- a/docs/examples/query-results.py +++ b/docs/examples/query-results.py @@ -103,7 +103,7 @@ def run(plot=True): print(" Covariance(width, area) = ", cov.getcovariance((0, 1), (0, 2))) # Baseline parameters. By convention, baseline is final element in cov. - (slope, intercept) = cov.model[-1] + slope, intercept = cov.model[-1] print("\nThe linear baseline B(r)=%f*r + %f" % tuple(par for par in cov.model[-1])) print("\n ------ Uncertainties from a Saved File --------") @@ -173,7 +173,7 @@ def run(plot=True): # Calculated the scaled intensities and uncertainties. intensity = [] for i in range(0, len(cov.model) - 1): - (area, darea) = cov.get((i, 2)) + area, darea = cov.get((i, 2)) area *= scale darea = area * np.sqrt((dscale / scale) ** 2 + (darea / area) ** 2) intensity.append((ideal_intensity[i], area, darea)) diff --git a/news/precommit-hook-update.rst b/news/precommit-hook-update.rst new file mode 100644 index 0000000..e4228a5 --- /dev/null +++ b/news/precommit-hook-update.rst @@ -0,0 +1,23 @@ +**Added:** + +* No news needed: updating docformatter not user facing + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/pyproject.toml b/pyproject.toml index b132bbe..0dd7456 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,11 +60,10 @@ exclude-file = ".codespell/ignore_lines.txt" ignore-words = ".codespell/ignore_words.txt" skip = "*.cif,*.dat" -[tool.ruff] -line-length = 115 - -[tool.ruff.lint.pydocstyle] -convention = "numpy" +[tool.docformatter] +recursive = true +wrap-summaries = 72 +wrap-descriptions = 72 [tool.black] line-length = 115 diff --git a/src/diffpy/srmise/__init__.py b/src/diffpy/srmise/__init__.py index 299db09..34d9ab1 100644 --- a/src/diffpy/srmise/__init__.py +++ b/src/diffpy/srmise/__init__.py @@ -13,8 +13,7 @@ # ############################################################################## """Peak extraction and peak fitting tool for atomic pair distribution -functions. -""" +functions.""" # package version from diffpy.srmise.version import __version__ # noqa diff --git a/src/diffpy/srmise/applications/extract.py b/src/diffpy/srmise/applications/extract.py index 3dd4eaa..efb4db2 100755 --- a/src/diffpy/srmise/applications/extract.py +++ b/src/diffpy/srmise/applications/extract.py @@ -433,7 +433,7 @@ def main(): ) parser.add_option_group(group) - (options, args) = parser.parse_args() + options, args = parser.parse_args() if len(args) != 1: parser.error("Exactly one argument required. \n" + usage) diff --git a/src/diffpy/srmise/applications/plot.py b/src/diffpy/srmise/applications/plot.py index b4d28c0..931efb5 100755 --- a/src/diffpy/srmise/applications/plot.py +++ b/src/diffpy/srmise/applications/plot.py @@ -522,7 +522,6 @@ def makeplot(ppe_or_stability, ip=None, **kwds): def on_draw(event): - global _lastxpos fig = event.canvas.figure ax_main = fig.get_axes()[0] invisiblelabel = ax_main.axis["left"].label @@ -556,8 +555,7 @@ def on_draw(event): def readcompare(filename): """Returns a list of distances read from filename, otherwise - None. - """ + None.""" # TODO: Make this safer try: datastring = open(filename, "rb").read() diff --git a/src/diffpy/srmise/basefunction.py b/src/diffpy/srmise/basefunction.py index 861a85d..7954412 100644 --- a/src/diffpy/srmise/basefunction.py +++ b/src/diffpy/srmise/basefunction.py @@ -12,8 +12,7 @@ # ############################################################################## """Defines BaseFunction, the base class for mathematical functions in -srmise. -""" +srmise.""" import logging import re diff --git a/src/diffpy/srmise/baselines/base.py b/src/diffpy/srmise/baselines/base.py index fabf835..2954a91 100644 --- a/src/diffpy/srmise/baselines/base.py +++ b/src/diffpy/srmise/baselines/base.py @@ -128,8 +128,7 @@ def getmodule(self): class Baseline(ModelPart): """Represents a baseline associated with a BaselineFunction - subclass. - """ + subclass.""" def __init__(self, owner, pars, free=None, removable=False, static_owner=False): """Initialize the BaselineComponent instance with specified diff --git a/src/diffpy/srmise/baselines/polynomial.py b/src/diffpy/srmise/baselines/polynomial.py index df0f379..2631c4f 100644 --- a/src/diffpy/srmise/baselines/polynomial.py +++ b/src/diffpy/srmise/baselines/polynomial.py @@ -24,8 +24,7 @@ class Polynomial(BaselineFunction): """Methods for evaluation and parameter estimation of a polynomial - baseline. - """ + baseline.""" def __init__(self, degree, Cache=None): """Initialize a polynomial function of degree d. diff --git a/src/diffpy/srmise/dataclusters.py b/src/diffpy/srmise/dataclusters.py index c79d5fb..fd82b11 100644 --- a/src/diffpy/srmise/dataclusters.py +++ b/src/diffpy/srmise/dataclusters.py @@ -12,8 +12,7 @@ # ############################################################################## """Defines class to partition sequences representing the x and y axis -into peak-like clusters. -""" +into peak-like clusters.""" import logging @@ -280,7 +279,7 @@ def find_nearest_cluster(self, idx): Returns ------- array-like - The array of cluster index and the distacne to the nearest cluster. None if no clusters exist. + The array of cluster index and the distance to the nearest cluster. None if no clusters exist. """ if self.status == self.INIT: raise Exception("Cannot cluster next point while status is INIT.") @@ -399,9 +398,10 @@ def find_adjacent_clusters(self): """Return all cluster indices with no unclustered points between them. - Return array([[leftmost_idx1,...,rightmost_idx1],...]) such that there - are no unclustered points between each element in subarray of clusters - (inclusive). If no such clusters exist, returns an empty array. + Return array([[leftmost_idx1,...,rightmost_idx1],...]) such that + there are no unclustered points between each element in subarray + of clusters (inclusive). If no such clusters exist, returns an + empty array. """ if self.status == self.INIT: raise Exception("Cannot cluster next point while status is INIT.") @@ -469,7 +469,7 @@ def plot(self, *args, **kwds): plt.plot(self.x, self.y, *args, **kwds) plt.ioff() boundaries = self.cluster_boundaries() - (ymin, ymax) = ax.get_ylim() + ymin, ymax = ax.get_ylim() for b in boundaries: plt.axvline(b[0], 0, (b[1] - ymin) / (ymax - ymin), color="k") plt.ion() diff --git a/src/diffpy/srmise/modelcluster.py b/src/diffpy/srmise/modelcluster.py index c1a64c5..7a7c467 100644 --- a/src/diffpy/srmise/modelcluster.py +++ b/src/diffpy/srmise/modelcluster.py @@ -369,8 +369,7 @@ def correlationwarning(self, threshold=0.8): def __str__(self): """Return string of value (uncertainty) pairs for all - parameters. - """ + parameters.""" if self.model is None or self.cov is None: return "Model and/or Covariance matrix undefined." lines = [] @@ -977,8 +976,9 @@ def deletepeak(self, idx): self.replacepeaks([], slice(idx, idx + 1)) def estimatepeak(self): - """Attempt to add single peak to empty cluster. Return True if - successful. + """Attempt to add single peak to empty cluster. + + Return True if successful. Returns ------- diff --git a/src/diffpy/srmise/modelevaluators/base.py b/src/diffpy/srmise/modelevaluators/base.py index 1da3f34..7b44d6f 100644 --- a/src/diffpy/srmise/modelevaluators/base.py +++ b/src/diffpy/srmise/modelevaluators/base.py @@ -72,7 +72,6 @@ def __init__(self, method, higher_is_better): def __lt__(self, other): """""" - assert self.method == other.method # Comparison between same types required assert self.stat is not None and other.stat is not None # The statistic must already be calculated @@ -83,7 +82,6 @@ def __lt__(self, other): def __le__(self, other): """""" - assert self.method == other.method # Comparison between same types required assert self.stat is not None and other.stat is not None # The statistic must already be calculated @@ -94,7 +92,6 @@ def __le__(self, other): def __eq__(self, other): """""" - assert self.method == other.method # Comparison between same types required assert self.stat is not None and other.stat is not None # The statistic must already be calculated @@ -102,7 +99,6 @@ def __eq__(self, other): def __ne__(self, other): """""" - assert self.method == other.method # Comparison between same types required assert self.stat is not None and other.stat is not None # The statistic must already be calculated @@ -110,7 +106,6 @@ def __ne__(self, other): def __gt__(self, other): """""" - assert self.method == other.method # Comparison between same types required assert self.stat is not None and other.stat is not None # The statistic must already be calculated @@ -121,7 +116,6 @@ def __gt__(self, other): def __ge__(self, other): """""" - assert self.method == other.method # Comparison between same types required assert self.stat is not None and other.stat is not None # The statistic must already be calculated diff --git a/src/diffpy/srmise/multimodelselection.py b/src/diffpy/srmise/multimodelselection.py index 91cd34c..fb67e7b 100644 --- a/src/diffpy/srmise/multimodelselection.py +++ b/src/diffpy/srmise/multimodelselection.py @@ -34,8 +34,7 @@ def eatkwds(*args, **kwds): class MultimodelSelection(PeakStability): """Quick and dirty multimodel selection using AIC and its - offspring. - """ + offspring.""" def __init__(self): """""" @@ -86,7 +85,7 @@ def makeaics(self, dgs, dr, filename=None): self.aics[dg] = [] aics_out[dg] = [] - (r, y, dr, dy) = self.ppe.resampledata(dr) + r, y, dr, dy = self.ppe.resampledata(dr) for model_idx in range(len(self.results)): print("Testing model %s of %s." % (model_idx, len(self.results))) @@ -199,8 +198,7 @@ def makeaicprobs(self): def makesortedprobs(self): """Make probabilities for the sequence of AICs in a sorted - order. - """ + order.""" self.sortedprobs = {} for dg in self.dgs: diff --git a/src/diffpy/srmise/pdfdataset.py b/src/diffpy/srmise/pdfdataset.py index 3965fe3..154d25f 100644 --- a/src/diffpy/srmise/pdfdataset.py +++ b/src/diffpy/srmise/pdfdataset.py @@ -16,7 +16,6 @@ ############################################################################## """Class PDFDataSet for experimental PDF data.""" - import os.path import re import time @@ -169,8 +168,9 @@ def setvar(self, var, value): return def getvar(self, var): - """Obtain value corresponding to PdfFit dataset variable. Used - by findParameters(). + """Obtain value corresponding to PdfFit dataset variable. + + Used by findParameters(). Parameters ---------- @@ -411,17 +411,18 @@ def writeStr(self): return datastring def copy(self, other=None): - """Copy self to other. if other is None, create new instance. - - Parameters - ---------- - other : PDFDataSet instance - ref to other object - - Returns - ------- - PDFDataSet instance - reference to copied object + """Copy self to other. + + if other is None, create new instance. + Parameters + ---------- + other : PDFDataSet instance + ref to other object + + Returns + ------- + PDFDataSet instance + reference to copied object """ if other is None: other = PDFDataSet(self.name) diff --git a/src/diffpy/srmise/pdfpeakextraction.py b/src/diffpy/srmise/pdfpeakextraction.py index 3744bb8..6fdc008 100644 --- a/src/diffpy/srmise/pdfpeakextraction.py +++ b/src/diffpy/srmise/pdfpeakextraction.py @@ -332,8 +332,9 @@ def errorscale(self, dr): return 1.0 def extract(self, **kwds): - """Extract peaks from the PDF. Returns ModelCovariance instance - summarizing results. + """Extract peaks from the PDF. + + Returns ModelCovariance instance summarizing results. Parameters ---------- @@ -394,7 +395,7 @@ def extract(self, **kwds): if dr_nyquist / dr_raw < self.supersample: # supersample PDF for initial extraction dr = dr_nyquist / self.supersample - (r1, y1, r_error1, y_error1) = self.resampledata(dr) + r1, y1, r_error1, y_error1 = self.resampledata(dr) else: # provided PDF already sufficiently oversampled r1 = self.x[rngslice] @@ -483,7 +484,7 @@ def extract(self, **kwds): dr_nyquist, ) - (r2, y2, r_error2, y_error2) = self.resampledata(dr_resample) + r2, y2, r_error2, y_error2 = self.resampledata(dr_resample) ext = ModelCluster( ext.model, @@ -556,8 +557,9 @@ def extract(self, **kwds): return cov def fit(self, **kwds): - """Fit peaks in the PDF. Returns ModelCovariance instance - summarizing results. + """Fit peaks in the PDF. + + Returns ModelCovariance instance summarizing results. Parameters ---------- @@ -602,7 +604,7 @@ def fit(self, **kwds): y1 = self.y[rngslice] y_error1 = self.effective_dy[rngslice] else: - (r1, y1, r_error1, y_error1) = self.resampledata(dr_nyquist) + r1, y1, r_error1, y_error1 = self.resampledata(dr_nyquist) # Set up for fit_single pe = PeakExtraction() diff --git a/src/diffpy/srmise/peakextraction.py b/src/diffpy/srmise/peakextraction.py index 48e3419..c78f20f 100644 --- a/src/diffpy/srmise/peakextraction.py +++ b/src/diffpy/srmise/peakextraction.py @@ -719,8 +719,7 @@ def writesummary(self): def getrangeslice(self): """Convert the ranges in terms of x-coordinates to a slice - object. - """ + object.""" low_idx = 0 while self.x[low_idx] < max(self.x[0], self.rng[0]): low_idx += 1 @@ -814,8 +813,9 @@ def add_peaks(self, peaks): self.initial_peaks.sort(key="position") def extract_single(self, recursion_depth=1): - """Find ModelCluster with peaks extracted from data. Return - ModelCovariance instance at top level. + """Find ModelCluster with peaks extracted from data. + + Return ModelCovariance instance at top level. Every extracted peak is one of the peak functions supplied. All comparisons of different peak models are performed with the class diff --git a/src/diffpy/srmise/peaks/base.py b/src/diffpy/srmise/peaks/base.py index 7e57c10..eca3c76 100644 --- a/src/diffpy/srmise/peaks/base.py +++ b/src/diffpy/srmise/peaks/base.py @@ -135,8 +135,7 @@ def __init__(self, *args, **kwds): def argsort(self, key="position"): """Return sequence of indices which sort peaks in order - specified by key. - """ + specified by key.""" keypars = np.array([p[key] for p in self]) # In normal use the peaks will already be sorted, so check for it. sorted = True @@ -215,8 +214,7 @@ def sort(self, reverse=False, key="position"): class Peak(ModelPart): """Represents a single peak associated with a PeakFunction - subclass. - """ + subclass.""" def __init__(self, owner, pars, free=None, removable=True, static_owner=False): """Set instance members. diff --git a/src/diffpy/srmise/peaks/gaussian.py b/src/diffpy/srmise/peaks/gaussian.py index 2c9b713..b992b2f 100644 --- a/src/diffpy/srmise/peaks/gaussian.py +++ b/src/diffpy/srmise/peaks/gaussian.py @@ -46,8 +46,7 @@ class Gaussian(PeakFunction): # equivalent to 3 standard deviations. def __init__(self, maxwidth, Cache=None): """Maxwidth defined as full width at half maximum for the - corresponding Gaussian, which is physically relevant. - """ + corresponding Gaussian, which is physically relevant.""" parameterdict = {"position": 0, "width": 1, "area": 2} formats = ["internal", "pwa", "mu_sigma_area"] default_formats = { diff --git a/src/diffpy/srmise/peaks/gaussianoverr.py b/src/diffpy/srmise/peaks/gaussianoverr.py index c47191a..158d1b3 100644 --- a/src/diffpy/srmise/peaks/gaussianoverr.py +++ b/src/diffpy/srmise/peaks/gaussianoverr.py @@ -46,8 +46,7 @@ class GaussianOverR(PeakFunction): # equivalent to 3 standard deviations. def __init__(self, maxwidth, Cache=None): """Maxwidth defined as full width at half maximum for the - corresponding Gaussian, which is physically relevant. - """ + corresponding Gaussian, which is physically relevant.""" parameterdict = {"position": 0, "width": 1, "area": 2} formats = ["internal", "pwa", "mu_sigma_area"] default_formats = { diff --git a/src/diffpy/srmise/peaks/terminationripples.py b/src/diffpy/srmise/peaks/terminationripples.py index 315e02a..adaf710 100644 --- a/src/diffpy/srmise/peaks/terminationripples.py +++ b/src/diffpy/srmise/peaks/terminationripples.py @@ -24,8 +24,7 @@ class TerminationRipples(PeakFunction): """Methods for evaluation and parameter estimation of a peak - function with termination ripples. - """ + function with termination ripples.""" def __init__(self, base, qmax, extension=4.0, supersample=5.0, Cache=None): """Peak function constructor which adds termination ripples to @@ -241,7 +240,7 @@ def jacobian(self, peak, r, rng=None): if rng is None: rng = slice(0, len(r)) rpart = r[rng] - (ext_r, ext_slice) = self.extend_grid(rpart, dr) + ext_r, ext_slice = self.extend_grid(rpart, dr) jac = self._jacobianraw(peak.pars, ext_r, peak.free) output = [None for j in jac] for idx in range(len(output)): @@ -253,7 +252,7 @@ def jacobian(self, peak, r, rng=None): except TypeError: # dr is ad hoc if r is a single point. dr = 2 * np.pi / (self.supersample * self.qmax) - (ext_r, ext_slice) = self.extend_grid(np.array([r]), dr) + ext_r, ext_slice = self.extend_grid(np.array([r]), dr) jac = self._jacobianraw(peak.pars, ext_r, peak.free) for idx in range(len(output)): if jac[idx] is not None: @@ -297,7 +296,7 @@ def value(self, peak, r, rng=None): dr_super = 2 * np.pi / (self.supersample * self.qmax) if np.isscalar(r): # dr is ad hoc if r is a single point. - (ext_r, ext_slice) = self.extend_grid(np.array([r]), dr_super) + ext_r, ext_slice = self.extend_grid(np.array([r]), dr_super) value = self._valueraw(peak.pars, ext_r) value = self.cut_freq(value, dr_super) return value[ext_slice][0] @@ -324,7 +323,7 @@ def value(self, peak, r, rng=None): if segments > 1: rpart = np.arange(rpart[0], rpart[-1] + dr_segmented / 2, dr_segmented) - (ext_r, ext_slice) = self.extend_grid(rpart, dr_segmented) + ext_r, ext_slice = self.extend_grid(rpart, dr_segmented) value = self._valueraw(peak.pars, ext_r) value = self.cut_freq(value, dr_segmented) output[rng] = value[ext_slice][::segments] diff --git a/src/diffpy/srmise/peakstability.py b/src/diffpy/srmise/peakstability.py index 77e3928..894706a 100644 --- a/src/diffpy/srmise/peakstability.py +++ b/src/diffpy/srmise/peakstability.py @@ -48,7 +48,7 @@ def load(self, filename): in_s = open(filename, "rb") try: - (self.results, ppestr) = pickle.load(in_s) + self.results, ppestr = pickle.load(in_s) self.ppe = PDFPeakExtraction() self.ppe.readstr(ppestr) @@ -144,7 +144,7 @@ def setcurrent(self, idx): if idx is not None: result = self.results[idx] self.ppe.setvars(quiet=True, effective_dy=result[0] * np.ones(len(self.ppe.x))) - (r, y, dr, dy) = self.ppe.resampledata(result[3]) + r, y, dr, dy = self.ppe.resampledata(result[3]) self.ppe.extracted = ModelCluster( result[1], result[2], diff --git a/src/diffpy/srmise/srmiseerrors.py b/src/diffpy/srmise/srmiseerrors.py index cdd8f71..efe42e6 100644 --- a/src/diffpy/srmise/srmiseerrors.py +++ b/src/diffpy/srmise/srmiseerrors.py @@ -28,6 +28,8 @@ SrMiseStaticOwnerError: Error when changing ModelPart instance owner. """ +# FIXME: remove this line when `docformatter` fixes the blank line bug + # Superclass class for diffpy.srmise.mise class SrMiseError(Exception): diff --git a/src/diffpy/srmise/srmiselog.py b/src/diffpy/srmise/srmiselog.py index d5fcd6f..ba9e13a 100644 --- a/src/diffpy/srmise/srmiselog.py +++ b/src/diffpy/srmise/srmiselog.py @@ -99,7 +99,6 @@ def setfilelevel(level): ---------- level: The logging level. """ - global fh if fh is not None: level = LEVELS.get(level, level) fh.setLevel(level) @@ -117,7 +116,6 @@ def setlevel(level): ---------- level: The logging level. """ - global ch level = LEVELS.get(level, level) ch.setLevel(level) if level < logger.getEffectiveLevel(): diff --git a/tests/test_version.py b/tests/test_version.py index 04f9972..06a0a7c 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -5,7 +5,6 @@ def test_package_version(): """Ensure the package version is defined and not set to the initial - placeholder. - """ + placeholder.""" assert hasattr(diffpy.srmise, "__version__") assert diffpy.srmise.__version__ != "0.0.0"