lightcurvelynx.utils.bicubic_interp

The BicubicInterpolator is used by SALT models.

It is adapted from sncosmo’s BicubicInterpolator class (but implemented in JAX): https://github.com/sncosmo/sncosmo/blob/v2.10.1/sncosmo/salt2utils.pyx

Classes

BicubicInterpolator

An object that performs bicubic interpolation over a 2-d grid.

BicubicAxis

A helper class that represents values for an axis of bicubic interpolation

Functions

expand_to_cross_products(x_vals, y_vals)

Create the unraveled arrays representing the grid of points from each access.

Module Contents

expand_to_cross_products(x_vals, y_vals)[source]

Create the unraveled arrays representing the grid of points from each access.

Parameters:
  • x_vals (array-like) – A length N array of the x values.

  • y_vals (array-like) – A length M array of the y values.

Returns:

  • all_x (JAX array) – A length N * M array of the x values.

  • all_y (JAX array) – A length N * M array of the y values.

class BicubicInterpolator(x_vals, y_vals, z_vals)[source]

An object that performs bicubic interpolation over a 2-d grid.

Parameters:
  • x_vals (array-like) – The values along the x-axis of the grid. The values must be sorted and at regular step sizes.

  • y_vals (array-like) – The values along the y-axis of the grid. The values must be sorted and at regular step sizes.

  • z_vals (array-like) – The values along the z-axis of the grid.

x_vals[source]

The values along the x-axis of the grid stored with precomputed information.

Type:

BicubicAxis

y_vals[source]

The values along the y-axis of the grid stored with precomputed information.

Type:

BicubicAxis

z_vals[source]

The values along the z-axis of the grid.

Type:

JAX array

x_vals[source]
y_vals[source]
z_vals[source]
classmethod from_grid_file(filename, scale_factor=1.0)[source]

Load the grid data from an ASCII file and create a BicubicInterpolator.

Parameters:
  • filename (str) – The name of the grid file.

  • scale_factor (float) – A multiplicative scale factor for the z values. Default: 1.0

__call__(x_q, y_q)[source]

Evaluate the bicubic interpolation at a grid of points.

Parameters:
  • x_q (array-like) – The N-length array of x values.

  • y_q (array-like) – The M-length array of y values.

Returns:

results – An N x M array of interpolated values for each (x, y) pair.

Return type:

jaxlib.xla_extension.ArrayImpl

class BicubicAxis(values)[source]

A helper class that represents values for an axis of bicubic interpolation with restrictions on acceptable data to match the SALT2 and SALT3 models.

Restrictions include:

  • Data must contain at least 3 values.

  • Data must be sorted.

  • Data must be spaced at regular steps.

values[source]

The values of the range.

Type:

JAX Array

min_val[source]

The starting value of the range.

Type:

float

max_val[source]

The maximum value of the range.

Type:

float

num_vals[source]

The number of values in the range.

Type:

int

regular_steps

Indicates whether the axis uses regularly sized steps.

Type:

bool

step_size

The step size of the range.

Type:

float

values[source]
num_vals[source]
min_val[source]
max_val[source]
__len__()[source]
__str__()[source]
find_indices(query_pts)[source]

Finds the first index before each of the query values with the n - 1 index in each dimension mapped to n - 2:

values[idx[i]] <= query_pts[i] < values[idx[i] + 1]
for all i where idx[i] > 0 and idx[i] < n - 2.
Parameters:

query_pts (array-like) – The values of the query points.

Returns:

idx – A pair of arrays with the indices.

Return type:

JAX Array

out_of_bounds(values)[source]

Compute a Boolean array of the values that are out of bounds.

Parameters:

values (array-like) – The N values to test

Returns:

results – A length N array indicating whether each element is out of bounds.

Return type:

JAX array