Skip to main content

Numba accelerated coherent structure package.

Project description

NumbaCS

Documentation: https://numbacs.readthedocs.io/

Source Code (MPL-2.0): https://github.com/alb3rtjarvis/numbacs

NumbaCS (Numba Coherent Structures) is a Python package for performing coherent structure analysis in a user-friendly and efficient manner. It implements methods referred to as "coherent structure methods", an umbrella term for any method that can be used to infer or extract Lagrangian and Eulerian coherent structures. These are tools for performing analysis of time-dependent dynamical systems, mainly with a focus on material transport in fluid flows. While this package can be used with any (incompressible) flow, methods are provided which make it simple for the user to take advantage of these tools for large-scale geophysical flows.

Features

NumbaCS currently implements the following features:

Diagnostics:

  • FTLE -- finite time Lyapunov exponent
  • iLE -- instantaneous Lyapunov exponent
  • LAVD -- Lagrangian averaged vorticity deviation
  • IVD -- instantaneous vorticity deviation

Feature extraction:

  • LCS -- hyperbolic and elliptic Lagrangian coherent structures
  • OECS -- hyperbolic and elliptic objective Eulerian coherent structures
  • Ridge extraction -- FTLE and iLE ridge extraction

Installation

Conda:

conda install -c conda-forge numbacs

Pip:

python -m pip install numbacs

NOTE: It is strongly recommended to use conda for installation due to some reported issues when using pip for one of the dependencies.

Basic usage

Predefined flow

import numpy as np
from math import copysign
from numbacs.flows import get_predefined_flow
from numbacs.integration import flowmap_grid_2D
from numbacs.diagnostics import ftle_grid_2D

# set integration span and integration direction
t0 = 0.
T = -10.
int_direction = copysign(1, T)

# get ode to be used by 'flowmap_grid_2D'
funcptr, params, domain = get_predefined_flow('double_gyre', int_direction = int_direction)

# set up domain
nx,ny = 401,201
x = np.linspace(domain[0][0], domain[0][1], nx)
y = np.linspace(domain[1][0], domain[1][1], ny)
dx = abs(x[1] - x[0])
dy = abs(y[1] - y[0])

# computes final position of particle trajectories over grid
flowmap = flowmap_grid_2D(funcptr, t0, T, x, y, params)

# compute FTLE over grid
ftle = ftle_grid_2D(flowmap, T, dx, dy)

Numerical velocity data

import numpy as np
from math import copysign
from numbacs.flows import get_interp_arrays_2D, get_flow_2D
from numbacs.integration import flowmap_grid_2D
from numbacs.diagnostics import ftle_grid_2D

# given you have data in current directory,
# load data, set integration span and direction
t = np.load('./t.npy')
x = np.load('./x.npy')
y = np.load('./y.npy')
U = np.load('./u.npy')
V = np.load('./v.npy')
dx = abs(x[1] - x[0])
dy = abs(y[1] - y[0])
t0 = 0.
T = -10.
params = np.array([copysign(1, T)])

# get ode to be used by 'flowmap_grid_2D'
grid_vel, C_eval_u, C_eval_v = get_interp_arrays_2D(t, x, y, U, V)
funcptr = get_flow_2D(grid_vel, C_eval_u, C_eval_v)

# computes final position of particle trajectories over grid
flowmap = flowmap_grid_2D(funcptr, t0, T, x, y, params)

# compute FTLE over grid
ftle = ftle_grid_2D(flowmap, T, dx, dy)

Key dependencies

NumbaCS is built on top of three main packages: Numba, numbalsoda, and interpolation. Numba is a JIT-compiler for Python array and numerical functions that generates optimized machine code just-in-time (using the LLVM compiler library) to significantly speed up numerical operations in Python. Numbalsoda is a Python wrapper to ODE solvers in both C++ (LSODA) and FORTRAN (DOP853) that is compatible with Numba (standard Python ODE solvers cannot be used within Numba functions) and bypasses the Python interpreter, speeding up the most computationally expensive piece of Lagrangian coherent structure methods, particle integration. The interpolation package is a Numba-compatible package which optimizes interpolation in Python. It is used in NumbaCS to generate JIT-compiled interpolant functions of numerical velocity fields which can be fed into solvers from the numbalsoda package, resulting in efficient particle integration for flows defined by numerical velocity data. All of this interfacing, which is done behind the scenes through modules the user can call in a straightforward manner, is how NumbaCS achieves impressive speeds while maintaining a relatively simple user experience. We are grateful to the creators, maintainers, and contributors of each of these packages, as well as the other dependencies which NumbaCS relies on (NumPy, SciPy, and ContourPy).

Roadmap

Future releases aim to extend certain methods to higher dimensions, implement new features that should be straightforward within this framework (shape coherent sets, lobe dynamics, etc.), and further streamline and optimize the process for large-scale geophysical applications.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate. See the Contributing Guide for more details.

Similar software

Lagrangian -- Python package for computing FSLE, FTLE, and eigenvectors of Cauchy-Green tensor with a focus on geophysical flows. Largely written in C++ with pybind11 used for binding, resulting in fast runtimes. Particle integration is performed by 4th order Runge-Kutta method (RK4).

Dynlab -- Object oriented Python package which computes Lagrangian and Eulerian diagnostics along with ridge extraction. Provides a large collection of predefined flows and is very user friendly. Particle integration performed by scipy.integrate.odeint (LSODA).

TBarrier -- Collection of Jupyter notebooks accompanying the book Transport Barriers and Coherent Structures in Flow Data -- Advective, Diffusive, Stochastic, and Active methods by George Haller. Python code which implements a variety of Lagrangian and Eulerian diagnostics and extraction methods for a variety of different transport settings (NumbaCS currently only implements purely advective methods). Particle integration performed by 4th order Runge-Kutta method (RK4).

Newman -- Fast C++ code for computing FTLE which works with geophysical flows and storm tracking. Various methods for particle integration, both fixed and adaptive step-size methods. No longer maintained.

Aquila-LCS -- Python code designed to compute FTLE for high-speed turbulent boundary layers in 3D. Utilizes Numba to implement GPU and CPU versions of the code for fast runtimes. Particle integration performed by Euler method.

CoherentStructures.jl -- Julia toolbox for computing LCS/FTCS in aperiodic flows. Implements elliptic LCS methods, FEM-based methods (FEM approximation of dynamic Laplacian for FTCS extraction), and Graph Laplacian-based methods (spectral clustering and diffusion maps for coherent sets). Makes use of DifferentialEquations.jl for particle integration, a very advanced and efficient suite of DE solvers in Julia.

LCS Tool MATLAB code used to compute Elliptic LCS, Hyperbolic LCS, and FTLE. Particle integration performed by MATLAB's ode45 function (based off of RK5(4) due to Dormand and Prince).

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

numbacs-0.1.1.tar.gz (116.4 kB view details)

Uploaded Source

Built Distribution

numbacs-0.1.1-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file numbacs-0.1.1.tar.gz.

File metadata

  • Download URL: numbacs-0.1.1.tar.gz
  • Upload date:
  • Size: 116.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for numbacs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e8b84cc10991a160ae476163fd91466144492d651bbca3cd9e8eafc1bcdccb8a
MD5 77aae1157570bdf72fbbc6e958b59684
BLAKE2b-256 c3ab3aac30b87fe1f1b4edf3e73f0579623915c3b31f264fe4edaacf66fa8066

See more details on using hashes here.

File details

Details for the file numbacs-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: numbacs-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 43.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for numbacs-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 affb17edec8a1792451f77eac0a0da863e93023c00693fcee01b53e704f0e760
MD5 307fc326bd717389c90c361ec9945b52
BLAKE2b-256 d9370ff9f59e69fdf583982dd859cec984a3b2a826e93c4e40b24a5d0c130011

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