pyoptools.misc.Poly2D package

Module contents

class pyoptools.misc.Poly2D.poly2d

Bases: object

Class to define a 2D polynomial

z=c0+
c1*x+c2*y+
c3*x^2+c4*x*y+c5*y^2+
c6*x^3+c7*x^2*y+c8*x*y^2+c9*y^3+...

cohef
dxdy()

Function that calculates the derivative with respect to X and Y of a given polynomial represented as a matrix.

Return Value

(dx,dy)
Tuple containing the Poly2D representing de derivative with respect to X, and the Poly2D containing the derivative with respect to Y

Note: this method gets cached the first time it is called. If you modify the cohef attribute, the cache does not get updated

eval()

Evaluate the polynomial at x,y

This is the general method written in numpy. In this method x and y can have any shape (number, vectors, matrices, etc). Because of its generality, this method is not the fastest.

Parameters:
  • ========================================================= (=) –
  • Number, vector or matrix containing the values of x where (x) – the polynomial is goint to be evaluated.
  • Number, vector or matrix containing the values of y where (y) – the polynomial is goint to be evaluated.
  • =========================================================

Return Value:

This method returns the polynomial evaluated Z=P(X,Y). Z will have the same shape as X and Y

In order to increase speed, use peval to evaluate for a single point, or meval to evaluate for 2D matrices

eval_2()
gpu_eval()

Evaluate the polynomial using the GPU, x and y are vectors

This method is similar to vveval, but using the GPU

gpu_eval1()

Evaluate the polynomial between -1 and 1 using the gpu

meval()

Evaluate the polynomial at for the values given in the 2D matrices x, y.

Parameters:
  • ========================================================= (=) –
  • 2D matrix the values of x where the polynomial is going to (x) – be evaluated.
  • 2D matrix the values of y where the polynomial is going to (y) – be evaluated.
  • =========================================================

Return Value:

This method returns the polynomial evaluated Z=P(X,Y). Z will have the same shape as x and y
mevalr()

Evaluate the polynomial at for the values given in the 2D matrices x, y rotated.

Parameters:
  • ========================================================= (===) –
  • 2D matrix the values of x where the polynomial is going to (x) – be evaluated.
  • 2D matrix the values of y where the polynomial is going to (y) – be evaluated.
  • Angle to rotate the coordinate points x,y before evaluating (rot) – the polynomial. Given in radians
  • =========================================================

Return Value:

This method returns the polynomial evaluated Z=P(x’, y’). Z will have the same shape as x and y. x’ and y’ are calculated from rotating x and y
order
peval()

Evaluate the polynomial at the point x,y

Parameters:
  • ========================================================= (=) –
  • Floating point number containing the x value used to (x) – evaluate the polynomial.
  • Floating point number containing the y value used to (y) – evaluate the polynomial.
  • =========================================================

Return Value:

This method returns the polynomial evaluated z=P(X,Y).
vveval()

Evaluate the polynomials in a 2D mesh defined by the vectors x and y.

Parameters:
  • ========================================================= (===) –
  • 1D vector with the values of x where the polynomial is going to (x) – be evaluated.
  • 1D vector with the values of y where the polynomial is going to (y) – be evaluated.
  • =========================================================

Return Value:

This method returns the polynomial evaluated Z=P(x,y). Z will have the shape (nx, ny), where nx is the length of the x vector, and ny is the length of the y vector.

This method is not really faster than meval, but it might be useful when doing parallel programming parallelizing, because needs to transfer a smaller amount of information to the child processes (vectors instead matrices).

pyoptools.misc.Poly2D.i2pxpy()

Method that returns the x and y powers for a given poly index

index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
xpower 0 1 0 2 1 0 3 2 1 0 4 3 2 1 0
ypower 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4
pol_order 0 1 1 2 2 2 3 3 3 3 4 4 4 4 4
pyoptools.misc.Poly2D.ord2i()

Method that returns the number of coefficients of a polynomial of order o

order 0 1 2 3 4
i 1 3 6 10 15
pyoptools.misc.Poly2D.pxpy2i()

Method that returns the index given power in x and the power in y