From 2247e52ccfc90330f960673318385e0fbd94619c Mon Sep 17 00:00:00 2001 From: Koji Noshita Date: Sun, 10 Mar 2024 22:12:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?test:=20=F0=9F=9A=A8=20add=20tests=20for=20?= =?UTF-8?q?input/output=20shapes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/test_Procrustes_analysis.py | 28 +++++++++++++++++++ .../tests/test_elliptic_Fourier_analysis.py | 20 ++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 ktch/landmark/tests/test_Procrustes_analysis.py diff --git a/ktch/landmark/tests/test_Procrustes_analysis.py b/ktch/landmark/tests/test_Procrustes_analysis.py new file mode 100644 index 0000000..4e65814 --- /dev/null +++ b/ktch/landmark/tests/test_Procrustes_analysis.py @@ -0,0 +1,28 @@ +import numpy as np +import pytest +from numpy.testing import assert_array_almost_equal + +from ktch.datasets import load_landmark_mosquito_wings +from ktch.landmark import GeneralizedProcrustesAnalysis, centroid_size + +data_landmark_mosquito_wings = load_landmark_mosquito_wings(as_frame=True) +data_landmark_mosquito_wings.coords + +X = data_landmark_mosquito_wings.coords.to_numpy().reshape(-1, 18 * 2) + + +def test_gpa_shape(): + gpa = GeneralizedProcrustesAnalysis() + gpa.fit_transform(X) + X_transformed = gpa.fit_transform(X) + + assert X.shape == X_transformed.shape + + +@pytest.mark.parametrize("n_dim", [2, 3]) +def test_centroid_size(n_dim): + x = np.random.uniform(0, 100, (10, n_dim)) + cs_r = np.sqrt(np.sum((x - x.mean(axis=0)) ** 2)) + cs_t = centroid_size(x) + + assert_array_almost_equal(cs_r, cs_t) diff --git a/ktch/outline/tests/test_elliptic_Fourier_analysis.py b/ktch/outline/tests/test_elliptic_Fourier_analysis.py index 1f01337..3dbd9bc 100644 --- a/ktch/outline/tests/test_elliptic_Fourier_analysis.py +++ b/ktch/outline/tests/test_elliptic_Fourier_analysis.py @@ -1,13 +1,8 @@ import numpy as np - -from numpy.testing import assert_array_almost_equal import pytest +from numpy.testing import assert_array_almost_equal -from ktch.datasets import ( - load_outline_bottles, - load_coefficient_bottles, - convert_coords_df_to_list, -) +from ktch.datasets import load_coefficient_bottles, load_outline_bottles from ktch.outline import EllipticFourierAnalysis bottles = load_outline_bottles() @@ -31,6 +26,17 @@ def test_data_prep_align(): assert_array_almost_equal(x_frame, x_list) +@pytest.mark.parametrize("norm", [False, True]) +def test_efa_shape(norm): + n_harmonics = 6 + + X = bottles.coords + efa = EllipticFourierAnalysis(n_harmonics=n_harmonics) + X_transformed = efa.fit_transform(X, norm=norm) + + assert X_transformed.shape == (len(X), 4 * (n_harmonics + 1)) + + @pytest.mark.parametrize("norm", [False, True]) @pytest.mark.parametrize("set_output", [None, "pandas"]) def test_efa(norm, set_output): From b0d6150bc1f7117fffaec04c45b8293edca203b6 Mon Sep 17 00:00:00 2001 From: Koji Noshita Date: Sun, 10 Mar 2024 22:22:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?release:=20=F0=9F=9A=80=20v0.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- environment.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 4441624..2eaf011 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,7 @@ ############################################################################### # NOTE: This file has been auto-generated by poetry2conda # poetry2conda version = 0.3.0 -# date: Fri Feb 9 00:53:13 2024 +# date: Sun Mar 10 22:20:31 2024 ############################################################################### # If you want to change the contents of this file, you should probably change # the pyproject.toml file and then use poetry2conda again to update this file. diff --git a/pyproject.toml b/pyproject.toml index 39a9ca3..5a97fec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ license = "Apache-2.0" name = "ktch" readme = "README.md" repository = "https://github.com/noshita/ktch" -version = "0.3.2" +version = "0.4.0" [tool.poetry.dependencies] numpy = ">=1.22"