Skip to content

Commit

Permalink
ruff check . --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Nov 12, 2024
1 parent 843cbdf commit 69d1354
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
target-version = "py39"

extend-exclude = [ 'extern', 'doc/source/gettingstarted/examples' ]

lint.extend-select = [
"A",
"B",
Expand Down
58 changes: 17 additions & 41 deletions freud/diffraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,16 @@
finalized in a future release.
"""

# from libcpp import bool as cbool
# from libcpp.vector import vector

from freud.util import _Compute # , vec3

import logging

import numpy as np
import rowan
import scipy.ndimage

import freud.locality

import numpy as np

import freud._diffraction
import freud.locality
import freud.util
from freud.util import _Compute

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -214,11 +206,12 @@ def compute(self, system, query_points=None, N_total=None, reset=True):
value: True).
""" # noqa E501
if (query_points is None) != (N_total is None):
raise ValueError(
msg = (
"If query_points are provided, N_total must also be provided "
"in order to correctly compute the normalization of the "
"partial structure factor."
)
raise ValueError(msg)

if reset:
self._reset()
Expand Down Expand Up @@ -248,13 +241,8 @@ def min_valid_k(self):

def __repr__(self):
return (
"freud.diffraction.{cls}(num_k_values={num_k_values}, "
"k_max={k_max}, k_min={k_min})"
).format(
cls=type(self).__name__,
num_k_values=self.num_k_values,
k_max=self.k_max,
k_min=self.k_min,
f"freud.diffraction.{type(self).__name__}(num_k_values={self.num_k_values},"
f" k_max={self.k_max}, k_min={self.k_min})"
)

def plot(self, ax=None, **kwargs):
Expand Down Expand Up @@ -433,11 +421,12 @@ def compute(self, system, query_points=None, N_total=None, reset=True):
value = True).
""" # noqa E501
if (query_points is None) != (N_total is None):
raise ValueError(
msg = (
"If query_points are provided, N_total must also be provided "
"in order to correctly compute the normalization of the "
"partial structure factor."
)
raise ValueError(msg)
if reset:
self._reset()

Expand Down Expand Up @@ -480,15 +469,9 @@ def k_points(self):

def __repr__(self):
return (
"freud.diffraction.{cls}(bins={bins}, "
"k_max={k_max}, k_min={k_min}, "
"num_sampled_k_points={num_sampled_k_points})"
).format(
cls=type(self).__name__,
bins=self.nbins,
k_max=self.k_max,
k_min=self.k_min,
num_sampled_k_points=self.num_sampled_k_points,
f"freud.diffraction.{type(self).__name__}(bins={self.nbins}, "
f"k_max={self.k_max}, k_min={self.k_min}, "
f"num_sampled_k_points={self.num_sampled_k_points})"
)

def plot(self, ax=None, **kwargs):
Expand Down Expand Up @@ -611,8 +594,7 @@ def _calc_proj(self, view_orientation, box):
shear = box_matrix[np.ix_([0, 1], secondary_axes)]

# Return the inverse shear matrix
inv_shear = np.linalg.inv(shear)
return inv_shear
return np.linalg.inv(shear)

def _transform(self, img, box, inv_shear, zoom):
"""Zoom, shear, and scale diffraction intensities.
Expand All @@ -630,7 +612,7 @@ def _transform(self, img, box, inv_shear, zoom):
Returns:
(``output_size, output_size``) :class:`numpy.ndarray`:
Transformed array of diffraction intensities.
""" # noqa: E501
"""

# The adjustments to roll and roll_shift ensure that the peak
# corresponding to k=0 is located at exactly
Expand Down Expand Up @@ -667,14 +649,13 @@ def _transform(self, img, box, inv_shear, zoom):
# transforms 2D points and adds an offset.
inverse_transform = np.linalg.inv(zoom_matrix @ shear_matrix @ shift_matrix)

img = scipy.ndimage.affine_transform(
return scipy.ndimage.affine_transform(
input=img,
matrix=inverse_transform,
output_shape=(self.output_size, self.output_size),
order=1,
mode="constant",
)
return img

def compute(self, system, view_orientation=None, zoom=4, peak_width=1, reset=True):
r"""Computes diffraction pattern.
Expand Down Expand Up @@ -703,9 +684,8 @@ def compute(self, system, view_orientation=None, zoom=4, peak_width=1, reset=Tru
system = freud.locality.NeighborQuery.from_system(system)

if not system.box.cubic:
raise ValueError(
"freud.diffraction.DiffractionPattern only " "supports cubic boxes"
)
msg = "freud.diffraction.DiffractionPattern only supports cubic boxes"
raise ValueError(msg)

if view_orientation is None:
view_orientation = np.array([1.0, 0.0, 0.0, 0.0])
Expand Down Expand Up @@ -816,12 +796,8 @@ def k_vectors(self):

def __repr__(self):
return (
"freud.diffraction.{cls}(grid_size={grid_size}, "
"output_size={output_size})"
).format(
cls=type(self).__name__,
grid_size=self.grid_size,
output_size=self.output_size,
f"freud.diffraction.{type(self).__name__}(grid_size={self.grid_size}, "
f"output_size={self.output_size})"
)

def to_image(self, cmap="afmhot", vmin=None, vmax=None):
Expand Down

0 comments on commit 69d1354

Please sign in to comment.