GeoStat-Framework / PyKrige

Kriging Toolkit for Python
https://pykrige.readthedocs.io
BSD 3-Clause "New" or "Revised" License
759 stars 188 forks source link

Use kriging with external drift to interpolate temperature #155

Closed crazyapril closed 4 years ago

crazyapril commented 4 years ago

I'm trying to interpolate temperature data with DEM data and kriging with external drift is suggested. The documentation lists several drift terms (‘regional_linear’, ‘point_log’, ‘external_Z’, ‘specified’, and ‘functional’) but I don't know what's the difference and which to use since I'm new to kriging method. Most tutorials about kriging I've read just throw equations and I couldn't relate them to "drift terms". Could someone give me a clue?

MuellerSeb commented 4 years ago

I can give you a short survey:

If your DEM data is grided and you don't have the elevation data at your target points, you should use external Z drift otherwise use specified drift.

Does that help?

Cheers, Sebastian

crazyapril commented 4 years ago

Thanks, it helps a lot. I've figured out.

MuellerSeb commented 4 years ago

Cool! Don't forget to cite PyKrige ;-) Closing.

guidocioni commented 2 years ago

Sorry for reviving this old thread but just to make sure I understand... If x, y, z, h are the coordinates, values and altitude of some weather stations and lon, lat, hi are the coordinates and altitude of the DEM, then I would do something like this

UniversalKriging(
    x,
    y,
    z,
    drift_terms=['external_Z','specified_drift'],
    external_drift=hi,
    external_drift_x=lon,
    external_drift_y=lat,
    specified_drift=h
)

right?

cerodell commented 2 years ago

Hello! I am trying to krig with external drift. I am using the following setup.

startTime = datetime.now()
krig_uk_dem =UniversalKriging(
    x=df["Easting"],   ## x location of aq monitors in lambert conformal
    y=df["Northing"], ## y location of aq monitors in lambert conformal
    z=df["PM2.5"],     ## measured PM 2.5 concentrations at locations
    drift_terms=['external_Z','specified'],
    external_drift=dem_ds.data.values[0,:,:].T, ## 2d array of dem used for external drift
    external_drift_x=gridx,  ## x coordinates of 2d dem data file in lambert conformal
    external_drift_y=gridy,  ## y coordinates of 2d dem data file in lambert conformal
    specified_drift=df["dem"]       ## elevation of aq monitors 
)
print(f"UK build time {datetime.now() - startTime}")

I thought this was the correct way to set up to krig with external drift, but I received the following error.

AttributeError: 'UniversalKriging' object has no attribute 'external_Z_array'

Im currently using pykrig version 1.6.1

I'm not sure what I'm doing wrong. Any help is greatly appreciated :)