Skip to main content

Fast expansion into harmonics on the disk

Project description

fle_2d

Installing in conda environment

conda create --name fle python=3.9 pip
conda activate fle
conda install -c conda-forge pip numpy scipy joblib matplotlib finufft
pip install fle-2d

Installing using pip

pip install numpy scipy joblib matplotlib finufft fle-2d

Testing install

git clone https://github.com/nmarshallf/fle_2d.git
# Or download folder and unzip
cd fle_2d/tests/
python3 test_fle_2d.py 

If you find the code useful, please cite the corresponding paper:

Nicholas F. Marshall, Oscar Mickelin, and Amit Singer. Fast expansion into harmonics on the disk: A steerable basis with fast radial convolutions. SIAM Journal on Scientific Computing, 45(5):A2431–A2457, 2023.

@article{marshall2023fast,
  author = {Marshall, Nicholas F. and Mickelin, Oscar and Singer, Amit},
  title = {Fast Expansion into Harmonics on the Disk: A Steerable Basis with Fast Radial Convolutions},
  journal = {SIAM Journal on Scientific Computing},
  volume = {45},
  number = {5},
  pages = {A2431-A2457},
  year = {2023},
  doi = {10.1137/22M1542775},
}

Acknowledgements

We thank Yunpeng Shi for contributing a vectorized version of the code for tensor inputs consisting of multiples images.

Usage

Given an image represented by a 2D array of size LxL that you want to expand into the disk harmonic basis, first create a basis object by calling

from fle_2d import FLEBasis2D
L = 128         #replace this by the side-length of your image
bandlimit = L   #maximum number of basis functions to use
eps = 1e-7      #desired accuracy
fle = FLEBasis2D(L, bandlimit, eps)

Here, eps is the accuracy desired in applying the basis expansion, corresponding to the epsilon in Theorem 4.1 in the paper. "Bandlimit" is a parameter that determines how many basis functions to use and corresponds to the variable lambda in equation (5.1) in the paper, scaled so that L is the maximum suggested.

All arguments to FLEBasis2D:

  • L: size of image to be expanded

  • bandlimit: bandlimit parameter (scaled so that L is max suggested)

  • eps: requested relative precision

  • expand_eps: requested approximate relative precision in the expand method (if not specified, pre-tuned values are used)

  • expand_alpha: requested step-size in the expand method (if not specified, pre-tuned values are used)

  • expand_rel_tol: requested relative tolerance in the expand method (if not specified, pre-tuned values are used)

  • maxitr: maximum number of iterations for the expand method (if not specified, pre-tuned values are used)

  • maxfun: maximum number of basis functions to use (if not specified, which is the default, the number implied by the choice of bandlimit is used)

  • mode: choose either "real" or "complex" (default) output, using either real-valued or complex-valued basis functions

  • precision: choose either "double" or "single"

To go from the image to the basis coefficients, you would then call either

coeff = fle.evaluate_t(image)

which applies the operator $\tilde{B}^*$ in Theorem 4.1 of the paper, or

coeff = fle.expand(image)

which solves a least squares problem instead of just applying equation $\tilde{B}^*$ once. The latter can be more accurate, but takes a bit longer since it applies evaluate_t maxitr times using conjugate-gradient (Richardson iteration is also implemented).

Once you have coefficients coeff in the basis, you can evaluate the corresponding function with expansion coefficients coeff on the LxL grid by running

image = fle.evaluate(coeff)

which corresponds to applying the operator $\tilde{B}$ in Theorem 4.1 in the paper.

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

fle_2d-0.1.2.tar.gz (54.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fle_2d-0.1.2-py3-none-any.whl (54.9 MB view details)

Uploaded Python 3

File details

Details for the file fle_2d-0.1.2.tar.gz.

File metadata

  • Download URL: fle_2d-0.1.2.tar.gz
  • Upload date:
  • Size: 54.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for fle_2d-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2cb369ea8dff6eee8e5e9f5737b85cbc20c0e9095375af16ef408fcaad5d8b30
MD5 2b54427a514e8db656318e63bf167db2
BLAKE2b-256 3a3c221ec1f89243bf9e9c035a19c9a2efbf90fb0314792af7232070f8e8b8cf

See more details on using hashes here.

File details

Details for the file fle_2d-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fle_2d-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 54.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for fle_2d-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c283eefcc26a05e65c59711e292804b691593804cc6cc12c6836372a8d41fbb
MD5 25d91aa805281165f84198a9d35a18e6
BLAKE2b-256 a3e4a01c8768af16b70f74df322d84f29f06104570a56360c4aa42fcee84d6a0

See more details on using hashes here.

Supported by

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