コード例 #1
0
ファイル: classes_kriging.py プロジェクト: olaurendin/Kriging
    def __init__(self, verbose, session, engine, lims, msg, imgfolder, img,
                 colx, coly, colz, colpt, nb_slice, flg_proj, type_Z_data,
                 params_extraction_db, params_random_deposits, params_kriging,
                 params_plots):
        if not img:
            self.img = msg.__class__.__name__
        self.nameimg = os.path.join(imgfolder, img)

        seq = msg.seq
        self.pos, self.seq, self.lims = extract_points(session, seq, colx,
                                                       coly, colz, colpt,
                                                       flg_proj, lims)
        if type_Z_data == "extraction_db":
            print("extraction_db")
            self.data = self.extract_data_db()
        elif type_Z_data == "random_deposits":
            print("random_deposits")
            self.data, self.deposits = self.generate_random_points()
        else:
            print("error")

        self.slice()
        fig, ax = apply_parameters(plut.plotscatterdata,
                                   [self.data, self.nameimg],
                                   params_plots["plotscatterdata"])
        ax.scatter(self.deposits[:, 0],
                   self.deposits[:, 1],
                   self.deposits[:, 2],
                   c="r",
                   s=16 * self.deposits[:, 3])
        plt.show()

        fig, mu, std = apply_parameters(plut.plotgaussiandist,
                                        [self.data[:, 3], self.nameimg],
                                        params_plots["plotgaussiandist"])
        plt.show()

        pw = utilities.pairwise(self.pos)
        apply_parameters(
            plut.laghistogram, [self.data[:, 3], self.nameimg, pw],
            params_plots["laghistogram"])  #, namefile = imgnamebase )

        kriginginstance = self.train_kriging()

        apply_parameters(plut.plotresidualsvario, [
            kriginginstance.delta, kriginginstance.sigma,
            kriginginstance.epsilon, self.nameimg
        ])

        ### TODO : A SUPPRIMER
        n_closest_points = 10

        # self.plotcolormesh(kriginginstance, backend='loop', n_closest_points=n_closest_points)
        apply_parameters(self.plotcolormesh, [kriginginstance],
                         params_plots["plotcolormesh"])
        plt.show()
コード例 #2
0
ファイル: kriging.py プロジェクト: x-malet/geostatsmodels
def kmatrices( data, covfct, u, N=0 ):
    '''
    Input  (data)  ndarray, data
           (model) modeling function
                    - spherical
                    - exponential
                    - gaussian
           (u)     unsampled point
           (N)     number of neighboring points
                   to consider, if zero use all
    '''
    # u needs to be two dimensional for cdist()
    if np.ndim( u ) == 1:
        u = [u]
    # distance between u and each data point in P
    d = cdist( data[:,:2], u )
    # add these distances to P
    P = np.hstack(( data, d ))
    # if N>0, take the N closest points,
    if N > 0:
        P = P[d[:,0].argsort()[:N]]
    # otherwise, use all of the points
    else:
        N = len( P )

    # apply the covariance model to the distances
    k = covfct( P[:,3] )
    # check for nan values in k
    if np.any( np.isnan( k ) ):
        raise ValueError('The vector of covariances, k, contains NaN values')
    # cast as a matrix
    k = np.matrix( k ).T

    # form a matrix of distances between existing data points
    K = pairwise( P[:,:2] )
    # apply the covariance model to these distances
    K = covfct( K.ravel() )
    # check for nan values in K
    if np.any( np.isnan( K ) ):
        raise ValueError('The matrix of covariances, K, contains NaN values')
    # re-cast as a NumPy array -- thanks M.L.
    K = np.array( K )
    # reshape into an array
    K = K.reshape(N,N)
    # cast as a matrix
    K = np.matrix( K )

    return K, k, P
コード例 #3
0
def variogram(data, lags, tol, method):
    '''
    Input:  (data) NumPy array where the fris t two columns
                   are the spatial coordinates, x and y
            (lag)  the distance, h, between points
            (tol)  the tolerance we are comfortable with around (lag)
            (method) either 'semivariogram', or 'covariogram'
    Output: (cv)   <2xN> NumPy array of lags and variogram values
    '''
    # calculate the pairwise distances
    pwdist = utilities.pairwise(data)
    # create a list of lists of indices of points having the ~same lag
    index = [lagindices(pwdist, lag, tol) for lag in lags]
    # calculate the variogram at different lags given some tolerance
    if method in ['semivariogram', 'semi', 'sv', 's']:
        v = [semivariance(data, indices) for indices in index]
    elif method in ['covariogram', 'cov', 'co', 'cv', 'c']:
        v = [covariance(data, indices) for indices in index]
    # bundle the semivariogram values with their lags
    return np.array(zip(lags, v)).T
コード例 #4
0
def variogram(data, lags, tol, method):
    '''
    Input:  (data) NumPy array where the fris t two columns
                   are the spatial coordinates, x and y
            (lag)  the distance, h, between points
            (tol)  the tolerance we are comfortable with around (lag)
            (method) either 'semivariogram', or 'covariogram'
    Output: (cv)   <2xN> NumPy array of lags and variogram values
    '''
    # calculate the pairwise distances
    pwdist = utilities.pairwise(data)
    # create a list of lists of indices of points having the ~same lag
    index = [lagindices(pwdist, lag, tol) for lag in lags]
    # calculate the variogram at different lags given some tolerance
    if method in ['semivariogram', 'semi', 'sv', 's']:
        v = [semivariance(data, indices) for indices in index]
    elif method in ['covariogram', 'cov', 'co', 'cv', 'c']:
        v = [covariance(data, indices) for indices in index]
    # bundle the semivariogram values with their lags
    return np.array(list(zip(lags, v))).T
コード例 #5
0
def variogram(data, lags, tol, method):
    '''
    Input:  (data) NumPy array where the first two columns
                   are the spatial coordinates, x and y
            (lag)  the distance, h, between points
            (tol)  the tolerance we are comfortable with around (lag)
            (method) either 'semivariogram', or 'covariogram'
    Output: (cv)   <2xN> NumPy array of lags and variogram values
    '''
    # calculate the pairwise distances
    pwdist = utilities.pairwise(data)
    # create a list of lists of indices of points having the ~same lag
    index = [lagindices(pwdist, lag, tol) for lag in lags]
    # remove empty "lag" sets, prevents zero division error in [co|semi]variance()
    index = list(filter(lambda x: len(x) > 0, index))
    # calculate the variogram at different lags given some tolerance
    if method in ['semivariogram', 'semi', 'sv', 's']:
        v = [semivariance(data, indices) for indices in index]
    elif method in ['covariogram', 'cov', 'co', 'cv', 'c']:
        v = [covariance(data, indices) for indices in index]
    # bundle the semivariogram values with their lags
    return np.c_[lags, v].T
コード例 #6
0
import scipy.stats as stats
qqdata = stats.probplot(z.por, dist="norm",plot=plt,fit=False)
xh=plt.xlabel('Standard Normal Quantiles')
yh=plt.ylabel('Sorted Porosity Values')
fig=plt.gcf()
fig.set_size_inches(8,8)
th=plt.title('')

# <markdowncell>

# What is the optimal "lag" distance between points?  Use the utilities scattergram() function to help determine that distance.

# <codecell>

pw = utilities.pairwise(P)
geoplot.hscattergram(P,pw,1000,500)
geoplot.hscattergram(P,pw,2000,500)
geoplot.hscattergram(P,pw,3000,500)

# <markdowncell>

# Here, we plot the semivariogram and overlay a horizontal line for the sill, $c$.

# <codecell>

tolerance = 250
lags = np.arange( tolerance, 10000, tolerance*2 )
sill = np.var(P[:,2])

geoplot.semivariogram( P, lags, tolerance )