Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maint: update curvesimilarities to v0.1.3 #288

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"scipy",
"numba",
"shapely >= 2.0",
"curvesimilarities >= 0.1.1",
"curvesimilarities >= 0.1.3",
"PyYAML",
"tqdm",
]
Expand All @@ -56,7 +56,7 @@ test = [
doc = [
"furo",
"sphinx",
"sphinx-autoapi != 3.1.0",
"sphinx-autoapi < 3.1.0",
"sphinx-tabs >= 3.4.5",
"matplotlib",
]
Expand Down
26 changes: 10 additions & 16 deletions src/finitedepth/coatinglayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import cv2
import numpy as np
import numpy.typing as npt
from curvesimilarities import dtw_acm, dtw_owp # type: ignore
from curvesimilarities import dtw_owp, sdtw_owp # type: ignore
from scipy.interpolate import splev, splprep # type: ignore
from scipy.optimize import root # type: ignore
from scipy.spatial.distance import cdist # type: ignore
Expand Down Expand Up @@ -607,13 +607,11 @@ def conformality(self) -> tuple[float, npt.NDArray[np.int32]]:
I0, I1 = self.surface()
surf = self.contour()[I0:I1]

dist = cdist(np.squeeze(surf, axis=1), np.squeeze(intf, axis=1))
mat = dtw_acm(dist)
path = dtw_owp(mat)
d = dist[path[:, 0], path[:, 1]]
d_avrg = mat[-1, -1] / len(path)
C = 1 - np.sum(np.abs(d - d_avrg)) / mat[-1, -1]
pairs = np.concatenate([surf[path[..., 0]], intf[path[..., 1]]], axis=1)
dtw, p = dtw_owp(np.squeeze(surf, axis=1), np.squeeze(intf, axis=1))
dtw_avrg = dtw / len(p)
d = cdist(np.squeeze(surf, axis=1), np.squeeze(intf, axis=1))[p[:, 0], p[:, 1]]
C = 1 - np.sum(np.abs(d - dtw_avrg)) / dtw
pairs = np.concatenate([surf[p[..., 0]], intf[p[..., 1]]], axis=1)
return (float(C), pairs)

@attrcache("_roughness")
Expand All @@ -634,17 +632,13 @@ def roughness(self) -> tuple[float, npt.NDArray[np.float64]]:
ul_len = cv2.arcLength(ul.astype(np.float32), closed=False)
if self.roughness_measure == "DTW":
ul = sample_polyline(ul, int(np.ceil(ul_len)))
dist = cdist(np.squeeze(surf, axis=1), np.squeeze(ul, axis=1))
mat = dtw_acm(dist)
path = dtw_owp(mat)
roughness = mat[-1, -1] / len(path)
dtw, path = dtw_owp(np.squeeze(surf, axis=1), np.squeeze(ul, axis=1))
roughness = dtw / len(path)
pairs = np.concatenate([surf[path[..., 0]], ul[path[..., 1]]], axis=1)
elif self.roughness_measure == "SDTW":
ul = sample_polyline(ul, int(np.ceil(ul_len)))
dist = cdist(np.squeeze(surf, axis=1), np.squeeze(ul, axis=1))
mat = dtw_acm(dist**2)
path = dtw_owp(mat)
roughness = np.sqrt(mat[-1, -1] / len(path))
sdtw, path = sdtw_owp(np.squeeze(surf, axis=1), np.squeeze(ul, axis=1))
roughness = np.sqrt(sdtw / len(path))
pairs = np.concatenate([surf[path[..., 0]], ul[path[..., 1]]], axis=1)
else:
roughness = np.nan
Expand Down
Loading