From 080fc8f9cc494e87fe0540dfe4e7601a07c191a1 Mon Sep 17 00:00:00 2001 From: tinatn29 Date: Tue, 17 Jun 2025 16:05:17 -0400 Subject: [PATCH 1/8] skpkg: mirate src folder --- src/diffpy/__init__.py | 10 +--------- src/diffpy/fourigui/__init__.py | 6 +++--- src/diffpy/fourigui/functions.py | 31 +++++++++++++++++++++++++++++++ src/diffpy/fourigui/version.py | 6 +++--- 4 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 src/diffpy/fourigui/functions.py diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index 1df0753..794e198 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2022-2025 The Trustees of Columbia University in the City of New York. +# (c) 2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # # File coded by: Billinge Group members and community contributors. @@ -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..c36c5ea 100644 --- a/src/diffpy/fourigui/__init__.py +++ b/src/diffpy/fourigui/__init__.py @@ -1,10 +1,10 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2022-2025 The Trustees of Columbia University in the City of New York. +# (c) 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/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..56d6490 100644 --- a/src/diffpy/fourigui/version.py +++ b/src/diffpy/fourigui/version.py @@ -1,13 +1,13 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2022-2025 The Trustees of Columbia University in the City of New York. +# (c) 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. # From 20f3744b43dc7745afa5267868c7500c03c48d83 Mon Sep 17 00:00:00 2001 From: tinatn29 Date: Tue, 17 Jun 2025 16:05:31 -0400 Subject: [PATCH 2/8] skpkg: migrate tests folder --- tests/test_functions.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_version.py | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/test_functions.py 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(): From 94b2c151c3f3a98e490ceb8f9658df72830a2428 Mon Sep 17 00:00:00 2001 From: tinatn29 Date: Tue, 17 Jun 2025 16:10:24 -0400 Subject: [PATCH 3/8] skpkg: list dependencies in requirements folder --- requirements/build.txt | 0 requirements/docs.txt | 1 + 2 files changed, 1 insertion(+) delete mode 100644 requirements/build.txt 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 From 21a9d1abffd137f92ea25565105406ae5fc3c10c Mon Sep 17 00:00:00 2001 From: tinatn29 Date: Tue, 17 Jun 2025 16:13:46 -0400 Subject: [PATCH 4/8] skpkg: add CI and issue/PR templates --- .github/workflows/tests-on-pr.yml | 18 ------------------ .gitignore | 1 + 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 .github/workflows/tests-on-pr.yml diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml deleted file mode 100644 index 9cb0637..0000000 --- a/.github/workflows/tests-on-pr.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Tests on PR - -on: - push: - branches: - - main - pull_request: - workflow_dispatch: - -jobs: - tests-on-pr: - uses: Billingegroup/release-scripts/.github/workflows/_tests-on-pr.yml@v0 - with: - project: diffpy.fourigui - c_extension: false - headless: true - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 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/ From f345477924f7364ec35b001f750a4a8adf13184f Mon Sep 17 00:00:00 2001 From: tinatn29 Date: Tue, 17 Jun 2025 16:15:31 -0400 Subject: [PATCH 5/8] skpkg: add pyproject.toml --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) 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?$' From ce5481f2866aa3fbc38b6cd940fcda36ead71297 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Jun 2025 20:17:42 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit hooks --- src/diffpy/fourigui/fourigui.py | 37 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) 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 From 97248413e68d98108bd02018cd2e76f37cdfb962 Mon Sep 17 00:00:00 2001 From: tinatn29 Date: Wed, 18 Jun 2025 10:54:35 -0400 Subject: [PATCH 7/8] edit date range --- src/diffpy/__init__.py | 2 +- src/diffpy/fourigui/__init__.py | 2 +- src/diffpy/fourigui/version.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index 794e198..2b9a97b 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (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. diff --git a/src/diffpy/fourigui/__init__.py b/src/diffpy/fourigui/__init__.py index c36c5ea..cf795f7 100644 --- a/src/diffpy/fourigui/__init__.py +++ b/src/diffpy/fourigui/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2022-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # # File coded by: Billinge Group members. diff --git a/src/diffpy/fourigui/version.py b/src/diffpy/fourigui/version.py index 56d6490..7dc6ccb 100644 --- a/src/diffpy/fourigui/version.py +++ b/src/diffpy/fourigui/version.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2022-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # # File coded by: Billinge Group members. From a99fd8653ea8c9c4b5a2e35b50028147a5584a0a Mon Sep 17 00:00:00 2001 From: tinatn29 Date: Wed, 18 Jun 2025 11:10:51 -0400 Subject: [PATCH 8/8] add tests-on-pr back from main --- .github/workflows/tests-on-pr.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/tests-on-pr.yml diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml new file mode 100644 index 0000000..9cb0637 --- /dev/null +++ b/.github/workflows/tests-on-pr.yml @@ -0,0 +1,18 @@ +name: Tests on PR + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + tests-on-pr: + uses: Billingegroup/release-scripts/.github/workflows/_tests-on-pr.yml@v0 + with: + project: diffpy.fourigui + c_extension: false + headless: true + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}