Skip to main content

Kernels for continuous data transformations.

Project description

Polare

Polare is a computation tool that provides a continuous representation of input data, referred to as a Stroke, which doubles as an algebraic node for computations. A set of discrete data can be stored in the Stroke object and operated on as if it was a continuous function; the altered Stroke can then be evaluated within its input domain.

Why is Polare Useful?

In computation workflows, data can be interpolated after initial processing. Although, in cases where the post-transformation data is vastly more irregular than input data, it can be challenging to capture the actual data behaviour through interpolating the transformed data. In such cases, interpolating the input data before applying the transformations is desirable to capture the behaviour of the underlying data. By design, Strokes take advantage of pre-interpolation without the need first to decide where to interpolate.

The ability to decide interpolation points after the fact can be helpful in many applications. For example, in root-finding algorithms, it is necessary to be able to interpolate at any arbitrary point within the input domain without knowing the root of the data previously.

In short, if interpolation of irregular transformed data is desired, a more robust and representative interpolation can be achieved by performing the conversion using a Stroke rather than post interpolation.

Design Focus

The design focus of Polare was for seamless integration into NumPy intensive workflows. As a result, Strokes are compatible with most NumPy universal functions. Currently, NumPy functions that depend on a scalar input (e.g. np.cos, np.radians, etc.) only work on single Stroke objects whereas NumPy functions that necessitate array inputs (e.g. np.sum, np.dot, etc), are supported. Additionally, the program supports many Python operands for Stroke-to-Stroke and Stroke-to-scalar operations.

Quick Start Guide

Firstly, we can use a Stroke for interpolation!

from polare import Stroke
import numpy as np

# Generate data.
x = np.linspace(-1, 1, 10)
y = np.exp(x) + np.cos(np.pi * x) + 1

# Instantiate Stroke object.
f = Stroke(x=x, y=y, kind="cubic")

# Interpolate.
xnew = np.linspace(-1, 1, 100)
ynew = f(xnew)

Strokes can be operated on using standard Python operators, unlike other interpolation objects.

# We can shift the Stroke through addition/subtraction.
f = f + 10

# We can scale the Stroke through multiplication/division.
f = 5 * f

# And then interpolate the final result...
y_new = f(x_new)

Strokes are compatible with many NumPy universal functions allowing for simple integration into NumPy intensive workflows.

For the following NumPy-focused examples, we will use the proceeding variable definitions:

t = np.linspace(0, 10, 100)

x1 = Stroke(t, x1_data, kind="cubic")
y1 = Stroke(t, y1_data, kind="cubic")
z1 = Stroke(t, z1_data, kind="cubic")

x2 = Stroke(t, x1_data, kind="cubic")
y2 = Stroke(t, y1_data, kind="cubic")
z2 = Stroke(t, z1_data, kind="cubic")

where x1,y1,z1 and x2,y2,z2 represent coordinate points in 3D space. We can then form NumPy vectors:

v1 = np.array([x1, y1, z1])
v2 = np.array([x2, y2, z2])

Using standard NumPy techniques, we can get a continuous/interpolable representation of expected results. For example, we can get a continuous/interpolable representation of the norm of our vectors with time:

norm1 = np.linalg.norm(v1)
norm2 = np.linalge.norm(v2)

# Interpolate norms.
t_new = np.linspace(5, 6, 100)
norm1_new = norm1(t_new)
norm2_new = norm2(t_new)

Or we could get a continuous/interpolable representation of the vector dot product with time:

dot12 = np.dot(v1, v2)

# Interpolate inner product.
t_new = np.linspace(5, 6, 100)
dot12_new = dot12(t_new)

Combining these results, we can get a continuous/interpolable time-series of the angle between our two vectors:

theta12_rad = np.arccos(dot12 / (norm1 * norm2))
theta12_deg = np.degrees(theta12_rad)

# Interpolate angles.
t_new = np.linspace(5, 6, 100)
theta12_rad_new = theta12_rad(t_new)
theta12_deg_new = theta12_deg(t_new)

An example of another helpful data operation is matrix-vector multiplication. To rotate our vector, v1, about the z-axis by a time-evolving angle, theta12_rad, we can use the 3rd principal axis rotation:

# Construct rotation matrix and rotate position vector.
c3 = np.array([[np.cos(theta12_rad), -np.sin(theta12_rad), 0],
               [np.sin(theta12_rad), np.cos(theta12_rad),  0],
               [0,                   0,                    1]])
new_pos = np.matmul(c3, v1)

# Interpolate new (rotated) positions.
t_new = np.linspace(0, 9, 100)
x1_new = new_pos[0](t_new)
y1_new = new_pos[1](t_new)
z1_new = new_pos[2](t_new)

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

polare-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

polare-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file polare-0.1.0.tar.gz.

File metadata

  • Download URL: polare-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for polare-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b9fa031df2683d220ec7ca31c3b9a9eb2c347b9a20c92ca6cbcb9d112969044a
MD5 54804bf24dec9cbde521d4718be4ceff
BLAKE2b-256 77bbcc4c0a90de864239ec6c19d0415cf757165dbe759e7cd5455858fa007672

See more details on using hashes here.

File details

Details for the file polare-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: polare-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for polare-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba84bf29180ade6437c32d7431b87038755358d2326f1ce234a48fe9df152075
MD5 26a92e126617c04af3526acce582b81d
BLAKE2b-256 bd479cc7ea335a72567d1f8ab105e64e1eccdacaa83d6402d48848a12eb5dddf

See more details on using hashes here.

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