A robot calibration table may store a small position correction for every combination of two stage coordinates. The table can have the expected shape even after its two axes have been swapped. A square array makes this especially easy to miss because transposing it leaves the row and column counts unchanged. Check which physical coordinate each array axis represents before interpolating between measured points.

Pair each coordinate axis with its data

SciPy's RegularGridInterpolator accepts a rectilinear grid, including uneven spacing between coordinates. Each coordinate vector must be strictly increasing or strictly decreasing. The order of those vectors matches the corresponding axes of the values array. NumPy's meshgrid with indexing="ij" builds coordinate arrays in that same order, so the first index selects the first coordinate vector.

Here, the x stage visits positions in descending order while the y stage uses uneven spacing. An affine test surface stands in for known corrections in millimeters. The query at x equal to 30 and y equal to 2.5 is inside the grid. The query at x equal to 45 extends beyond the measured range.

import numpy as np

from scipy.interpolate import RegularGridInterpolator

x_mm = np.array([40.0, 20.0, 0.0])

y_mm = np.array([0.0, 10.0, 30.0])

x_grid, y_grid = np.meshgrid(x_mm, y_mm, indexing="ij")

offset_mm = 0.10 + 0.01 * x_grid - 0.04 * y_grid

queries = np.array([[30.0, 2.5], [45.0, 2.5]])

lookup = RegularGridInterpolator(

(x_mm, y_mm), offset_mm, bounds_error=False,

)

flipped = RegularGridInterpolator((x_mm[::-1], y_mm), offset_mm[::-1, :])

transposed = RegularGridInterpolator((x_mm, y_mm), offset_mm.T)

inside, outside = lookup(queries)

assert np.isclose(inside, 0.30)

assert np.isnan(outside)

assert np.isclose(flipped(queries[:1])[0], inside)

assert np.isclose(transposed(queries[:1])[0], 0.25)

The inside query returns 0.30 mm, which matches the test formula. The transposed table has the same shape and is accepted by the constructor, but returns 0.25 mm at the same query. Reversing both the x vector and the x rows preserves the intended value. With bounds checking disabled and the default fill value, the outside query returns NaN.

Check the imported table at known positions

Save the axis names and units with the coordinate vectors and the values array. Check at least one known grid corner and an interior point with unequal relative distances along the two axes. A symmetric sample can let a transpose pass by coincidence. If the source sorts an axis, reorder the matching dimension of the corrections in the same operation.

Choose the out-of-range policy when configuring the lookup. The routine can raise on an outside query or return a configured fill value. A fill value of None instead requests extrapolation when bounds checking is disabled. Keep outside-grid results visible in calibration reports, since a plausible value beyond the sampled region says little about measurement coverage.

Sources

SciPy RegularGridInterpolator reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RegularGridInterpolator.html

NumPy meshgrid reference: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html