Skip to content

style: set the line width limit to 79 #164

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

Merged
merged 4 commits into from
Feb 10, 2025
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: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exclude =
build,
dist,
doc/source/conf.py
max-line-length = 115
max-line-length = 79
# Ignore some style 'errors' produced while formatting by 'black'
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings
extend-ignore = E203
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[settings]
line_length = 115
line_length = 79
multi_line_output = 3
include_trailing_comma = True
18 changes: 16 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
("index", "diffpy.pdfmorph.tex", "diffpy.pdfmorph Documentation", ab_authors, "manual"),
(
"index",
"diffpy.pdfmorph.tex",
"diffpy.pdfmorph Documentation",
ab_authors,
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -251,7 +257,15 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [("index", "diffpy.pdfmorph", "diffpy.pdfmorph Documentation", ab_authors, 1)]
man_pages = [
(
"index",
"diffpy.pdfmorph",
"diffpy.pdfmorph Documentation",
ab_authors,
1,
)
]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand Down
23 changes: 23 additions & 0 deletions news/line79.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* reduce the line width limit to 79

**Security:**

* <news item>
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ignore-words = ".codespell/ignore_words.txt"
skip = "*.cif,*.dat,*agr"

[tool.black]
line-length = 115
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
Expand Down
11 changes: 8 additions & 3 deletions src/diffpy/pdfmorph/morph_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
#
##############################################################################

"""List of helpers for certain morphing operations (currently only used for smear)."""
"""List of helpers for certain morphing operations
(currently only used for smear)."""

from diffpy.pdfmorph.morph_helpers.transformpdftordf import TransformXtalPDFtoRDF
from diffpy.pdfmorph.morph_helpers.transformrdftopdf import TransformXtalRDFtoPDF
from diffpy.pdfmorph.morph_helpers.transformpdftordf import (
TransformXtalPDFtoRDF,
)
from diffpy.pdfmorph.morph_helpers.transformrdftopdf import (
TransformXtalRDFtoPDF,
)

# List of helpers
morph_helpers = [
Expand Down
4 changes: 3 additions & 1 deletion src/diffpy/pdfmorph/morph_helpers/transformpdftordf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def morph(self, x_morph, y_morph, x_target, y_target):
morph_baseline = self.baselineslope * self.x_morph_in
self.y_morph_out = self.x_morph_in * (self.y_morph_in - morph_baseline)
target_baseline = self.baselineslope * self.x_target_in
self.y_target_out = self.x_target_in * (self.y_target_in - target_baseline)
self.y_target_out = self.x_target_in * (
self.y_target_in - target_baseline
)
return self.xyallout


Expand Down
8 changes: 6 additions & 2 deletions src/diffpy/pdfmorph/morph_helpers/transformrdftopdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ def morph(self, x_morph, y_morph, x_target, y_target):
morph_baseline = self.baselineslope * self.x_morph_in
target_baseline = self.baselineslope * self.x_target_in
with numpy.errstate(divide="ignore", invalid="ignore"):
self.y_target_out = self.y_target_in / self.x_target_in + target_baseline
self.y_target_out = (
self.y_target_in / self.x_target_in + target_baseline
)
self.y_target_out[self.x_target_in == 0] = 0
with numpy.errstate(divide="ignore", invalid="ignore"):
self.y_morph_out = self.y_morph_in / self.x_morph_in + morph_baseline
self.y_morph_out = (
self.y_morph_in / self.x_morph_in + morph_baseline
)
self.y_morph_out[self.x_target_in == 0] = 0
return self.xyallout

Expand Down
21 changes: 14 additions & 7 deletions src/diffpy/pdfmorph/morphs/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
class Morph(object):
"""Base class for implementing a morph given a target.

Adapted from diffpy.pdfgetx to include two sets of arrays that get passed through.
Adapted from diffpy.pdfgetx to include two sets of arrays that get passed
through.

Attributes are taken from config when not found locally. The morph may modify the config dictionary.
This is the means by which to communicate automatically modified attributes.
Attributes are taken from config when not found locally. The morph may
modify the config dictionary. This is the means by which to communicate
automatically modified attributes.

Class Attributes
----------------
Expand Down Expand Up @@ -142,7 +144,8 @@ def __init__(self, config=None):
def morph(self, x_morph, y_morph, x_target, y_target):
"""Morph arrays morphed or target.

Identity operation. This method should be overloaded in a derived class.
Identity operation.
This method should be overloaded in a derived class.

Parameters
----------
Expand All @@ -154,7 +157,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
Returns
-------
tuple
A tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out)
A tuple of numpy arrays
(x_morph_out, y_morph_out, x_target_out, y_target_out)
"""
self.x_morph_in = x_morph
self.y_morph_in = y_morph
Expand Down Expand Up @@ -223,7 +227,8 @@ def plotOutputs(self, xylabels=True, **plotargs):
xylabels: bool
Flag for updating x and y axes labels.
plotargs
Arguments passed to the pylab plot function. Note that "label" will be ignored.
Arguments passed to the pylab plot function.
Note that "label" will be ignored.

Returns
-------
Expand All @@ -234,7 +239,9 @@ def plotOutputs(self, xylabels=True, **plotargs):

pargs = dict(plotargs)
pargs.pop("label", None)
rv = plot(self.x_target_out, self.y_target_out, label="target", **pargs)
rv = plot(
self.x_target_out, self.y_target_out, label="target", **pargs
)
rv = plot(self.x_morph_out, self.y_morph_out, label="morph", **pargs)
if xylabels:
xlabel(self.xoutlabel)
Expand Down
68 changes: 50 additions & 18 deletions src/diffpy/pdfmorph/morphs/morphchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
class MorphChain(list):
"""Class for chaining morphs together.

This class is a queue of morphs that get executed in order via the 'morph' method.
This class derives from the built-in list, and list methods are used to modify the queue.
This class is a queue of morphs that get executed in order via the 'morph'
method. This class derives from the built-in list, and list methods are
used to modify the queue.

This derives from list and relies on its methods where possible.

Expand Down Expand Up @@ -57,7 +58,8 @@ class MorphChain(list):
xy_target_out
Tuple of (x_target_out, y_target_out) from last morph.
xyallout
Tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out) from last morph.
Tuple of (x_morph_out, y_morph_out, x_target_out, y_target_out)
from last morph.
parnames
Names of parameters collected from morphs (Read only).

Expand All @@ -66,19 +68,47 @@ class MorphChain(list):
The properties return tuples of None if there are no morphs.
"""

x_morph_in = property(lambda self: None if len(self) == 0 else self[0].x_morph_in)
y_morph_in = property(lambda self: None if len(self) == 0 else self[0].y_morph_in)
x_target_in = property(lambda self: None if len(self) == 0 else self[0].x_target_in)
y_target_in = property(lambda self: None if len(self) == 0 else self[0].y_target_in)
x_morph_out = property(lambda self: None if len(self) == 0 else self[-1].x_morph_out)
y_morph_out = property(lambda self: None if len(self) == 0 else self[-1].y_morph_out)
x_target_out = property(lambda self: None if len(self) == 0 else self[-1].x_target_out)
y_target_out = property(lambda self: None if len(self) == 0 else self[-1].y_target_out)
xy_morph_in = property(lambda self: (None, None) if len(self) == 0 else self[0].xy_morph_in)
xy_morph_out = property(lambda self: (None, None) if len(self) == 0 else self[-1].xy_morph_out)
xy_target_in = property(lambda self: (None, None) if len(self) == 0 else self[0].xy_target_in)
xy_target_out = property(lambda self: (None, None) if len(self) == 0 else self[-1].xy_target_out)
xyallout = property(lambda self: (None, None, None, None) if len(self) == 0 else self[-1].xyallout)
x_morph_in = property(
lambda self: None if len(self) == 0 else self[0].x_morph_in
)
y_morph_in = property(
lambda self: None if len(self) == 0 else self[0].y_morph_in
)
x_target_in = property(
lambda self: None if len(self) == 0 else self[0].x_target_in
)
y_target_in = property(
lambda self: None if len(self) == 0 else self[0].y_target_in
)
x_morph_out = property(
lambda self: None if len(self) == 0 else self[-1].x_morph_out
)
y_morph_out = property(
lambda self: None if len(self) == 0 else self[-1].y_morph_out
)
x_target_out = property(
lambda self: None if len(self) == 0 else self[-1].x_target_out
)
y_target_out = property(
lambda self: None if len(self) == 0 else self[-1].y_target_out
)
xy_morph_in = property(
lambda self: (None, None) if len(self) == 0 else self[0].xy_morph_in
)
xy_morph_out = property(
lambda self: (None, None) if len(self) == 0 else self[-1].xy_morph_out
)
xy_target_in = property(
lambda self: (None, None) if len(self) == 0 else self[0].xy_target_in
)
xy_target_out = property(
lambda self: (None, None) if len(self) == 0 else self[-1].xy_target_out
)
xyallout = property(
lambda self: (
(None, None, None, None) if len(self) == 0 else self[-1].xyallout
)
)
parnames = property(lambda self: set(p for m in self for p in m.parnames))

def __init__(self, config, *args):
Expand All @@ -89,7 +119,8 @@ def __init__(self, config, *args):

Notes
-----
Additional arguments are morphs that will extend the queue of morphs.
Additional arguments are morphs that will extend the queue of
morphs.
"""
self.config = config
self.extend(args)
Expand All @@ -108,7 +139,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
Returns
-------
tuple
A tuple of numpy arrays (x_morph_out, y_morph_out, x_target_out, y_target_out).
A tuple of numpy arrays
(x_morph_out, y_morph_out, x_target_out, y_target_out).

Notes
-----
Expand Down
24 changes: 17 additions & 7 deletions src/diffpy/pdfmorph/morphs/morphrgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ class MorphRGrid(Morph):

Notes
-----
If any of these is not defined or outside the bounds of the input arrays,
then it will be taken to be the most inclusive value from the input arrays.
These modified values will be stored as the above attributes.
If any of these is not defined or outside the bounds of the input
arrays, then it will be taken to be the most inclusive value from the
input arrays. These modified values will be stored as the above
attributes.
"""

# Define input output types
Expand All @@ -63,18 +64,27 @@ def morph(self, x_morph, y_morph, x_target, y_target):
r_step_target = self.x_target_in[1] - self.x_target_in[0]
r_step_morph = self.x_morph_in[1] - self.x_morph_in[0]
rstepinc = max(r_step_target, r_step_morph)
rmaxinc = min(self.x_target_in[-1] + r_step_target, self.x_morph_in[-1] + r_step_morph)
rmaxinc = min(
self.x_target_in[-1] + r_step_target,
self.x_morph_in[-1] + r_step_morph,
)
if self.rmin is None or self.rmin < rmininc:
self.rmin = rmininc
if self.rmax is None or self.rmax > rmaxinc:
self.rmax = rmaxinc
if self.rstep is None or self.rstep < rstepinc:
self.rstep = rstepinc
# Make sure that rmax is exclusive
self.x_morph_out = numpy.arange(self.rmin, self.rmax - epsilon, self.rstep)
self.y_morph_out = numpy.interp(self.x_morph_out, self.x_morph_in, self.y_morph_in)
self.x_morph_out = numpy.arange(
self.rmin, self.rmax - epsilon, self.rstep
)
self.y_morph_out = numpy.interp(
self.x_morph_out, self.x_morph_in, self.y_morph_in
)
self.x_target_out = self.x_morph_out.copy()
self.y_target_out = numpy.interp(self.x_target_out, self.x_target_in, self.y_target_in)
self.y_target_out = numpy.interp(
self.x_target_out, self.x_target_in, self.y_target_in
)
return self.xyallout


Expand Down
30 changes: 9 additions & 21 deletions src/diffpy/pdfmorph/morphs/morphshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def morph(self, x_morph, y_morph, x_target, y_target):
def _sphericalCF(r, psize):
"""Spherical nanoparticle characteristic function.

From Kodama et al., Acta Cryst. A, 62, 444-453 (converted from radius to diameter).
From Kodama et al., Acta Cryst. A, 62, 444-453
(converted from radius to diameter).

Parameters
----------
Expand Down Expand Up @@ -163,21 +164,19 @@ def _spheroidalCF2(r, psize, axrat):
r = rx[rx <= v * psize]
r2 = r * r
f1 = (
1
- 3 * r / (4 * d * v) * (1 - r2 / (4 * d2) * (1 + 2.0 / (3 * v2)))
- 3 * r / (4 * d) * (1 - r2 / (4 * d2)) * v / sqrt(1 - v2) * atanh(sqrt(1 - v2))
1 - 3*r/(4*d*v)*(1-r2/(4*d2)*(1+2.0/(3*v2))) - 3*r/(4*d)*(1-r2/(4*d2))*v/sqrt(1-v2)*atanh(sqrt(1-v2)) # fmt: skip # noqa: E501
)

r = rx[numpy.logical_and(rx > v * psize, rx <= psize)]
r2 = r * r
# fmt: off
f2 = (
(
3 * d / (8 * r) * (1 + r2 / (2 * d2)) * sqrt(1 - r2 / d2)
- 3 * r / (4 * d) * (1 - r2 / (4 * d2)) * atanh(sqrt(1 - r2 / d2))
3*d/(8*r)*(1+r2/(2*d2))*sqrt(1-r2/d2) - 3*r/(4*d)*(1-r2/(4*d2))*atanh(sqrt(1-r2/d2)) # noqa: E501
)
* v
/ sqrt(1 - v2)
* v / sqrt(1-v2)
)
# fmt: on

r = rx[rx > psize]
f3 = numpy.zeros_like(r)
Expand All @@ -188,24 +187,13 @@ def _spheroidalCF2(r, psize, axrat):
r = rx[rx <= psize]
r2 = r * r
f1 = (
1
- 3 * r / (4 * d * v) * (1 - r2 / (4 * d2) * (1 + 2.0 / (3 * v2)))
- 3 * r / (4 * d) * (1 - r2 / (4 * d2)) * v / sqrt(v2 - 1) * atan(sqrt(v2 - 1))
1 - 3*r/(4*d*v)*(1-r2/(4*d2)*(1+2.0/(3*v2))) - 3*r/(4*d)*(1-r2/(4*d2))*v/sqrt(v2-1)*atan(sqrt(v2-1)) # fmt: skip # noqa: E501
)

r = rx[numpy.logical_and(rx > psize, rx <= v * psize)]
r2 = r * r
f2 = (
1
- 3 * r / (4 * d * v) * (1 - r2 / (4 * d2) * (1 + 2.0 / (3 * v2)))
- 3.0 / 8 * (1 + r2 / (2 * d2)) * sqrt(1 - d2 / r2) * v / sqrt(v2 - 1)
- 3
* r
/ (4 * d)
* (1 - r2 / (4 * d2))
* v
/ sqrt(v2 - 1)
* (atan(sqrt(v2 - 1)) - atan(sqrt(r2 / d2 - 1)))
1 - 3*r/(4*d*v)*(1-r2/(4*d2)*(1+2.0/(3*v2))) - 3.0/8*(1+r2/(2*d2))*sqrt(1-d2/r2)*v/sqrt(v2-1) - 3*r/(4*d)*(1-r2/(4*d2))*v/sqrt(v2-1)*(atan(sqrt(v2-1))-atan(sqrt(r2/d2-1))) # fmt: skip # noqa:E501
)

r = rx[rx > v * psize]
Expand Down
Loading
Loading