# geoestadistica-con-pykrige-variogramas-e-interpolacion-espacial
Geoestadística con PyKrige: Variogramas e Interpolación Espacial
Volver a la portada del cursoConfiguración de PyKrige
Sección 2 · Conceptos Básicos de PyKrige
En este video
- Creas un entorno virtual, instalas PyKrige con pip y verificas la versión instalada con pip show
- Recorres los módulos del paquete: OrdinaryKriging, UniversalKriging, las versiones 3D, RegressionKriging y los seis modelos de variograma
- Preparas los datos como tres arreglos x, y, z en coordenadas proyectadas y ves cuándo usar coordinates_type geographic
- Repasas los cinco notebooks del curso, que generan sus datos con semilla fija para que tus números coincidan
python -m venv .venv
.venv\Scripts\activate
# macOS o Linux: source .venv/bin/activate
pip install pykrige matplotlib
# Salida:
# Successfully installed ... matplotlib-3.11.2
# numpy-2.5.3 ... pykrige-1.7.3
# ... scipy-1.18.1 six-1.17.0
python -c "import pykrige; print(pykrige.__version__)"
# Salida:
# 1.7.3
pip show pykrige
# Salida:
# Name: PyKrige
# Version: 1.7.3
# Requires: numpy, scipy
# Con conda: conda install -c conda-forge pykrige
python -c "from pykrige.rk import Krige"
# Salida:
# pykrige.compat.SklearnException:
# sklearn needs to be installed
# in order to use this module
pip install scikit-learn
import numpy, scipy, matplotlib
import pykrige
for lib in [pykrige, numpy, scipy, matplotlib]:
print(lib.__name__, lib.__version__)
import numpy as np
from pykrige.ok import OrdinaryKriging
x = np.array([1.0, 4.0, 7.5, 2.0, 9.0]) # km
y = np.array([2.0, 6.0, 3.0, 9.0, 8.0]) # km
z = np.array([30.1, 31.4, 29.8, 32.2, 31.0])
ok = OrdinaryKriging(x, y, z, variogram_model="linear")
print(x.shape, y.shape, z.shape)
print(ok.variogram_model_parameters.round(3))
# Paso que el video ejecuta sin mostrarlo en pantalla:
lon = np.array([-99.2, -98.7, -99.9, -98.3, -99.5, -98.9])
lat = np.array([19.4, 19.9, 20.3, 19.1, 18.8, 20.6])
z = np.array([12.1, 13.4, 11.8, 14.0, 12.6, 13.1])
from pykrige.ok import OrdinaryKriging
from pykrige.uk import UniversalKriging
ok = OrdinaryKriging(lon, lat, z,
coordinates_type="geographic")
print(ok.coordinates_type)
try:
UniversalKriging(lon, lat, z,
coordinates_type="geographic")
except TypeError as e:
print(type(e).__name__)