modelling
py3dinterpolations.modelling
¶
Modelling pipeline for 3D interpolation.
Estimator(griddata, params, scoring='neg_mean_absolute_error', verbose=3)
¶
Parameter estimation via sklearn GridSearchCV.
Currently supports pykrige's Krige wrapper for cross-validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
griddata
|
GridData
|
Training data. |
required |
params
|
dict[str, list[object]]
|
Parameter grid for GridSearchCV. |
required |
scoring
|
str
|
Scoring method. See sklearn docs. |
'neg_mean_absolute_error'
|
verbose
|
int
|
Verbosity level (0-3). |
3
|
Source code in py3dinterpolations/modelling/estimator.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
Modeler(griddata, grid, model)
¶
Orchestrates fitting a model and predicting on a 3D grid.
Handles normalization-aware grid selection and standardization reversal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
griddata
|
GridData
|
Training data. |
required |
grid
|
Grid3D
|
3D grid for predictions. |
required |
model
|
BaseModel
|
Fitted or unfitted BaseModel instance. Will be fit on construction. |
required |
Source code in py3dinterpolations/modelling/modeler.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
predict(**kwargs)
¶
Make predictions, handling normalization and standardization reversal.
Returns:
| Type | Description |
|---|---|
ndarray
|
Interpolated numpy array. |
Source code in py3dinterpolations/modelling/modeler.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
BaseModel
¶
Bases: ABC
Interface for interpolation models.
All models must implement fit() and predict() with consistent signatures.
name
abstractmethod
property
¶
Human-readable model name.
fit(x, y, z, v)
abstractmethod
¶
Fit the model to training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
X coordinates of training points. |
required |
y
|
ndarray
|
Y coordinates of training points. |
required |
z
|
ndarray
|
Z coordinates of training points. |
required |
v
|
ndarray
|
Values at training points. |
required |
Source code in py3dinterpolations/modelling/models/base.py
16 17 18 19 20 21 22 23 24 25 26 | |
predict(grid_x, grid_y, grid_z, **kwargs)
abstractmethod
¶
Predict on 1D grid arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_x
|
ndarray
|
1D array of X grid coordinates. |
required |
grid_y
|
ndarray
|
1D array of Y grid coordinates. |
required |
grid_z
|
ndarray
|
1D array of Z grid coordinates. |
required |
Returns:
| Type | Description |
|---|---|
InterpolationResult
|
Interpolation result with at least the interpolated field. |
Source code in py3dinterpolations/modelling/models/base.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
IDWModel(power=1.0, threshold=1e-10)
¶
Bases: BaseModel
Vectorized IDW interpolation.
Uses numpy broadcasting instead of Python loops for ~1000x speedup on typical workloads. Batches computation for memory safety.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power
|
float
|
Power parameter controlling distance decay. Higher values give more weight to nearby points. |
1.0
|
threshold
|
float
|
Distance below which a point is treated as coincident with a training point (exact interpolation). |
1e-10
|
Source code in py3dinterpolations/modelling/models/idw.py
25 26 27 28 29 | |
fit(x, y, z, v)
¶
Store training data.
Source code in py3dinterpolations/modelling/models/idw.py
31 32 33 34 | |
predict(grid_x, grid_y, grid_z, **kwargs)
¶
Predict on a regular grid defined by 1D arrays.
Returns:
| Type | Description |
|---|---|
InterpolationResult
|
InterpolationResult with shape (len(grid_z), len(grid_y), len(grid_x)) |
InterpolationResult
|
to match pykrige's output convention. |
Source code in py3dinterpolations/modelling/models/idw.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
KrigingModel(**kriging_params)
¶
Bases: BaseModel
Ordinary Kriging 3D wrapper around pykrige.
pykrige fits at construction time, so fit() constructs the OrdinaryKriging3D instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kriging_params
|
object
|
Parameters passed to OrdinaryKriging3D constructor. |
{}
|
Source code in py3dinterpolations/modelling/models/kriging.py
20 21 22 | |
fit(x, y, z, v)
¶
Fit by constructing the OrdinaryKriging3D model.
Source code in py3dinterpolations/modelling/models/kriging.py
24 25 26 | |
predict(grid_x, grid_y, grid_z, **kwargs)
¶
Execute kriging on the given grid arrays.
Returns:
| Type | Description |
|---|---|
InterpolationResult
|
InterpolationResult with interpolated and variance arrays. |
InterpolationResult
|
Shape is (len(grid_z), len(grid_y), len(grid_x)) per pykrige convention. |
Source code in py3dinterpolations/modelling/models/kriging.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
SklearnModel(estimator, model_name='sklearn')
¶
Bases: BaseModel
Wrapper for any sklearn estimator with fit/predict interface.
Handles classifiers (predict_proba) and regressors (predict).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
SklearnEstimator
|
A sklearn estimator instance. |
required |
model_name
|
str
|
Human-readable name for this model. |
'sklearn'
|
Source code in py3dinterpolations/modelling/models/sklearn_model.py
19 20 21 | |
fit(x, y, z, v)
¶
Fit the sklearn estimator.
Source code in py3dinterpolations/modelling/models/sklearn_model.py
23 24 25 26 | |
predict(grid_x, grid_y, grid_z, **kwargs)
¶
Predict on a regular grid.
Returns:
| Type | Description |
|---|---|
InterpolationResult
|
InterpolationResult with shape (len(grid_z), len(grid_y), len(grid_x)) |
InterpolationResult
|
to match the convention of other models. |
Source code in py3dinterpolations/modelling/models/sklearn_model.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
PreprocessingKwargs
¶
Bases: TypedDict
Type-safe kwargs for Preprocessor construction.
Preprocessor(griddata, downsampling_res=None, downsampling_method=DownsamplingStatistic.MEAN, normalize_xyz=True, standardize_v=True)
¶
Preprocess GridData before interpolation.
Supports downsampling, normalization of XYZ, and standardization of V. Returns a new GridData with preprocessing params attached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
griddata
|
GridData
|
Source data to preprocess. |
required |
downsampling_res
|
float | None
|
Block resolution for downsampling. None to skip. |
None
|
downsampling_method
|
DownsamplingStatistic | str | Callable[..., DataFrame]
|
Statistic for downsampling, or a custom callable. |
MEAN
|
normalize_xyz
|
bool
|
Whether to normalize XYZ to [0, 1]. |
True
|
standardize_v
|
bool
|
Whether to standardize V to mean=0, std=1. |
True
|
Source code in py3dinterpolations/modelling/preprocessor.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
preprocess()
¶
Execute the preprocessing pipeline.
Returns:
| Type | Description |
|---|---|
GridData
|
New GridData with preprocessed data and params attached. |
Source code in py3dinterpolations/modelling/preprocessor.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
get_model(model_type, **kwargs)
¶
Instantiate a model by type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_type
|
ModelType | str
|
Model identifier, either a ModelType enum or its string value. |
required |
**kwargs
|
object
|
Parameters passed to the model constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
BaseModel
|
An instantiated model ready for fit(). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If model_type is not in the registry. |
Source code in py3dinterpolations/modelling/models/__init__.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
reverse_preprocessing(griddata)
¶
Reverse all reversible preprocessing transformations.
Reverses normalization of XYZ and standardization of V. Downsampling cannot be reversed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
griddata
|
GridData
|
GridData with preprocessing_params set. |
required |
Returns:
| Type | Description |
|---|---|
GridData
|
New GridData with reversed transformations. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no preprocessing params are present. |
Source code in py3dinterpolations/modelling/preprocessor.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |