raster_tools.general.ModelPredictAdaptor#

class raster_tools.general.ModelPredictAdaptor(model, method=None)[source]#

An adaptor class that allows models without a predict method to be used with model_predict_raster() and model_predict_vector().

Examples

For a model function:

>>> def my_model_func(x):
...     return np.sin(x) + np.cos(x)
>>> model = ModelPredictAdaptor(my_model_func)
>>> result_raster = rts.general.model_predict_raster(
...         predictors, model, n_outputs=predictors.nbands
... )

For a model function lacking a predict method:

>>> class MyModel:
...     # ...
...     def transform(x):
...         # ...
...         return result
>>> model = ModelPredictAdaptor(MyModel(), "transform")
>>> result_raster = rts.general.model_predict_raster(predictors, model)
__init__(model, method=None)[source]#

Constructs an adaptor.

Parameters
  • model (callable, object) – The model function or object. The method parameter determines how this object is handled.

  • method (None, str, callable, optional) – Determines how input data is provided to model. If None, model is called with the data as the argument, e.g. model(x). If a string, the adaptor passes input data to the method on model with the same name, e.g. for method=”my_func”, model.my_func(x) is called.

Methods

__init__(model[, method])

Constructs an adaptor.

predict(x)

Pass the input data to the wrapped model and produce the results