scipp.lookup#

scipp.lookup(func, dim=None, *, mode=None, fill_value=None)#

Create a “lookup table” from a histogram (data array with bin-edge coord).

The lookup table can be used to map, e.g., time-stamps to corresponding values given by a time-series log.

Parameters:
  • func (DataArray) – Data array defining the lookup table.

  • dim (Optional[str], default: None) – Dimension along which the lookup occurs.

  • mode (Optional[Literal['previous', 'nearest']], default: None) – Mode used for looking up function values. Must be None when func is a histogram. Otherwise this defaults to ‘nearest’.

  • fill_value (Optional[Variable], default: None) – Value to use for points outside the range of the function as well as points in masked regions of the function. If set to None (the default) this will use NaN for floating point types and 0 for integral types. Must have the same dtype and unit as the function values.

Returns:

Lookup – The created lookup table.

Examples

>>> x = sc.linspace(dim='x', start=0.0, stop=1.0, num=4)
>>> vals = sc.array(dims=['x'], values=[3, 2, 1])
>>> hist = sc.DataArray(data=vals, coords={'x': x})
>>> sc.lookup(hist, 'x')[sc.array(dims=['event'], values=[0.1,0.4,0.1,0.6,0.9])]
<scipp.Variable> (event: 5)      int64  [dimensionless]  [3, 2, ..., 2, 1]