Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement automatic spell check via Codespell and fix typos #149

Merged
merged 3 commits into from
Oct 29, 2024
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
2 changes: 2 additions & 0 deletions .codespell/ignore_lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
;; Please include filenames and explanations for each ignored line.
;; See https://docs.openverse.org/meta/codespell.html for docs.
11 changes: 11 additions & 0 deletions .codespell/ignore_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; Please include explanations for each ignored word (lowercase).
;; See https://docs.openverse.org/meta/codespell.html for docs.

;; abbreviation for "materials" often used in a journal title
mater

;; alternative use of socioeconomic
socio-economic

;; Frobenius norm used in np.linalg.norm
fro
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ repos:
name: Prevent Commit to Main Branch
args: ["--branch", "main"]
stages: [pre-commit]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
- tomli
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Authors
=======

Luke Granlund
Billinge Group and community contibutors.
Billinge Group and community contributors.

Contributors
------------
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ trying to commit again.

Improvements and fixes are always appreciated.

Before contribuing, please read our `Code of Conduct <https://github.com/diffpy/diffpy.srmise/blob/main/CODE_OF_CONDUCT.rst>`_.
Before contributing, please read our `Code of Conduct <https://github.com/diffpy/diffpy.srmise/blob/main/CODE_OF_CONDUCT.rst>`_.

Contact
-------
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ the copiously commented scripts helpful.
* Peak extraction with initial peaks:
extract_initial.py

* Peak fitting with intial peaks:
* Peak fitting with initial peaks:
fit_initial.py

* Querying SrMise results:
Expand Down Expand Up @@ -678,7 +678,7 @@ the baseline. The methods of greatest interest are as follows. ::
# Get the correlation between two parameters
cov.getcorrelation((i1,j1), (i2,j2))

Suppose, for example, one wants to emperically estimate the number of silver
Suppose, for example, one wants to empirically estimate the number of silver
atoms contributing to each occupied coordination shell of the FCC structure,
knowing that the coordination number (i.e. nearest neighbors) of an ideal FCC
structure is exactly 12. For a monoelemental material the intensity of a peak
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/multimodel_known_dG2.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def run(plot=True):
# with respect to the actual experiment when using a Nyquist-sampled PDF
# with experimentally determined uncertainties.
#
# The present PDF satisifes these conditions, so the rankings below reflect
# The present PDF satisfies these conditions, so the rankings below reflect
# an AIC-based estimate of which of the tested models the data best support.
print("\n--------- Model Rankings for dG = %f ---------" % dG)
print("Rank Model Class Free AIC Prob File")
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/extract_single_peak.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
2.90074809344 0.267213055365 9.84389058517 # 1
2 changes: 1 addition & 1 deletion doc/examples/output/fit_initial.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
1.44052045545 0.126922793092 35515.0466525 # 1
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/known_dG_m0.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
11.2310491383 0.29009226516 19.2512559254 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/known_dG_m1.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
11.2529285169 0.364905691879 35.069510576 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/known_dG_m12.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
11.2573520325 0.373991203999 34.6040498151 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/known_dG_m8.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
11.2506286561 0.370187490596 34.3566941925 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/parameter_summary.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
1.9557575566 0.248658302944 2.57966649229 # 1
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/query_results.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
2.90080420526 0.268377339284 9.93053286298 # 1
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/unknown_dG_m11.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
1.44110805058 0.137450008306 36477.2666515 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/unknown_dG_m17.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
1.44210250295 0.130428325915 35832.2439651 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/unknown_dG_m18.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
1.44255991965 0.130976461359 35872.4728645 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/unknown_dG_m5.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
1.44110346987 0.135456358948 36202.906939 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/output/unknown_dG_m7.pwa
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ModelEvaluator=AIC
## Extracted Peaks
# Parameters are given in the natural units of the data,
# where width is measured as full-width at half maximum.
# Each line is followd by a comment which gives the index
# Each line is followed by a comment which gives the index
# of the corresponding Peak Function.
#L position fwhm area
1.4417380998 0.13653359706 36320.7534683 # 2
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# See LICENSE.txt for license information.
#
##############################################################################
"""Example of extracting multiple peaks and accessing results programatically.
"""Example of extracting multiple peaks and accessing results programmatically.

This example shows how to extract a range of peaks from a simple crystalline
PDF using a crystalline baseline obtained from an existing trial. It shows
Expand Down
2 changes: 1 addition & 1 deletion doc/source/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ functionality common to all SrMise baseline and peak functions, which are
separately implemented in the ``diffpy.srmise.baselines`` and
``diffpy.srmise.peaks`` subpackages. Specific baseline and peak functions
inherit from the ``BaselineFunction`` and ``PeakFunction`` classes in those
subpackges, as shown below.
subpackages, as shown below.

* .. py:class:: BaseFunction

Expand Down
23 changes: 23 additions & 0 deletions news/codespell.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Codespell for automatic spelling check, configured in pre-commit

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Typos in the source code and documentation

**Security:**

* <news item>
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ namespaces = false # to disable scanning PEP 420 namespaces (true by default)
[tool.setuptools.dynamic]
dependencies = {file = ["requirements/pip.txt"]}

[tool.codespell]
exclude-file = ".codespell/ignore_lines.txt"
ignore-words = ".codespell/ignore_words.txt"
skip = "*.cif,*.dat"

[tool.black]
line-length = 115
include = '\.pyi?$'
Expand Down
10 changes: 5 additions & 5 deletions src/diffpy/srmise/modelcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ModelCovariance(object):
"""

def __init__(self, *args, **kwds):
"""Intialize object."""
"""Initialize object."""
self.cov = None # The raw covariance matrix
self.model = None # ModelParts instance, so both peaks and baseline (if present)

Expand Down Expand Up @@ -430,7 +430,7 @@ class ModelCluster(object):
"""

def __init__(self, model, *args, **kwds):
"""Intialize explicitly, or from existing ModelCluster.
"""Initialize explicitly, or from existing ModelCluster.

Parameters
----------
Expand Down Expand Up @@ -978,7 +978,7 @@ def estimatepeak(self):
# be estimating and fitting each possible peak type to the data
# and seeing which works best, but for small clusters evaluating
# model quality is generally unreliable, and most peak shapes will
# be approxiately equally good anyway.
# be approximately equally good anyway.
if len(self.model) > 0:
# throw some exception
pass
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def fit(
# after a second peak could potentially explain its residual.
#
# This is a tricky point. It is often the case while fitting that an
# intially good peak becomes less accurate due to greater overlap at
# initially good peak becomes less accurate due to greater overlap at
# the edges of the cluster, even as its (calculated) quality improves.
# This may make combining clusters later more difficult, and so test
# if the degree by which the new fit is off could perhaps be adequately
Expand Down Expand Up @@ -1220,7 +1220,7 @@ def reduce_to(self, x, y):
-------
ModelEvaluator or None
Return ModelEvaluator instance if fit changed, otherwise None."""
# No reduction neccessary
# No reduction necessary
if self.model.value(x) < y:
logger.debug("reduce_to: No reduction necessary.")
return None
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srmise/modelevaluators/aicc.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def akaikeweights(aics):
Parameters
----------
aics : array-like
The squence of AIC instances
The sequence of AIC instances

Returns
-------
Expand All @@ -195,7 +195,7 @@ def akaikeprobs(aics):
Parameters
----------
aics : array-like
The squence of AIC instances
The sequence of AIC instances

Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srmise/pdfdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def readStr(self, datastring):
if res:
self.metadata["doping"] = float(res.groups()[0])

# parsing gerneral metadata
# parsing general metadata
if metadata:
regexp = r"\b(\w+)\ *=\ *(%(f)s)\b" % rx
while True:
Expand Down Expand Up @@ -458,7 +458,7 @@ def copy(self, other=None):


class PDFDataFormatError(Exception):
"""Exception class marking failure to proccess PDF data string."""
"""Exception class marking failure to process PDF data string."""

pass

Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srmise/pdfpeakextraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def resampledata(self, dr, **kwds):
The effective error may be scaled if class member scale is True.

The method for 'resampling' the uncertainties is interpolation, since insufficient
information exists in a PDFPeakExtraction object to propogate them correctly on the
information exists in a PDFPeakExtraction object to propagate them correctly on the
new grid.

Parameters
Expand Down Expand Up @@ -897,7 +897,7 @@ def writepwastr(self, comments):
lines.append("## Extracted Peaks")
lines.append("# Parameters are given in the natural units of the data,")
lines.append("# where width is measured as full-width at half maximum.")
lines.append("# Each line is followd by a comment which gives the index")
lines.append("# Each line is followed by a comment which gives the index")
lines.append("# of the corresponding Peak Function.")
lines.append("#L position fwhm area")
for p in self.extracted.model:
Expand Down
14 changes: 7 additions & 7 deletions src/diffpy/srmise/peakextraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def readstr(self, datastring):
for s in res[1:]:
self.initial_peaks.append(Peak.factory(s, safepf))

# Instantiating srmise metatdata
# Instantiating srmise metadata

# pf
res = re.search(r"^pf=(.*)$", srmisemetadata, re.M)
Expand Down Expand Up @@ -1382,16 +1382,16 @@ def fit_single(self):
err = np.ones(len(r))
evaluator = AICc()

te = PeakExtraction()
te.setdata(r, y, None, err)
te.setvars(rng=[1.51, 10.0], pf=[pf], cres=0.1, effective_dy=1.5 * err)
te.extract_single()
peak_extraction = PeakExtraction()
peak_extraction.setdata(r, y, None, err)
peak_extraction.setvars(rng=[1.51, 10.0], pf=[pf], cres=0.1, effective_dy=1.5 * err)
peak_extraction.extract_single()

print("--- Actual Peak parameters ---")
print(ideal_peaks)

print("\n--- After extraction ---")
print(te)
print(peak_extraction)

te.plot()
peak_extraction.plot()
input()
4 changes: 2 additions & 2 deletions src/diffpy/srmise/peaks/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def estimate_parameters(self, r, y):
)
guesspars[1] = 0.5 * (sigma_right + sigma_left) * self.sigma2fwhm
else:
# Procede cautiously if min_y == max_y. Without other information
# Proceed cautiously if min_y == max_y. Without other information
# we choose the center of the cluster as the peak center, and make
# sure the peak has died down by the time it reaches the edge of
# the data.
Expand Down Expand Up @@ -261,7 +261,7 @@ def _jacobianraw(self, pars, r, free):
if free[2]:
# derivative with respect to peak area
# abs'(x)=sign(x) for real x except at 0 where it is undetermined. Since any real peak necessarily has
# non-zero area and the function is paramaterized such that values of either sign represent equivalent
# non-zero area and the function is parameterized such that values of either sign represent equivalent
# curves I arbitrarily choose positive sign for pars[2]==0 in order to
# push the system back into a realistic parameter space should this improbable scenario occur.
# jacobian[2] = sign(pars[2])*exp_p
Expand Down
Loading