Interpolators

A “Interpolator” in spexxy is similar to a Grid, but works on a continuous parameter space instead of a discrete one. In fact, many interpolators build on an existing grid and allows for interpolation between grid points.

As with a Grid, the usual way of getting data from an interpolator is by calling it with the requested parameters:

ip = Interpolator()
data = ip((3.14, 42.))

A class inheriting from Interpolator must overwrite all necessary methods, in particular __call__() and axes().

spexxy comes with three pre-defined interpolators:

Interpolator

class spexxy.interpolator.Interpolator(cache_level: int = 0, *args, **kwargs)

Base class for all interpolators in spexxy.

__call__(params: Tuple) → Any

Interpolates at the given parameter set

Parameters:params – Parameter set to interpolate at
Returns:Interpolation result at given position
__init__(cache_level: int = 0, *args, **kwargs)

Initializes a new interpolator.

Parameters:cache_level – Level of caching: 0 means off, 1 means only last dimension, 2 is last 2 dimensions and so on. Interpolation might be faster with higher level, but will consume significantly more memory.
axes() → List[spexxy.grid.grid.GridAxis]

Returns information about the axes.

Returns:List of GridAxis objects describing the grid’s axes
clear_cache()

Clear cache.

LinearInterpolator

class spexxy.interpolator.LinearInterpolator(grid: spexxy.grid.grid.Grid, *args, **kwargs)

A basic linear interpolator that operates on a given grid.

__call__(params: Tuple) → spexxy.data.spectrum.Spectrum

Interpolates at the given parameter set

Parameters:params – Parameter set to interpolate at
Returns:Interpolated spectrum at given position
__init__(grid: spexxy.grid.grid.Grid, *args, **kwargs)

Initializes a new linear interpolator.

Parameters:grid – Grid to interpolate on.
axes() → List[spexxy.grid.grid.GridAxis]

Returns information about the axes.

Returns:List of GridAxis objects describing the grid’s axes
grid

Returns grid used in this interpolator

Returns:Grid used for this interpolator

SplineInterpolator

class spexxy.interpolator.SplineInterpolator(grid: spexxy.grid.grid.Grid, derivs: spexxy.grid.grid.Grid = None, n: int = 1, verbose: bool = False, *args, **kwargs)

A cubic spline interpolator that operates on a given grid.

__call__(params: Tuple) → spexxy.data.spectrum.Spectrum

Interpolates at the given parameter set.

Parameters:params – Parameter set to interpolate at.
Returns:Interpolated spectrum at given position.
__init__(grid: spexxy.grid.grid.Grid, derivs: spexxy.grid.grid.Grid = None, n: int = 1, verbose: bool = False, *args, **kwargs)

Initializes a new linear interpolator.

Parameters:
  • grid – Grid to interpolate on.
  • derivs – If given, contains a second grid at the same parameters as grid, but containg 2nd derivatives for the first axis of the grid.
  • n – Number of points on each side to use for calculating derivatives.
  • verbose – If True, output some more logs
axes() → List[spexxy.grid.grid.GridAxis]

Returns information about the axes.

Returns:List of GridAxis objects describing the grid’s axes.
grid

Returns grid used in this interpolator.

Returns:Grid used for this interpolator

UlyssInterpolator

class spexxy.interpolator.UlyssInterpolator(filename: str, *args, **kwargs)

Interpolator that works with Ulyss input files.

__call__(params: Tuple) → spexxy.data.spectrum.Spectrum

Interpolates at the given parameter set.

Parameters:params – Parameter set to interpolate at.
Returns:Interpolated spectrum at given position.
__init__(filename: str, *args, **kwargs)

Initializes a new Ulyss interpolator.

Parameters:filename – Name of file containing ulyss interpolator.
axes() → List[spexxy.grid.grid.GridAxis]

Returns information about the axes.

Returns:List of GridAxis objects describing the grid’s axes.
static create(files: List[str], output: str)

Create a new ulyss interpolator from a set of spectrum files.

Parameters:
  • files – List of spectrum files.
  • output – Output file name.