API Reference

xinfereo.data module

xinfereo.data.sentinel2_cube(**kwargs)

Read the netcdf file present in this directory and return a xarray cube.

xinfereo.data.tcd_model()

Load the model and return the ONNX runtime session with default options.

xinfereo.data.tcd_model_meta()

Load model metadata as dictionary.

xinfereo.data.tcd_model_path()

Return the path to the model file.

xinfereo.core module

class xinfereo.core.EOInferencer(model_meta: dict, model_name: str = 'tcd_onnx_v0.2')

Bases: object

Facilitates inference of spatio-temporal deep learning models by handling data validation, preprocessing, and model input preparation.

predict(dataset: Dataset) ndarray | dask.array.Array

Full pipeline: prepares input, runs inference (Dask-aware). Returns the raw model output (NumPy array or Dask array), with dimensions matching model_meta[‘output’][‘dim_order’].

prepare_input(dataset: Dataset) ndarray

Validates, preprocesses the input dataset, and returns a NumPy array. This method is suitable for non-Dask inputs or when a full NumPy array is needed.

run_inference(input_numpy_array: ndarray) ndarray

Runs the ONNX model inference on a single NumPy array. This is the core inference kernel.

xinfereo.encoders module

class xinfereo.encoders.HarmonicEncoder

Bases: TemporalEncoder

Encodes temporal information by adding sine and cosine of the day-of-year as new bands/channels. Assumes ‘order: 1’ and ‘frequency: yearly’ from metadata.

encode(data_array: DataArray, time_dim: str = 'time', order: int = 1, frequency: str = 'yearly', **kwargs) DataArray

Adds sine and cosine of the day-of-year as new bands/channels along the ‘band’ dimension of the input data_array.

The input data_array is expected to be the result of stacking spectral bands, e.g., with dimensions (band, time, y, x). The harmonic features will be broadcast to match spatial/temporal dimensions and then concatenated.

Parameters:
  • data_array (xr.DataArray) – Input data array.

  • time_dim (str) – Name of the time dimension. Defaults to ‘time’.

  • order (int) – Expected to be 1 for this encoder (producing one sin and one cos channel). Higher orders are not currently implemented. Defaults to 1.

  • frequency (str) – Expected to be ‘yearly’. Other frequencies are not implemented. Defaults to ‘yearly’.

  • **kwargs – Additional keyword arguments (not used by this encoder).

Returns:

Data array with ‘sin_doy’ and ‘cos_doy’ features added as new

items along the ‘band’ dimension.

Return type:

xr.DataArray

Example

>>> import numpy as np
>>> import pandas as pd
>>> import xarray as xr
>>> # Create sample data: 2 spectral bands, 10 time steps, 3x3 spatial
>>> times = pd.date_range("2021-01-01", periods=10, freq="15D")
>>> bands = ['B01', 'B02']
>>> sample_data = xr.DataArray(
...     np.random.rand(len(bands), len(times), 3, 3),
...     coords={'band': bands, 'time': times, 'y': [1, 2, 3], 'x': [1, 2, 3]},
...     dims=['band', 'time', 'y', 'x'],
...     name='reflectance'
... )
>>> sample_data
<xarray.DataArray 'reflectance' (band: 2, time: 10, y: 3, x: 3)>
[180 values with dtype=float64]
Coordinates:
  * band     (band) <U3 'B01' 'B02'
  * time     (time) datetime64[ns] 2021-01-01 2021-01-16 ... 2021-05-16
  * y        (y) int64 1 2 3
  * x        (x) int64 1 2 3
>>> encoder = HarmonicEncoder()
>>> encoded_data = encoder.encode(sample_data)
>>> encoded_data
<xarray.DataArray (band: 4, time: 10, y: 3, x: 3)>
[360 values with dtype=float32]
Coordinates:
  * band     (band) <U13 'B01' 'B02' 'sin_doy' 'cos_doy'
  * time     (time) datetime64[ns] 2021-01-01 2021-01-16 ... 2021-05-16
  * y        (y) int64 1 2 3
  * x        (x) int64 1 2 3
>>> print(encoded_data.band.values)
['B01' 'B02' 'cos_doy' 'sin_doy']
class xinfereo.encoders.TemporalEncoder

Bases: ABC

Abstract base class for temporal encoders.

abstract encode(data_array: DataArray, time_dim: str = 'time', **kwargs) DataArray

Applies temporal encoding to the data_array.

Parameters:
  • data_array (xr.DataArray) – Input data array, typically with dimensions like (band, time, y, x) after spectral bands have been stacked.

  • time_dim (str) – Name of the time dimension in data_array. Defaults to ‘time’.

  • **kwargs – Additional parameters specific to the encoder.

Returns:

Data array with temporal encoding applied.

For HarmonicEncoder, this means new “bands” or channels for sin/cos day-of-year are added along the ‘band’ dimension.

Return type:

xr.DataArray