Skip to content

xarray output

mtdr.xarray_io

The MTDR.to_xarray backend (optional xarray extra).

to_dataset packs a fitted MTDR into an xarray.Dataset. xarray is imported when the function is called, so import mtdr never needs it; without it the call raises ImportError with the install hint. Coordinates are positional (neuron = arange(n_neurons_), time = arange(n_bins_)): the package never sees unit IDs or bin times, and the caller can relabel them afterwards. There is no xarray accessor.

to_dataset(model)

Return a fitted model as an xarray.Dataset.

Dims regressor, neuron, time, component. Variables: B (regressor, neuron, time), the coefficient matrices \(B_p\) of (M37); W (regressor, neuron, component) and S (regressor, time, component), in the model's frame, with component running to max(ranks_) and NaN beyond each regressor's rank; rank (regressor,); intercept (neuron, time) (absent without one); and noise_precision (neuron,). Attributes: estimator, aic, log_likelihood, n_parameters, mtdr_version.

Parameters:

Name Type Description Default
model MTDR

A fitted model.

required

Returns:

Type Description
Dataset

The dataset.

Raises:

Type Description
ImportError

If xarray is not installed.

Examples:

>>> from mtdr import MTDR, simulate
>>> from mtdr.xarray_io import to_dataset
>>> sim = simulate(n_neurons=10, n_bins=5, n_trials=80, ranks=[2, 1], seed=0)
>>> ds = to_dataset(MTDR(ranks=[2, 1], estimator="svd").fit(sim.Y, sim.X))
>>> ds["rank"].values.tolist(), bool(ds["W"].isnull()[1, :, 1].all())
([2, 1], True)