# `Geostatex.SpaceTimeVariogram`
[🔗](https://github.com/CountlinkX-Solutions/geostatex/blob/v0.6.0/lib/geostatex/space_time_variogram.ex#L1)

Space-time variograms, after `skgstat.SpaceTimeVariogram` (scikit-gstat).

`new/3` takes `values` as one row per point with one value per time step (`n` points by `T`
steps, steps one unit apart). Every pair of two points at two steps is classed by its spatial
lag (between the points) and its temporal lag (between the steps); the semivariance of each
class gives the experimental grid, `x_lags` spatial lags by `t_lags` temporal ones.

As in scikit-gstat a pair takes the first point (by index) at the earlier step and the second
at the later one, and the classes are `(lower, upper]` intervals from 0, so pairs at the same
point or step are left out.

## Marginals and model

The two marginal variograms are ordinary `Geostatex.Variogram`s: `x_marginal` over all points
at all steps (spatial coordinates), `t_marginal` over the steps at every point (temporal
coordinates), each with the lag options of its axis and a spherical model. The space-time model
combines their fitted models `Vx(h)` and `Vt(t)`:

  * `:sum` - `Vx(h) + Vt(t)`;
  * `:product` - `Cx * Vt(t) + Ct * Vx(h) - Vx(h) * Vt(t)`;
  * `:product_sum` (default) - `(k2 + k1 * Ct) * Vx(h) + (k3 + k1 * Cx) * Vt(t) -
    k1 * Vx(h) * Vt(t)`,

with `Cx` and `Ct` the sills of the marginals (`sills`) and `k1, k2, k3 >= 0` fitted to the
experimental grid by least squares (`cof`). scikit-gstat pairs its grid with transposed lags
when it fits the product-sum model; Geostatex fits it on the lags of each class.

## Options

  * `:x_lags` - spatial lags (default `10`); `:xbins` - their binning, `:even` (default),
    `:uniform` or a numpy rule (`:sturges`, `:scott`, `:sqrt`, `:fd`, `:doane`, `:rice`);
  * `:t_lags` - temporal lags (default `:max`, one per step); `:tbins` - as `:xbins`;
  * `:maxlag` - the largest spatial lag, as in `Geostatex.Variogram`;
  * `:estimator` - as in `Geostatex.Variogram` except `:entropy` (default `:matheron`);
  * `:xdist_func`, `:tdist_func` - `:euclidean` (default), `:cityblock` or `:chebyshev`;
  * `:use_nugget` - fit nuggets in the marginals (default `false`);
  * `:model` - `:sum`, `:product` or `:product_sum` (default).

# `t`

```elixir
@type t() :: %Geostatex.SpaceTimeVariogram{
  bin_count: [[non_neg_integer()]],
  cof: [float()],
  experimental: [[float() | :nan]],
  maxlag: float() | nil,
  model: :sum | :product | :product_sum,
  model_at_bins: [[float()]],
  sills: map(),
  t_lags: pos_integer(),
  t_marginal: Geostatex.Variogram.t(),
  tbins: [float()],
  x_lags: pos_integer(),
  x_marginal: Geostatex.Variogram.t(),
  xbins: [float()]
}
```

# `model_grid`

```elixir
@spec model_grid(t(), [number()]) :: [[float()]]
```

The space-time model with coefficients `cof` (`[k1, k2, k3]` for `:product_sum`, `[]`
otherwise) on the lag grid: one row per spatial lag, one value per temporal lag.

# `new`

```elixir
@spec new(term(), [[number()]], keyword()) :: t()
```

The space-time variogram of `values` (one list of `T` values per point) observed at `points`
(as in `Geostatex.Variogram.new/3`). See the module documentation for the options.

# `transform`

```elixir
@spec transform(t(), [{number(), number()}]) :: [float()]
```

The fitted space-time model at the spatial and temporal lags `pairs` (`[{h, t}]`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
