Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
39 changes: 20 additions & 19 deletions docs/examples/multimodel-known-dG1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 21 additions & 20 deletions docs/examples/multimodel-known-dG2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
37 changes: 19 additions & 18 deletions docs/examples/multimodel-unknown-dG1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 28 additions & 25 deletions docs/examples/multimodel-unknown-dG2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/query-results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------")
Expand Down Expand Up @@ -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))
Expand Down
23 changes: 23 additions & 0 deletions news/precommit-hook-update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news needed: updating docformatter not user facing

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/diffpy/srmise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srmise/applications/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/diffpy/srmise/applications/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Loading
Loading