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

where are the search parameters #54

Closed
SBFRF opened this issue Mar 10, 2017 · 8 comments
Closed

where are the search parameters #54

SBFRF opened this issue Mar 10, 2017 · 8 comments

Comments

@SBFRF
Copy link

SBFRF commented Mar 10, 2017

Hey there, New user here. Trying to do some of the krigging we do in SURFER using an open source library like this. Where can the user define the search parameters?

@bsmurphy
Copy link
Contributor

PyKrige doesn't use search parameters in the same way that Surfer does; by default all points in the dataset are used to solve the kriging system. There is an option to specify a number of closest points to use in solving the kriging problem (the 'moving window' capability). You can invoke that by using the n_closest_points kwarg when calling the execute method (see the docstrings). We currently don't support the elliptical search window thing that other kriging packages use. (Mainly because no one has requested or worked on that yet, although in my opinion this capability also can cause more trouble than it's worth.)

@rth
Copy link
Contributor

rth commented Mar 10, 2017

Also, a good description of Surfer search parameters can be found here and in here, I think (never used it myself).

As @bsmurphy mentioned, the only search parameter we support at the moment is n_closest_points, though I believe we could add a spherical search radius (which would be simpler than the elliptical one) if that would be useful. What search parameters are you interested in?

@SBFRF
Copy link
Author

SBFRF commented Mar 13, 2017

so forgive me here, as i'm not all that familar with the innards of the krigging. but doesn't the search ellipse allow one to make an assumption about the data, ie the data are going to vary in a similar manner. for my case, we use the search window to define the cross shore and along shore widths of beach transect data. where we can make the assumption about the data that the beach profile will vary more in the cross shore direction than it does in the alongshore direction. ie the beach gets deeper faster than it varies moving down the beach. if one uses a 'moving window' or n_closest_points I feel like that would weight them, for lack of a better way to put it, weird? no?

@bsmurphy
Copy link
Contributor

Sounds like you would want to use the anisotropy parameters in your problem -- you can specify the angle of anisotropy and the relative scaling between the principle directions in order to essentially define a new internal coordinate system in which the variogram model is the same in all directions. Inside the code, once you specify the anisotropy direction and scaling, the data coordinates are translated into this new coordinate system and then the kriging problem is actually solved in this 'uniform' coordinate system. The point is just to take into account exactly your kind of problem, where things aren't changing in the same way in different directions. Adjusting for anisotropy makes the problem 'homogeneous' in some sense.

You're right, using a uniform search radius or n_closest_points does somewhat ignore this kind of anisotropy. @rth, if we do end up implementing a search radius kwarg (which I think we should do, definitely a nice feature to have), we should be sure to search on the anisotropy-adjusted data, that way it'll be in the 'uniform' coordinate space...

Using an elliptical search window would allow you to do something similar, but I think actually implementing anisotropy explicitly (i.e., in the PyKrige formulation) would be a better bet in your case... If you end up using it on your data, please let us know how it works for you! I've never used the anisotropy parameters myself in any problems, so any input on how it's working would be useful. (Also, if you need help making sense of the anisotropy settings, let us know...)

@SBFRF
Copy link
Author

SBFRF commented Mar 13, 2017

so i implement the following arguments in addition to the search ellipse in surfer. which I've also included in the initialization on your OK class
anisotropyAngle = 90
anisotropyRatio=2
VariogramSlope=1

@SBFRF SBFRF closed this as completed Mar 13, 2017
@SBFRF SBFRF reopened this Mar 13, 2017
@bsmurphy
Copy link
Contributor

So the call to OrdinaryKriging should look something like this:

OrdinaryKriging(x, y, z, anisotropy_angle=90., anisotropy_scaling=2., variogram_model='linear', variogram_parameters=[1., 0.])

I'd recommend looking at the docstring for the OrdinaryKriging class as well, just to make sure the way in which the anisotropy is handle is as you'd expect with these values (specifically, the new y direction is multiplied by 2 I think, not the x direction...).

@SBFRF
Copy link
Author

SBFRF commented Mar 16, 2017

so my notes are two fold: First, If the anisotropy parameters take care of the anisotropy of the data, then what do the search parameters do? are the simply to make the variogram generation more efficient (ie not looking at the whole data set) ?

Secondly, while I've added those, i'm running into constant memory issues when using this interpolation scheme. I've attached the data (and code) for reference.
from pykrige.ok import OrdinaryKriging
import numpy as np
x _grid = np.loadtxt('gridX.txt', delimiter=',', usecols=[0])
y_grid = np.loadtxt('gridY.txt', delimiter=',', usecols=[0])
data_x, data_y, data_z = np.loadtxt('xyzGridparms.txt', delimiter=',', usecols=[0,1,2], unpack=True)
ok = OrdinaryKriging(data_x, data_y, data_z, anisotropy_angle=90,
anisotropy_scaling=2,
variogram_parameters=[1, 0.],
variogram_model='linear')
newBathyGrid, ss = ok.execute('grid', x_grid, y_grid, backend='C', n_closest_points=40)

gridX.txt
gridY.txt
xyzGridparms.txt

@MuellerSeb
Copy link
Member

Closing due to inactivity. Feel free to re-open.

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

No branches or pull requests

4 participants