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.8.2
  • scipy 0.13.3

These python, numpy and scipy versions were available on the Ubuntu 14.04 Linux release at the time of testing. The package has been informally tested with python 3.4 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 2.4.4. 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.

Filename, size & hash SHA256 hash help File type Python version Upload date
Scikit_Qfit-0.1.4-py2.py3-none-any.whl (19.1 kB) Copy SHA256 hash SHA256 Wheel py2.py3
Scikit-Qfit-0.1.4.tar.gz (2.4 MB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page