# Help for "shapelets_phi" routine:

## Calculate 1D and 2D Cartesian shapelet basis functions.

This routine calculates the 2D Cartesian shapelet basis functions phi. It can be called using basis=shapelets_phi([2,0],1,1).

The first argument specifies that the n_1=2, n_2=0 basis function should be calculated. The second and third argumentscontain the position where the basis function should be evaluated, in (x,y) Cartesian coordinates. This could be replaced by a grid of points, such as those created by shapelets_make_xarr.pro, where x1 is an array containing the x positions and x2 is an array of the same size containing the y positions. Optionally, beta can be specified by adding e.g. beta=1.4, but if it is not, beta is assumed to be unity. Frequently in other shapelets routines, the x1 and x2 are instead rescaled to create the same effect.

Setting the flag /INTEGRATE integrates the basis functions within rectangular pixels centred on the (x1,x2) grid points, rather than simply evaluating the functions at the centres of the pixels. Setting the flag /ARRAY returns an array containing all polar shapelet basis functions with n less than or equal to that input. Since the (integrated) Cartesian shapelet basis functions are calculated using a recursion relation anyway, this is no slower ad can be useful (e.g. for simultaneously fitting all of the shapelet coefficients).

```; NAME:
;      SHAPELETS_PHI
;
; CATEGORY:
;      Shapelets.
;
; PURPOSE:
;      Compute (dimensionless) Cartesian shapelet basis functions phi(x)
;      in 1D or 2D, based on Hermite polynomials. Dimensionful basis functions
;      can be calculated with shapelets_phi(n,x1/beta[,x2/beta])/beta.
;
; INPUTS:
;      n - Basis function order. Integer n OR vector [n1,n2].
;      If you supply an n with 1 dimension, it will return a 1D basis function.
;      If you supply an n with 2 dimensions, it will return a 2D basis function.
;
; OPTIONAL INPUTS:
;      x1         - Grid of x coordinates (e.g. created by shapelets_make_xarr.pro).
;      x2         - Grid of y coordinates if a 2D basis function is required.
;      BETA       - Shapelet scale size beta.
;      ELLIPTICITY- Ellipticity of basis functions, in weak lensing notation:
;                   either [e1,e2] or complex(e1,e2), where e1=e*cos(2theta) and
;                   e2=e*sin(2theta), with e=(a-b)/(a+b) for major and minor axes
;                   and theta is the angle of the major axis, a/c/w from x axis.
;                   This only works for basis functions not integrated in pixels.
;      THETA_ZERO - Basis functions are rotated by this anlge, a/c/w from x axis.
;
; KEYWORD PARAMETERS:
;      /INTEGRATE - Default behaviour is to simply evaluate phi at the centre
;                   of each pixel. If /INTEGRATE is set, the routine will use
;                   the recursion relation in Shapelets III to integrate the
;                   the basis functions within pixels (currently 2D only).
;      /ARRAY     - Instead of just returning one basis function, if /ARRAY is
;                   set, the routine will return an array containing all of
;                   the (pixellated) basis functions up to n_max=n[0]+n[1].
;
; OUTPUTS:
;      Cartesian shapelet basis function phi_n1[_n2](x[,y])
;
; EXAMPLE USE:
;      plot,x,shapelets_phi(4,x,beta=1),psym=-3
;      tvscl,float(shapelets_phi([2,2],/integrate))
;
; TO DO:
;      Work round factorials if n>20? Doesn't matter as much as in
;       shapelets_hermite.pro, though, since here are just multiplying
;       large numbers rather than subtracting them.
;      Truncate pixellation to within pixels near the centre only, for
;       a speed up.
;      Model unresponsive dead zones around the edges of CCD pixels by
;       rescaling pix_size.
;
; MODIFICATION HISTORY:
;      Jan 09 - Division error if beta and X1, X2 are integers caught by RM.
;      Apr 07 - RM added theta_zero option.
;      Mar 07 - Elliptical basis functions added by RM.
;      Jul 05 - BETA input added by RM to make dimensionful basis functions.
;      Feb 05 - Bug fixed when using /ARRAY but not /INTEGRATE by RM.
;      Aug 04 - Error catching for 1D arrays of 2D functions improved by RM.
;      Oct 03 - Speed up by efficient calculation of polynomials by RM.
;      Oct 03 - Bug fixed in integration limits by Alain Bonissent.
;      Sep 03 - Analytic integration option for 1D shapelets added by RM.
;      Nov 01 - Analytic integration option for 2D shapelets added by RM.
;      Sep 01 - 1D/2D version written by Richard Massey.
;      Jul 99 - Written by Alexandre Refregier.
```