diff --git a/ktch/outline/_elliptic_Fourier_analysis.py b/ktch/outline/_elliptic_Fourier_analysis.py index e4bd099..143b356 100644 --- a/ktch/outline/_elliptic_Fourier_analysis.py +++ b/ktch/outline/_elliptic_Fourier_analysis.py @@ -330,7 +330,7 @@ def _transform_single( return X_transformed - def _normalize(self, an, bn, cn, dn): + def _normalize(self, an, bn, cn, dn, keep_start_point=False): """Normalize Fourier coefficients. Todo: @@ -343,18 +343,29 @@ def _normalize(self, an, bn, cn, dn): c1 = cn[1] d1 = dn[1] - theta = (1 / 2) * np.arctan2( - 2 * (a1 * b1 + c1 * d1), (a1**2 + c1**2 - b1**2 - d1**2) + theta = (1 / 2) * np.arctan( + 2 * (a1 * b1 + c1 * d1) / (a1**2 + c1**2 - b1**2 - d1**2) ) - if theta < 0: - theta = theta + 2 * np.pi + + [[a_s, b_s], [c_s, d_s]] = np.array([[a1, b1], [c1, d1]]).dot( + rotation_matrix_2d(theta) + ) + s1 = a_s**2 + c_s**2 + s2 = b_s**2 + d_s**2 + + if s1 < s2: + if theta < 0: + theta = theta + np.pi / 2 + else: + theta = theta - np.pi / 2 a_s = a1 * np.cos(theta) + b1 * np.sin(theta) c_s = c1 * np.cos(theta) + d1 * np.sin(theta) scale = np.sqrt(a_s**2 + c_s**2) psi = np.arctan2(c_s, a_s) - if psi < 0: - psi = psi + 2 * np.pi + + if keep_start_point: + theta = 0 coef_norm_list = [] r_psi = rotation_matrix_2d(-psi) diff --git a/pyproject.toml b/pyproject.toml index 8f4a951..0249461 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ version = "0.3.1" [tool.poetry.dependencies] numpy = ">=1.22" pandas = ">=1.5" -python = "^3.8" +python = "^3.9" scikit-learn = ">=1.2" scipy = ">=1.8" toml = ">=0.10" @@ -48,20 +48,20 @@ jupyter = "^1.0.0" jupyterlab = "^3.4.4" jupytext = "^1.14.5" liccheck = "^0.7.2" -llvmlite = "^0.39.1" -matplotlib = "^3.5.2" +llvmlite = "^0.41" module-name = "^0.6.0" -numba = "^0.56.4" +numba = "^0.58" opencv-python = "^4.7.0.68" plotly = "^5.9.0" poetry2conda = "^0.3.0" pytest = "^7.1" pytest-cov = "^3.0" -seaborn = "^0.11.0" setuptools = "<60.0" tqdm = "^4.64.1" tslearn = "^0.5.3.2" xarray = "^2022.6.0" +matplotlib = "^3.8.2" +seaborn = "^0.13.0" [tool.poetry.group.doc.dependencies] myst-nb = "^0.17.2"