Skip to main content

No project description provided

Project description

spdist: Simple metrics for comparing the distance between two curves.

spdist is a simple metrics for comparing the distance between two given curves. The curves can be passed in as a numpy array with discrete values. It will interpolate between the values and calculate the minimum distance between each points in the curve and reference curve.

pip install spdist

How to use.

Currently spdist has only one function spdist.

import spdist
import numpy as np

x = np.linspace(0, 10, 100)
y = 2*x

x_ref = x
y_ref = 2*x + 1

distance = spdist.spdist(x,y,x_ref,y_ref)

print(f"{distance}")

Example plot

Following example plot a straight line $y = 2x$ and a line with a constant offset. The distance between the two lines is calculated using the spdist function. The normal vector is calculated as $(2/\sqrt{5}, -1/\sqrt{5})$. Normal vector scaled by the distance is plot green line.

test

Algorithm

The algorithm of the caculation is somewhat brute force and the time complexity is $O(n^2)$. The algorithm is as follows:

distance = 0

for i in zip(x,y):

  tmp_distance = 0
  for j in zip(x_ref, y_ref):
    if (x_ref == x_ref_next) and (y_ref == y_ref_next):
        # point to point distance
        tmp_distance = min(tmp_distance, ((x - x_ref)**2 + (y - y_ref)**2)**0.5)
        continue
    # point to line distance
    # https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Line_defined_by_two_points
    tmp_distance = min(tmp_distance, ((x_ref_next - x_ref) * (y_ref - y) - (x_ref - x) * (y_ref_next - y_ref)) / ((x_ref_next - x_ref)**2 + (y_ref_next - y_ref)**2)**0.5)

  distance += tmp_distance

distance /= len(x)

Although the algorithm itself is not optimized, the whole library is written in Rust Rust with parallel processing. (Thanks to Rust's borrow checker and rayon rayon, which is both great work.) Therefore, the calculation is fast enough.

Where to use

This library was originally developed to calculate the distance between the measured spectra and the reference spectra of XAS. The metrics is useful to quantify and capture the features of the spectra.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spdist-0.1.1.tar.gz (94.9 kB view hashes)

Uploaded Source

Built Distributions

spdist-0.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

spdist-0.1.1-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

spdist-0.1.1-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

spdist-0.1.1-pp310-pypy310_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686

spdist-0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

spdist-0.1.1-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

spdist-0.1.1-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

spdist-0.1.1-pp39-pypy39_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686

spdist-0.1.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

spdist-0.1.1-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

spdist-0.1.1-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

spdist-0.1.1-pp38-pypy38_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686

spdist-0.1.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ s390x

spdist-0.1.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

spdist-0.1.1-cp312-none-win_amd64.whl (157.9 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

spdist-0.1.1-cp312-none-win32.whl (151.6 kB view hashes)

Uploaded CPython 3.12 Windows x86

spdist-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

spdist-0.1.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

spdist-0.1.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

spdist-0.1.1-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.12+ i686

spdist-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (305.1 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

spdist-0.1.1-cp312-cp312-macosx_10_12_x86_64.whl (304.3 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

spdist-0.1.1-cp311-none-win_amd64.whl (159.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

spdist-0.1.1-cp311-none-win32.whl (153.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

spdist-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

spdist-0.1.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

spdist-0.1.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

spdist-0.1.1-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.12+ i686

spdist-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (304.8 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

spdist-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl (304.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

spdist-0.1.1-cp310-none-win_amd64.whl (159.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

spdist-0.1.1-cp310-none-win32.whl (153.9 kB view hashes)

Uploaded CPython 3.10 Windows x86

spdist-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

spdist-0.1.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

spdist-0.1.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

spdist-0.1.1-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686

spdist-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (304.8 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

spdist-0.1.1-cp310-cp310-macosx_10_12_x86_64.whl (304.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

spdist-0.1.1-cp39-none-win_amd64.whl (159.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

spdist-0.1.1-cp39-none-win32.whl (154.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

spdist-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

spdist-0.1.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

spdist-0.1.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

spdist-0.1.1-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

spdist-0.1.1-cp38-none-win_amd64.whl (159.3 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

spdist-0.1.1-cp38-none-win32.whl (153.9 kB view hashes)

Uploaded CPython 3.8 Windows x86

spdist-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

spdist-0.1.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

spdist-0.1.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

spdist-0.1.1-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

spdist-0.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

spdist-0.1.1-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page