Transiograms¶
Experimental transiograms, the one-directional TransiogramModel, the 3D TransitionModel, and the fit_quality report that compares simulated realizations with their model. See the guide; the report is described in the T-PROGS and MCP and MCRF guides.
ExperimentalTransiogram
¶
Experimental transition probabilities per lag.
Attributes:
| Name | Type | Description |
|---|---|---|
lags |
ndarray
|
Nominal lag of each class. |
mean_lags |
ndarray
|
Mean separation of the pairs in each class (NaN when empty). |
counts |
ndarray
|
|
probabilities |
ndarray
|
|
tail_totals |
ndarray
|
|
directed |
bool
|
False when both orientations of each pair were counted. |
Examples:
>>> d = tg.datasets.varved_sequence()
>>> exp = tg.downhole_transiogram(
... d["CODE"], lags=[0.5, 1.0, 1.5, 2.0], holes=d["HOLE_ID"], from_=d["FROM"], to=d["TO"])
>>> exp.lags
array([0.5, 1. , 1.5, 2. ])
>>> exp.counts.shape, exp.probabilities.shape, exp.tail_totals.shape
((4, 3, 3), (4, 3, 3), (4, 3))
>>> bool(np.allclose(exp.probabilities.sum(axis=2), 1.0))
True
>>> tg.ExperimentalTransiogram.from_json(exp.to_json()).to_json() == exp.to_json()
True
mean_lags
property
¶
mean_lags: NDArray[float64]
(n_lags,) mean separation of the pairs in each class, NaN when empty.
counts
property
¶
counts: NDArray[float64]
(n_lags, k, k) pair counts (lengths for the downhole estimator).
probabilities
property
¶
probabilities: NDArray[float64]
(n_lags, k, k) counts over row totals; NaN rows where a tail category has no pair.
to_json
¶
to_json() -> str
from_json
staticmethod
¶
from_json(text: str) -> ExperimentalTransiogram
experimental_transiogram
builtin
¶
experimental_transiogram(
coords: ArrayLike | str | object,
codes: ArrayLike | str | None = None,
*,
holes: ArrayLike | str | None = None,
direction: tuple[float, float] | None = None,
lag: float,
n_lags: int,
lag_tolerance: float | None = None,
angle_tolerance: float = 22.5,
bandwidth: float = Ellipsis,
vertical_bandwidth: float = Ellipsis,
directed: bool = True,
pairs: Literal[
"all", "same_hole", "different_hole"
] = "all",
categories: Categories | int | object | None = None,
data: Mapping[str, ArrayLike] | object | None = None,
) -> ExperimentalTransiogram
Transiogram from scattered points (composites).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
array_like
|
|
required |
codes
|
array_like or str
|
Category per point, -1 or NaN missing. |
None
|
holes
|
array_like or str
|
Hole id per point, needed by |
None
|
direction
|
tuple of (azimuth, dip)
|
Degrees; None is omnidirectional. |
None
|
lag
|
(float, int)
|
Lag spacing and number of lag classes. |
required |
n_lags
|
(float, int)
|
Lag spacing and number of lag classes. |
required |
lag_tolerance
|
float
|
Half-width of a lag class; |
None
|
angle_tolerance
|
float
|
Degrees. |
22.5
|
bandwidth
|
float
|
Largest horizontal and vertical offset from the direction line. |
Ellipsis
|
vertical_bandwidth
|
float
|
Largest horizontal and vertical offset from the direction line. |
Ellipsis
|
directed
|
bool
|
Count pairs only head ahead of tail along the direction. |
True
|
pairs
|
(all, same_hole, different_hole)
|
|
"all"
|
categories
|
Categories or int
|
|
None
|
data
|
mapping
|
Strings name its columns. |
None
|
Returns:
| Type | Description |
|---|---|
ExperimentalTransiogram
|
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
When |
Examples:
>>> codes = tg.MarkovChain.from_matrix([[0.8, 0.2], [0.3, 0.7]]).simulate(200, seed=1)[0]
>>> xyz = np.column_stack([np.zeros(200), np.zeros(200), np.arange(200.0)])
>>> exp = tg.experimental_transiogram(xyz, codes, lag=1.0, n_lags=3)
>>> exp.probabilities.shape, exp.directed
((3, 2, 2), False)
downhole_transiogram
builtin
¶
downhole_transiogram(
codes: ArrayLike | str | object,
*,
lags: ArrayLike,
direction: Literal["up", "down"] = "up",
holes: ArrayLike | str | None = None,
from_: ArrayLike | str | None = None,
to: ArrayLike | str | None = None,
depth: ArrayLike | str | None = None,
step: float | None = None,
gap: float = 1e-06,
categories: Categories | int | object | None = None,
data: Mapping[str, ArrayLike] | object | None = None,
) -> ExperimentalTransiogram
Exact downhole transiogram from intervals or samples: overlap lengths at each lag along the holes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codes
|
array_like or str
|
|
required |
lags
|
array_like
|
Positive lags. |
required |
direction
|
(up, down)
|
|
"up"
|
holes
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
from_
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
to
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
depth
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
step
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
gap
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
categories
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
data
|
ArrayLike | str | None
|
The shared sequence arguments. |
None
|
Returns:
| Type | Description |
|---|---|
ExperimentalTransiogram
|
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
When a lag is not positive and finite, a code is out of range, or the sequence arguments disagree in length. |
Examples:
>>> d = tg.datasets.varved_sequence()
>>> exp = tg.downhole_transiogram(
... d["CODE"], lags=[0.5, 1.0, 1.5, 2.0], holes=d["HOLE_ID"], from_=d["FROM"], to=d["TO"])
>>> exp.probabilities.shape
(4, 3, 3)
grid_transiogram
builtin
¶
grid_transiogram(
codes: ArrayLike | str | object,
grid: Grid | object | None = None,
*,
offset: tuple[int, int, int],
n_lags: int,
mask: ArrayLike | None = None,
categories: Categories | int | object | None = None,
) -> ExperimentalTransiogram
Transiogram of a categorical grid along one cell offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codes
|
array_like
|
One code per cell, x fastest; -1 for inactive cells. |
required |
grid
|
Grid
|
|
None
|
offset
|
tuple of 3 int
|
Cell step of lag 1, for example |
required |
n_lags
|
int
|
|
required |
mask
|
array_like
|
Active cells. |
None
|
categories
|
Categories or int
|
|
None
|
Returns:
| Type | Description |
|---|---|
ExperimentalTransiogram
|
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
When |
Examples:
>>> grid = tg.Grid((0.0, 0.0, 0.0), (1.0, 1.0, 1.0), (4, 1, 6))
>>> codes = np.repeat([0, 0, 1, 1, 2, 2], 4)
>>> exp = tg.grid_transiogram(codes, grid, offset=(0, 0, 1), n_lags=2)
>>> exp.probabilities[0]
array([[0.5, 0.5, 0. ],
[0. , 0.5, 0.5],
[0. , 0. , 1. ]])
TransiogramModel
¶
One-directional transiogram model: a continuous-lag Markov chain (markov) or one
analytical curve per entry (entrywise, Li 2007).
Examples:
>>> d = tg.datasets.varved_sequence()
>>> exp = tg.downhole_transiogram(
... d["CODE"], lags=[0.5, 1.0, 1.5, 2.0], holes=d["HOLE_ID"], from_=d["FROM"], to=d["TO"])
>>> markov = tg.TransiogramModel.fit_markov(exp)
>>> markov.kind, markov.transition(1.0).shape, markov.transition([1.0, 2.0]).shape
('markov', (3, 3), (2, 3, 3))
>>> bool(np.nanmax(np.abs(markov.residuals(exp))) < 0.05)
True
>>> chain = tg.MarkovChain().fit(d["CODE"], holes=d["HOLE_ID"], from_=d["FROM"], to=d["TO"])
>>> tg.TransiogramModel.markov(chain).rates.shape
(3, 3)
>>> curves = tg.TransiogramModel.fit_entrywise(exp, markov.proportions, structures="spherical")
>>> curves.kind, curves.rates
('entrywise', None)
>>> fixed = tg.TransiogramModel.entrywise([0.5, 0.5], "exponential", [[2.0, 2.0], [2.0, 2.0]], max_lag=10.0)
>>> np.round(fixed.transition(100.0), 3)
array([[0.5, 0.5],
[0.5, 0.5]])
>>> tg.TransiogramModel.from_json(markov.to_json()) == markov
True
markov
staticmethod
¶
markov(rates: ArrayLike | MarkovChain) -> TransiogramModel
entrywise
staticmethod
¶
entrywise(
proportions: ArrayLike,
structures: str | ArrayLike,
ranges: ArrayLike,
*,
nuggets: ArrayLike | None = None,
complement: ArrayLike | None = None,
max_lag: float,
) -> TransiogramModel
Entrywise model: each entry rises from 0 (or its nugget) to its sill p_j with an
exponential, spherical or Gaussian shape; the complement entry of each row closes it to 1.
Parameters¶
proportions : array_like
structures : str or array_like
One shape for all entries, or (k, k) names.
ranges : array_like
(k, k) practical ranges.
nuggets : array_like, optional
(k, k) nuggets in [0, 1).
complement : array_like, optional
Complement column per row; the diagonal by default.
max_lag : float
Validity (non-negative entries) is checked on a lag grid up to here.
Returns¶
TransiogramModel
Raises¶
InvalidInput
When a shape or name is invalid, a range is not positive, a nugget is outside [0, 1),
or the complement entries turn negative before max_lag.
fit_markov
staticmethod
¶
fit_markov(
experimental: ExperimentalTransiogram,
*,
proportions: ArrayLike | None = None,
background: int = -1,
start: ArrayLike | None = None,
) -> TransiogramModel
Markov model fitted to an experimental transiogram by weighted least squares.
Parameters¶
experimental : ExperimentalTransiogram
proportions : array_like, optional
Sills to honour. By default the sills are the stationary proportions of the starting
rates (start, or the rates read off the first lag where every category is a tail),
which can differ from the data proportions; pass the sample proportions to hold the
sills there.
background : int
Category whose rates are filled from the others; -1 means the last.
start : array_like, optional
Starting rates.
Returns¶
TransiogramModel
kind="markov"; residuals(experimental) gives its misfit.
Raises¶
InvalidInput
When the proportions do not sum to 1, background is not a category, or no lag has
every category as a tail and start is not given.
ConvergenceError
When no valid starting rates exist for these proportions, or the simplex search does
not converge within its evaluation budget.
fit_entrywise
staticmethod
¶
fit_entrywise(
experimental: ExperimentalTransiogram,
proportions: ArrayLike,
*,
structures: str | Sequence[str] | None = None,
complement: ArrayLike | None = None,
) -> TransiogramModel
Entrywise model fitted entry by entry (range by golden section, nugget 0).
Parameters¶
experimental : ExperimentalTransiogram
proportions : array_like
Sills (k,).
structures : str or sequence of str, optional
One shape for all entries or k * k names (row-major, complement entries ignored);
None means "exponential".
complement : array_like, optional
Complement column per row; the diagonal by default.
Returns¶
TransiogramModel
kind="entrywise"; residuals(experimental) gives its misfit.
Raises¶
InvalidInput
When the proportions do not sum to 1, the number of structures is not 1 or k * k,
or the experimental transiogram has no usable row.
transition
¶
transition(h: float | ArrayLike) -> NDArray[np.float64]
residuals
¶
residuals(
experimental: ExperimentalTransiogram,
) -> NDArray[np.float64]
Fit-quality report against an experimental transiogram: experimental minus model t_ij
at each of its lags.
The model is evaluated at the mean lag of each lag class's pairs (the nominal lag when a
class is empty), as fit_markov and fit_entrywise do; those fits minimise the sum of
these squared residuals weighted by the tail totals.
Parameters¶
experimental : ExperimentalTransiogram With as many categories as the model.
Returns¶
numpy.ndarray
(n_lags, k, k) residuals; NaN where the experimental row has no pairs.
Raises¶
InvalidInput When the category counts differ.
Examples¶
d = tg.datasets.varved_sequence() exp = tg.downhole_transiogram( ... d["CODE"], lags=[0.5, 1.0, 2.0], holes=d["HOLE_ID"], from_=d["FROM"], to=d["TO"]) r = tg.TransiogramModel.fit_markov(exp).residuals(exp) r.shape (3, 3, 3) round(float(np.nanmax(np.abs(r))), 2) 0.05
to_json
¶
to_json() -> str
TransitionModel
¶
3D Markov transition model (Carle and Fogg): proportions and one rate matrix per principal axis, interpolated in between, rotated by azimuth, dip and rake.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proportions
|
array_like
|
|
required |
rates_x
|
array_like
|
|
required |
rates_y
|
array_like
|
|
required |
rates_z
|
array_like
|
|
required |
rotation
|
tuple of 3 float
|
Azimuth, dip and rake in degrees. |
(0.0, 0.0, 0.0)
|
background
|
int
|
Background category; -1 means the last. |
-1
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
When the proportions do not sum to 1, a rate matrix is not a generator with
|
Examples:
>>> m = tg.TransitionModel.from_geology(
... [0.5, 0.3, 0.2], [[40.0, 30.0, 20.0], [40.0, 30.0, 20.0], [4.0, 3.0, 2.0]])
>>> m.n_categories, m.background
(3, 2)
>>> np.round(m.mean_lengths([0.0, 0.0, 1.0]), 6)
array([4., 3., 2.])
>>> m.transition([0.0, 0.0, 1.0]).shape, m.transition([[0.0, 0.0, 1.0], [10.0, 0.0, 0.0]]).shape
((3, 3), (2, 3, 3))
>>> m.rates([1.0, 0.0, 0.0]).shape
(3, 3)
>>> c = m.closeness([[0.0, 0.0, 0.0], [0.0, 0.0, 2.0]])
>>> float(c[0]), bool(c[1] < 1.0)
(1.0, True)
>>> turned = tg.TransitionModel(m.proportions, m.rates_x, m.rates_y, m.rates_z, rotation=(30.0, 0.0, 0.0))
>>> turned.rotation
(30.0, 0.0, 0.0)
>>> tg.TransitionModel.from_json(m.to_json()) == m
True
from_geology
staticmethod
¶
from_geology(
proportions: ArrayLike,
mean_lengths: ArrayLike,
*,
embedded_x: ArrayLike | None = None,
embedded_y: ArrayLike | None = None,
embedded_z: ArrayLike | None = None,
rotation: tuple[float, float, float] = (0.0, 0.0, 0.0),
background: int = -1,
) -> TransitionModel
Model from proportions, mean lengths along each principal axis and optional embedded juxtapositions per axis (maximum entropy without them).
Parameters¶
proportions : array_like
mean_lengths : array_like
(3, k): rows x', y', z'.
embedded_x : array_like, optional
(k, k) embedded juxtapositions along each axis.
embedded_y : array_like, optional
(k, k) embedded juxtapositions along each axis.
embedded_z : array_like, optional
(k, k) embedded juxtapositions along each axis.
rotation : tuple of 3 float
background : int
Returns¶
TransitionModel
Raises¶
InvalidInput When the proportions do not sum to 1, a mean length is not positive, or the juxtapositions give no valid generator.
transition
¶
transition(lags: ArrayLike) -> NDArray[np.float64]
rates
¶
rates(lag: ArrayLike) -> NDArray[np.float64]
closeness
¶
closeness(lags: ArrayLike) -> NDArray[np.float64] | float
mean_lengths
¶
mean_lengths(lag: ArrayLike) -> NDArray[np.float64]
to_json
¶
to_json() -> str
FitQuality
¶
How far an ensemble of realizations sits from its model's proportions and transiograms.
Attributes:
| Name | Type | Description |
|---|---|---|
target_proportions |
ndarray
|
|
proportions |
ndarray
|
|
mean_proportions |
ndarray
|
|
offsets |
ndarray
|
|
model |
ndarray
|
|
mean |
ndarray
|
|
standard_error |
ndarray
|
|
proportion_error |
float
|
Largest |
transiogram_error |
float
|
Largest |
max_standard_errors |
float
|
Largest |
Examples:
>>> model = tg.TransitionModel.from_geology(
... [0.5, 0.3, 0.2], [[40.0, 30.0, 20.0], [40.0, 30.0, 20.0], [4.0, 3.0, 2.0]])
>>> grid = tg.Grid((0.0, 0.0, 0.0), (10.0, 10.0, 1.0), (12, 12, 6))
>>> xyz, codes = [[55.0, 55.0, 0.5], [55.0, 55.0, 3.5], [5.0, 105.0, 2.5]], [0, 1, 2]
>>> cells, hard = grid.snap(xyz, codes)
>>> real = tg.mcrf_simulate(model, grid, np.empty((0, 3)), [], n=4, seed=1)
>>> q = tg.fit_quality(model, grid, real, n_lags=2)
>>> q.offsets.shape, q.model.shape == q.mean.shape == q.standard_error.shape
((8, 3), True)
>>> q.proportions.shape, q.mean_proportions.shape, q.target_proportions
((4, 3), (3,), array([0.5, 0.3, 0.2]))
>>> bool(q.proportion_error < 0.2 and q.transiogram_error < 0.5 and q.max_standard_errors > 0)
True
>>> tg.FitQuality.from_json(q.to_json()).to_json() == q.to_json()
True
proportions
property
¶
proportions: NDArray[float64]
(n, k) proportions of each realization over its active cells.
offsets
property
¶
offsets: NDArray[int64]
(m, 3) cell offsets l * direction for l = 1..n_lags, direction-major.
mean
property
¶
mean: NDArray[float64]
(m, k, k) ensemble mean t_ij; NaN where a tail category has no pair.
standard_error
property
¶
standard_error: NDArray[float64]
(m, k, k) standard error of mean (spread over the square root of the number of realizations); NaN with one realization.
transiogram_error
property
¶
transiogram_error: float
Largest |mean t_ij - model t_ij| over every entry and offset.
max_standard_errors
property
¶
max_standard_errors: float
Largest |mean t_ij - model t_ij| / se (se below 0.001 counted as 0.001); above about 4 the ensemble misses the model by more than sampling error.
to_json
¶
to_json() -> str
fit_quality
builtin
¶
fit_quality(
model: TransitionModel,
grid: Grid | object,
realizations: Realizations,
*,
directions: Sequence[tuple[int, int, int]]
| None = None,
n_lags: int = 6,
mask: ArrayLike | None = None,
) -> FitQuality
Fit-quality report: ensemble proportions and grid transiograms of realizations against
model, per realization and on average, with standard errors from the spread across
realizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
TransitionModel
|
|
required |
grid
|
Grid
|
|
required |
realizations
|
Realizations
|
From |
required |
directions
|
sequence of (int, int, int)
|
Cell steps of lag 1; +x, +y, +z and -z by default. |
None
|
n_lags
|
int
|
Lags |
6
|
mask
|
array_like
|
Active cells. |
None
|
Returns:
| Type | Description |
|---|---|
FitQuality
|
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
When |
Examples:
>>> model = tg.TransitionModel.from_geology(
... [0.5, 0.3, 0.2], [[40.0, 30.0, 20.0], [40.0, 30.0, 20.0], [4.0, 3.0, 2.0]])
>>> grid = tg.Grid((0.0, 0.0, 0.0), (10.0, 10.0, 1.0), (12, 12, 6))
>>> xyz, codes = [[55.0, 55.0, 0.5], [55.0, 55.0, 3.5], [5.0, 105.0, 2.5]], [0, 1, 2]
>>> cells, hard = grid.snap(xyz, codes)
>>> real = tg.mcrf_simulate(model, grid, xyz, codes, n=2, seed=1)
>>> tg.fit_quality(model, grid, real, directions=[(0, 0, 1)], n_lags=3).offsets
array([[0, 0, 1],
[0, 0, 2],
[0, 0, 3]])