diff --git a/.gitignore b/.gitignore index d418364..099e294 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ __pycache__/ .Python env/ build/ +_build/ develop-eggs/ dist/ downloads/ diff --git a/pyproject.toml b/pyproject.toml index 9b70ac6..b5a477d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,11 @@ exclude-file = ".codespell/ignore_lines.txt" ignore-words = ".codespell/ignore_words.txt" skip = "*.cif,*.dat" +[tool.docformatter] +recursive = true +wrap-summaries = 72 +wrap-descriptions = 72 + [tool.black] line-length = 79 include = '\.pyi?$' diff --git a/requirements/build.txt b/requirements/build.txt deleted file mode 100644 index e69de29..0000000 diff --git a/requirements/docs.txt b/requirements/docs.txt index ab17b1c..5f34c6e 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -1,4 +1,5 @@ sphinx sphinx_rtd_theme +sphinx-copybutton doctr m2r diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index 1df0753..2b9a97b 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -12,11 +12,3 @@ # See LICENSE.rst for license information. # ############################################################################## -"""Blank namespace package for module diffpy.""" - - -from pkgutil import extend_path - -__path__ = extend_path(__path__, __name__) - -# End of file diff --git a/src/diffpy/fourigui/__init__.py b/src/diffpy/fourigui/__init__.py index b0c11f4..cf795f7 100644 --- a/src/diffpy/fourigui/__init__.py +++ b/src/diffpy/fourigui/__init__.py @@ -4,7 +4,7 @@ # (c) 2022-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Billinge Group members and community contributors. +# File coded by: Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. # https://github.com/diffpy/diffpy.fourigui/graphs/contributors @@ -15,7 +15,7 @@ """Tool for visualizing 3D diffraction and PDF images.""" # package version -from diffpy.fourigui.version import __version__ +from diffpy.fourigui.version import __version__ # noqa # silence the pyflakes syntax checker assert __version__ or True diff --git a/src/diffpy/fourigui/fourigui.py b/src/diffpy/fourigui/fourigui.py index f23e6b4..3c97e52 100755 --- a/src/diffpy/fourigui/fourigui.py +++ b/src/diffpy/fourigui/fourigui.py @@ -285,10 +285,10 @@ def initUI(self): ) # , height=HEIGHT//2, width=WIDTH//2) def load_cube(self): - """Loads 3D array in h5py file format from the filename input panel 3D - array is expected to be a reconstructed reciprocal scattering volume - when executed, one slide perpendicular to the selected axis will be - plotted in the plot panel.""" + """Loads 3D array in h5py file format from the filename input + panel 3D array is expected to be a reconstructed reciprocal + scattering volume when executed, one slide perpendicular to the + selected axis will be plotted in the plot panel.""" filename = self.filename_entry.get() f = h5py.File(filename, "r") @@ -397,8 +397,8 @@ def colorrange_upd(self): self.plot_plane() def intensity_upd_local(self): - """Show local intensity minimum, maximum and sum of current plotted - plane.""" + """Show local intensity minimum, maximum and sum of current + plotted plane.""" if self.axis.get() == 0: plane = self.cube[self.plane_num.get(), :, :] elif self.axis.get() == 1: @@ -418,7 +418,8 @@ def intensity_upd_local(self): self.localnanratio["text"] = f"{round(nan_ratio, 2)}" def intensity_upd_global(self): - """Load global intensity minimum, maximum and sum of 3D array.""" + """Load global intensity minimum, maximum and sum of 3D + array.""" self.intensity_upd_local() nan_ratio = np.count_nonzero(np.isnan(self.cube)) / self.cube.size self.globalmax["text"] = ( @@ -433,8 +434,9 @@ def intensity_upd_global(self): self.globalnanratio["text"] = "{}".format(round(nan_ratio, 2)) def fft(self): - """Fourier transform 3D array from reciprocal to real space the origin - of reciprocal and real space is expected to be the central voxel.""" + """Fourier transform 3D array from reciprocal to real space the + origin of reciprocal and real space is expected to be the + central voxel.""" def perform_fft(fftholder): fftholder = np.nan_to_num(fftholder) @@ -487,9 +489,9 @@ def perform_fft(fftholder): self.intensity_upd_global() def ifft(self): - """Inverse Fourier transform 3D array from real to reciprocal space the - origin of real and reciprocal space is expected to be the central - voxel.""" + """Inverse Fourier transform 3D array from real to reciprocal + space the origin of real and reciprocal space is expected to be + the central voxel.""" if not self.cutoff.get(): self.cube_real = self.cube self.cube = self.cube_reci @@ -562,8 +564,8 @@ def applycutoff(self): self.intensity_upd_global() def redocutuff(self): - """Redo the cutoff operation depending on the current space (real or - reciprocal).""" + """Redo the cutoff operation depending on the current space + (real or reciprocal).""" if self.space.get(): # in real space self.cube_realcut = self.cube if not self.transformed: @@ -588,8 +590,8 @@ def newcutoff(self): self.applycutoff() def plot_next_plane(self): - """Plot the next plane in the dataset, looping back to the first if at - the end.""" + """Plot the next plane in the dataset, looping back to the first + if at the end.""" n = self.plane_num.get() if n == len(self.cube[self.axis.get()]) - 1: n = 0 @@ -616,7 +618,8 @@ def animation(self): self.plot_next_plane() def multiple_funcs(*funcs): - """Executes multiple functions passed as arguments in sequence.""" + """Executes multiple functions passed as arguments in + sequence.""" for func in funcs: func diff --git a/src/diffpy/fourigui/functions.py b/src/diffpy/fourigui/functions.py new file mode 100644 index 0000000..e7e2c8e --- /dev/null +++ b/src/diffpy/fourigui/functions.py @@ -0,0 +1,31 @@ +import numpy as np + + +def dot_product(a, b): + """Compute the dot product of two vectors of any size. + + Ensure that the inputs, a and b, are of the same size. + The supported types are "array_like" objects, which can + be converted to a NumPy array. Examples include lists and tuples. + + Parameters + ---------- + a : array_like + The first input vector. + b : array_like + The second input vector. + + Returns + ------- + float + The dot product of the two vectors. + + Examples + -------- + Compute the dot product of two lists: + >>> a = [1, 2, 3] + >>> b = [4, 5, 6] + >>> dot_product(a, b) + 32.0 + """ + return float(np.dot(a, b)) diff --git a/src/diffpy/fourigui/version.py b/src/diffpy/fourigui/version.py index f52dcaa..7dc6ccb 100644 --- a/src/diffpy/fourigui/version.py +++ b/src/diffpy/fourigui/version.py @@ -4,10 +4,10 @@ # (c) 2022-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Billinge Group members and community contributors. +# File coded by: Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. -# https://github.com/diffpy/diffpy.fourigui/graphs/contributors +# https://github.com/diffpy/diffpy.fourigui/graphs/contributors # noqa: E501 # # See LICENSE.rst for license information. # diff --git a/tests/test_functions.py b/tests/test_functions.py new file mode 100644 index 0000000..a0d9774 --- /dev/null +++ b/tests/test_functions.py @@ -0,0 +1,40 @@ +import numpy as np +import pytest + +from diffpy.fourigui import functions # noqa + + +def test_dot_product_2D_list(): + a = [1, 2] + b = [3, 4] + expected = 11.0 + actual = functions.dot_product(a, b) + assert actual == expected + + +def test_dot_product_3D_list(): + a = [1, 2, 3] + b = [4, 5, 6] + expected = 32.0 + actual = functions.dot_product(a, b) + assert actual == expected + + +@pytest.mark.parametrize( + "a, b, expected", + [ + # Test whether the dot product function works with 2D and 3D vectors + # C1: lists, expect correct float output + ([1, 2], [3, 4], 11.0), + ([1, 2, 3], [4, 5, 6], 32.0), + # C2: tuples, expect correct float output + ((1, 2), (3, 4), 11.0), + ((1, 2, 3), (4, 5, 6), 32.0), + # C3: numpy arrays, expect correct float output + (np.array([1, 2]), np.array([3, 4]), 11.0), + (np.array([1, 2, 3]), np.array([4, 5, 6]), 32.0), + ], +) +def test_dot_product(a, b, expected): + actual = functions.dot_product(a, b) + assert actual == expected diff --git a/tests/test_version.py b/tests/test_version.py index 32b5ed4..2954e80 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,6 +1,6 @@ """Unit tests for __version__.py.""" -import diffpy.fourigui +import diffpy.fourigui # noqa def test_package_version():