Skip to main content

Fit gradient orthogonal Q-polynomials to 2D data

Project description

Scikit-Qfit is a package that supports fitting gradient orthogonal Q-polynomials to 2D data.


This package implements the algorithm described in:

Additional project documentation and references for Q- freeform polynomials can be found at:


The package can be installed through pip:

> pip install scikit-qfit


To generate a Q-freeform spectrum from a data map, pass the coordinate arrays x and y and 2-D array of data with shape (x.size,y.size) as arguments to the method qspec(). The azimuthal and radial spectrum limits are set by m_max and n_max respectively.

>>> import skqfit.qspectre as qf
>>> ...
>>> qspec = qf.qspec(x, y, zmap, m_max=500, n_max=500)

To observe the contribution of spectrum components it is necessary to use the sine and cosine elements in the forward processing step. After modifying the spectrum, an inverse process creates a data map along with the x and y derivatives.

>>> qs = qf.QSpectrum()
>>> qs.data_map(x, y, zmap)
>>> a_nm, b_nm = qs.q_fit(mmax, nmax)
>>> ... # modify spectrum
>>> nmap, dfdx, dfdy = qs.build_map(x, y, a_nm, b_nm, inc_deriv=True)

A 1D trace across the fitted data can also be generated by passing a set of xv, yv arrays that represent the (x, y) coordinates.

>>> zv, dfdx, dfdy = qs.build_profile(xv, yv, a_nm, b_nm, inc_deriv=True)


The Jacobian polynomial calculation required by the algorithm can generate very large numbers which limits spectral resolution to a maximum of 1500 for the radial and azimuthal terms (n, m). Using values greater than this can lead to an overflow. If the nominal spectral resolution for a datamap is greater than this limit the data should be filtered prior to processing to avoid aliasing.

Note that the process is an N^2 algorithm, so doubling the number of radial and azimuthal terms takes four times as long.


The package requires numpy and scipy and was tested on Linux with:

  • Python 2.7.6
  • numpy 1.14.5
  • scipy 1.0.0

These python, numpy and scipy versions were available on the Ubuntu 18.04 Linux release at the time of testing. The package has been informally tested with python 3.6 successfully and I am not aware of reason it should not work with later releases of these packages.


  • Greg Forbes for support with the implementation and validation of the algorithm.
  • Andreas Beutler, Mahr GmbH, for choosing to make this work available as open source.


This project has been set up using PyScaffold 3.2.1. For details and usage information on PyScaffold see

Project details

Download files

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

Files for Scikit-Qfit, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size Scikit_Qfit-0.1.5-py2.py3-none-any.whl (18.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size Scikit-Qfit-0.1.5.tar.gz (2.4 MB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page