Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kriging with external drift to interpolate temperature #155

Closed
crazyapril opened this issue May 24, 2020 · 5 comments
Closed

Use kriging with external drift to interpolate temperature #155

crazyapril opened this issue May 24, 2020 · 5 comments

Comments

@crazyapril
Copy link

crazyapril commented May 24, 2020

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?

@crazyapril crazyapril changed the title Use kriging with external drift to utilize DEM data Use kriging with external drift to interpolate temperature May 24, 2020
@MuellerSeb
Copy link
Member

I can give you a short survey:

  • regional linear drift is a functional drift, where a linear regional model is fitted automatically with universal kriging (classical case)
  • point-logarithmic drift is used for water level kriging (see here)
  • external Z drift is a special feature, where you can provide grided data in 2D, where the z-value (for example the DEM data) is interpolated to your target points
  • specified drift is the classical form of external drift kriging, where a linear correlated second variable needs to given at all conditioning points AND at the target points for kriging (this could also be used for DEM data, but you have to provide the data at the exact points, where you want to krige the temperature)
  • functional drift is like the regional linear drift, but you can give a set of self defined functions, that depend on the spatial position to generate the drift terms (for regional linear drift in 3D for example, you have 3 functions: f1(x,y,z)=x, f2(x,y,z)=y, f3(x,y,z)=z)

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
Copy link
Author

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

@MuellerSeb
Copy link
Member

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

@guidocioni
Copy link

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
Copy link

cerodell commented Jul 21, 2022

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants