Extended Variogram Mode¶
This notebook shows how to enable TerraFlow's extended kriging variogram search on a small synthetic station network. Extended mode evaluates the default spherical, exponential, and Gaussian candidates plus nested variogram candidates, then records candidate LOOCV scores in interpolation_cv.
In [1]:
Copied!
import numpy as np
import pandas as pd
from terraflow.climate import ClimateInterpolator
climate_df = pd.DataFrame(
{
"lat": [39.97, 39.97, 39.97, 39.97, 40.00, 40.00, 40.00, 40.00],
"lon": [-100.03, -100.01, -99.99, -99.97, -100.03, -100.01, -99.99, -99.97],
"mean_temp": [17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0],
"total_rain": [90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0],
}
)
interpolator = ClimateInterpolator(
climate_df=climate_df,
strategy="spatial",
interpolation_method="kriging",
variogram_mode="extended",
)
interpolator.cv_metrics["candidate_scores"]
import numpy as np
import pandas as pd
from terraflow.climate import ClimateInterpolator
climate_df = pd.DataFrame(
{
"lat": [39.97, 39.97, 39.97, 39.97, 40.00, 40.00, 40.00, 40.00],
"lon": [-100.03, -100.01, -99.99, -99.97, -100.03, -100.01, -99.99, -99.97],
"mean_temp": [17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0],
"total_rain": [90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0],
}
)
interpolator = ClimateInterpolator(
climate_df=climate_df,
strategy="spatial",
interpolation_method="kriging",
variogram_mode="extended",
)
interpolator.cv_metrics["candidate_scores"]
/Users/marupilla/workspace/projects/oss/AgroTerraFlow/terraflow/climate.py:347: OptimizeWarning: Covariance of the parameters could not be estimated params, _ = curve_fit( INFO:terraflow.climate:Kriging variogram selected: 'nested_exponential_gaussian' (LOOCV RMSE=0.8174 for 'mean_temp')
INFO:terraflow.climate:ClimateInterpolator initialised: strategy='spatial', interpolation_method='kriging', variogram_mode='extended', records=8, variables=['mean_temp', 'total_rain']
Out[1]:
{'spherical': {'rmse': 2.618615, 'mae': 2.285714},
'exponential': {'rmse': 1.774592, 'mae': 1.504604},
'gaussian': {'rmse': 1.255237, 'mae': 0.805604},
'nested_spherical_gaussian': {'rmse': 0.817436, 'mae': 0.591058},
'nested_exponential_gaussian': {'rmse': 0.817434, 'mae': 0.591057}}
Use the default variogram_mode: standard for large station networks unless nested structures are specifically needed. Extended mode fits custom nested variograms before LOOCV, so it is intentionally more expensive than standard kriging.
In [2]:
Copied!
cell_lats = np.array([39.985, 39.995])
cell_lons = np.array([-100.005, -99.985])
interpolator.interpolate(cell_lats, cell_lons)
cell_lats = np.array([39.985, 39.995])
cell_lons = np.array([-100.005, -99.985])
interpolator.interpolate(cell_lats, cell_lons)
Out[2]:
| mean_temp | mean_temp_krig_std | total_rain | total_rain_krig_std | |
|---|---|---|---|---|
| 0 | 20.223769 | 0.947425 | 122.237685 | 0.947425 |
| 1 | 22.839164 | 0.535845 | 148.391636 | 0.535845 |