Interpolants

These classes are principally used by InterpolatedImage. They define how the surface brightness between pixel centers is defined from the values at the centers.

class galsim.Interpolant[source]

A base class that defines how interpolation should be done.

An Interpolant is needed for an InterpolatedImage to define how interpolation should be done an locations in between the integer pixel centers.

static from_name(name, tol=None, gsparams=None)[source]

A factory function to create an Interpolant of the correct type according to the (string) name of the Interpolant.

This is mostly used to simplify how config files specify the Interpolant to use.

Valid names are:

In addition, if you want to specify the conserve_dc option for Lanczos, you can append either T or F to represent conserve_dc = True/False (respectively). Otherwise, the default conserve_dc=True is used.

Parameters:
  • name – The name of the interpolant to create.

  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property gsparams

The GSParams of the Interpolant

kval(k)[source]

Calculate the value of the interpolant kernel in Fourier space at one or more k values.

Parameters:

k – The value (as a float) or values (as a np.array) at which to compute the amplitude of the Interpolant kernel in Fourier space.

Returns:

The k-value(s) at the k location(s). If k was an array, then this is also

an array.

Return type:

kval

property negative_flux

The negative-flux fraction of the interpolation kernel.

property positive_flux

The positive-flux fraction of the interpolation kernel.

unit_integrals(max_len=None)[source]

Compute the unit integrals of the real-space kernel.

integrals[i] = int(xval(x), i-0.5, i+0.5)

Parameters:

max_len – The maximum length of the returned array. This is usually only relevant for SincInterpolant, where xrange = inf.

Returns:

An array of unit integrals of length max_len or smaller.

Return type:

integrals

withGSParams(gsparams=None, **kwargs)[source]

Create a version of the current interpolant with the given gsparams

xval(x)[source]

Calculate the value of the interpolant kernel at one or more x values

Parameters:

x – The value (as a float) or values (as a np.array) at which to compute the amplitude of the Interpolant kernel.

Returns:

The value(s) at the x location(s). If x was an array, then this is also

an array.

Return type:

xval

class galsim.Delta(tol=None, gsparams=None)[source]

Bases: Interpolant

Delta-function interpolation.

The interpolant for when you do not want to interpolate between samples. It is not really intended to be used for any analytic drawing because it is infinite in the x domain at the location of samples, and it extends to infinity in the u domain. But it could be useful for photon-shooting, where it is trivially implemented as no displacements.

Parameters:
  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property ixrange

The total integral range of the interpolant. Typically 2 * xrange.

property krange

The maximum extent of the interpolant in Fourier space (in 1/pixels).

unit_integrals(max_len=None)[source]

Compute the unit integrals of the real-space kernel.

integrals[i] = int(xval(x), i-0.5, i+0.5)

Parameters:

max_len – The maximum length of the returned array. (ignored)

Returns:

An array of unit integrals of length max_len or smaller.

Return type:

integrals

property xrange

The maximum extent of the interpolant from the origin (in pixels).

class galsim.Nearest(tol=None, gsparams=None)[source]

Bases: Interpolant

Nearest-neighbor interpolation (boxcar).

The nearest-neighbor interpolant performs poorly as a k-space or x-space interpolant for interpolated images. (See paper by “Bernstein & Gruen, http://arxiv.org/abs/1401.2636.) The objection to its use in Fourier space does not apply when shooting photons to generate an image; in that case, the nearest-neighbor interpolant is quite efficient (but not necessarily the best choice in terms of accuracy).

Parameters:
  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property ixrange

The total integral range of the interpolant. Typically 2 * xrange.

property krange

The maximum extent of the interpolant in Fourier space (in 1/pixels).

unit_integrals(max_len=None)[source]

Compute the unit integrals of the real-space kernel.

integrals[i] = int(xval(x), i-0.5, i+0.5)

Parameters:

max_len – The maximum length of the returned array. (ignored)

Returns:

An array of unit integrals of length max_len or smaller.

Return type:

integrals

property xrange

The maximum extent of the interpolant from the origin (in pixels).

class galsim.Linear(tol=None, gsparams=None)[source]

Bases: Interpolant

Linear interpolation

The linear interpolant is a poor choice for FFT-based operations on interpolated images, as it rings to high frequencies. (See Bernstein & Gruen, http://arxiv.org/abs/1401.2636.) This objection does not apply when shooting photons, in which case the linear interpolant is quite efficient (but not necessarily the best choice in terms of accuracy).

Parameters:
  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property ixrange

The total integral range of the interpolant. Typically 2 * xrange.

property krange

The maximum extent of the interpolant in Fourier space (in 1/pixels).

unit_integrals(max_len=None)[source]

Compute the unit integrals of the real-space kernel.

integrals[i] = int(xval(x), i-0.5, i+0.5)

Parameters:

max_len – The maximum length of the returned array. This is usually only relevant for SincInterpolant, where xrange = inf.

Returns:

An array of unit integrals of length max_len or smaller.

Return type:

integrals

property xrange

The maximum extent of the interpolant from the origin (in pixels).

class galsim.Cubic(tol=None, gsparams=None)[source]

Bases: Interpolant

Cubic interpolation

The cubic interpolant is exact to 3rd order Taylor expansion (from R. G. Keys, IEEE Trans. Acoustics, Speech, & Signal Proc 29, p 1153, 1981). It is a reasonable choice for a four-point interpolant for interpolated images. (See Bernstein & Gruen, http://arxiv.org/abs/1401.2636.)

Parameters:
  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property ixrange

The total integral range of the interpolant. Typically 2 * xrange.

property krange

The maximum extent of the interpolant in Fourier space (in 1/pixels).

unit_integrals(max_len=None)[source]

Compute the unit integrals of the real-space kernel.

integrals[i] = int(xval(x), i-0.5, i+0.5)

Parameters:

max_len – The maximum length of the returned array. This is usually only relevant for SincInterpolant, where xrange = inf.

Returns:

An array of unit integrals of length max_len or smaller.

Return type:

integrals

property xrange

The maximum extent of the interpolant from the origin (in pixels).

class galsim.Quintic(tol=None, gsparams=None)[source]

Bases: Interpolant

Fifth order interpolation

The quintic interpolant is exact to 5th order in the Taylor expansion and was found by Bernstein & Gruen (http://arxiv.org/abs/1401.2636) to give optimal results as a k-space interpolant.

Parameters:
  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property ixrange

The total integral range of the interpolant. Typically 2 * xrange.

property krange

The maximum extent of the interpolant in Fourier space (in 1/pixels).

property xrange

The maximum extent of the interpolant from the origin (in pixels).

class galsim.SincInterpolant(tol=None, gsparams=None)[source]

Bases: Interpolant

Sinc interpolation (inverse of nearest-neighbor).

The Sinc interpolant (K(x) = sin(pi x)/(pi x)) is mathematically perfect for band-limited data, introducing no spurious frequency content beyond kmax = pi/dx for input data with pixel scale dx. However, it is formally infinite in extent and, even with reasonable trunction, is still quite large. It will give exact results in GSObject.kValue for InterpolatedImage when it is used as a k-space interpolant, but is extremely slow. The usual compromise between sinc accuracy vs. speed is the Lanczos interpolant (see its documentation for details).

Parameters:
  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property ixrange

The total integral range of the interpolant. Typically 2 * xrange.

property krange

The maximum extent of the interpolant in Fourier space (in 1/pixels).

unit_integrals(max_len=None)[source]

Compute the unit integrals of the real-space kernel.

integrals[i] = int(xval(x), i-0.5, i+0.5)

Parameters:

max_len – The maximum length of the returned array.

Returns:

An array of unit integrals of length max_len or smaller.

Return type:

integrals

property xrange

The maximum extent of the interpolant from the origin (in pixels).

class galsim.Lanczos(n, conserve_dc=True, tol=None, gsparams=None)[source]

Bases: Interpolant

The Lanczos interpolation filter, nominally sinc(x)*sinc(x/n)

The Lanczos filter is an approximation to the band-limiting sinc filter with a smooth cutoff at high x. Order n Lanczos has a range of +/- n pixels. It typically is a good compromise between kernel size and accuracy.

Note that pure Lanczos, when interpolating a set of constant-valued samples, does not return this constant. Setting conserve_dc in the constructor tweaks the function so that it approximately conserves the value of constant (DC) input data (accurate to better than 1.e-5 when used in two dimensions).

Parameters:
  • n – The order of the Lanczos function

  • conserve_dc – Whether to add the first order correction to flatten out the flux response to a constant input. [default: True, see above]

  • tol – [deprecated]

  • gsparams – An optional GSParams argument. [default: None]

property conserve_dc

Whether this interpolant is modified to improve flux conservation.

property ixrange

The total integral range of the interpolant. Typically 2 * xrange.

property krange

The maximum extent of the interpolant in Fourier space (in 1/pixels).

property n

The order of the Lanczos function.

property xrange

The maximum extent of the interpolant from the origin (in pixels).