参考论文:      http://people.ku.edu/~gbohling/cpe940

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Kriging.py
# Created on: 2014-06-12 10:14:21.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# --------------------------------------------------------------------------- # Import arcpy module
import os
import math
import sys from pylab import *
import numpy as np
from pandas import DataFrame, Series
from scipy.spatial.distance import pdist, squareform # 计算距离 # dataXYV = [{"x":12100,"y":8300,"v":14.6515},{"x":5300,"y":8700,"v":14.5093},{"x":3500,"y":13900,"v":14.0639},{"x":5100,"y":1900,"v":15.1084},{"x":9900,"y":13700,"v":13.919},{"x":2900,"y":900,"v":13.1304},{"x":7900,"y":6700,"v":14.5724},{"x":16900,"y":4900,"v":15.0814},{"x":18700,"y":1500,"v":13.91},{"x":2700,"y":2100,"v":13.4024},{"x":10700,"y":5100,"v":14.9395},{"x":7500,"y":12900,"v":15.2159},{"x":5500,"y":11100,"v":14.5777},{"x":9500,"y":9100,"v":14.2483},{"x":15300,"y":3100,"v":14.4281},{"x":4700,"y":9700,"v":15.2606},{"x":16700,"y":15700,"v":16.1859},{"x":19500,"y":9700,"v":14.2079},{"x":16900,"y":13100,"v":16.9583},{"x":900,"y":3700,"v":13.8354},{"x":500,"y":11900,"v":14.1859},{"x":9100,"y":1300,"v":14.0381},{"x":9100,"y":13700,"v":14.3685},{"x":9900,"y":12900,"v":13.4018},{"x":6300,"y":100,"v":15.8953},{"x":3700,"y":5100,"v":12.8667},{"x":16300,"y":900,"v":15.1039},{"x":18300,"y":13500,"v":15.7736},{"x":9500,"y":6900,"v":14.1333},{"x":17900,"y":3100,"v":13.3369},{"x":9900,"y":15500,"v":15.1362},{"x":7100,"y":8900,"v":15.0847},{"x":19300,"y":7100,"v":14.2498},{"x":2300,"y":5700,"v":12.6811},{"x":7300,"y":8900,"v":14.9384},{"x":13900,"y":3700,"v":15.6005},{"x":8500,"y":10100,"v":13.7796},{"x":8100,"y":8700,"v":15.2907},{"x":14700,"y":11900,"v":15.6881},{"x":6300,"y":2300,"v":15.3677},{"x":11900,"y":12900,"v":14.3283},{"x":18100,"y":7100,"v":14.7374},{"x":11300,"y":7100,"v":15.0547},{"x":12500,"y":3100,"v":14.8889},{"x":2700,"y":12700,"v":14.436},{"x":2700,"y":4300,"v":12.1491},{"x":8500,"y":11300,"v":13.624},{"x":1500,"y":900,"v":14.188},{"x":7300,"y":1300,"v":14.9072},{"x":10700,"y":4100,"v":15.2029},{"x":7100,"y":1900,"v":15.3468},{"x":3900,"y":8500,"v":15.939},{"x":17100,"y":6100,"v":15.7269},{"x":14100,"y":10100,"v":15.3238},{"x":11500,"y":4900,"v":14.0445},{"x":13300,"y":15700,"v":14.4032},{"x":1900,"y":12100,"v":14.3586},{"x":15100,"y":2900,"v":14.6007},{"x":6500,"y":900,"v":16.1458},{"x":8900,"y":6100,"v":15.7727},{"x":4500,"y":2300,"v":13.6234},{"x":12900,"y":10300,"v":15.1024},{"x":10900,"y":5700,"v":15.3546},{"x":3500,"y":700,"v":13.8431},{"x":16300,"y":3700,"v":14.9427},{"x":900,"y":5100,"v":14.4139},{"x":12900,"y":12900,"v":13.6177},{"x":15300,"y":9300,"v":16.3787},{"x":7300,"y":6900,"v":14.258},{"x":16300,"y":12500,"v":15.7772},{"x":100,"y":8900,"v":14.6553},{"x":1700,"y":11700,"v":14.3627},{"x":17500,"y":11100,"v":15.9659},{"x":14900,"y":8300,"v":16.0095},{"x":8300,"y":10900,"v":13.9639},{"x":4100,"y":14500,"v":14.2649},{"x":11100,"y":15300,"v":15.7684},{"x":500,"y":4900,"v":14.591},{"x":13100,"y":1500,"v":15.1377},{"x":18900,"y":1700,"v":14.095},{"x":3500,"y":7500,"v":15.1486},{"x":3700,"y":6900,"v":13.9584},{"x":14500,"y":13300,"v":14.7381},{"x":4900,"y":9100,"v":15.0689},{"x":9700,"y":5700,"v":15.8042}]
dataXYV = [{"x":12100.00,"y":8300.00,"v":14.6515},
{"x":5300.00,"y":8700.00,"v":14.5093},
{"x":3500.00,"y":13900.00,"v":14.0639},
{"x":5100.00,"y":1900.00,"v":15.1084},
{"x":9900.00,"y":13700.00,"v":13.919},
{"x":2900.00,"y":900.00,"v":13.1304},
{"x":7900.00,"y":6700.00,"v":14.5724},
{"x":16900.00,"y":4900.00,"v":15.0814},
{"x":18700.00,"y":1500.00,"v":13.91},
{"x":2700.00,"y":2100.00,"v":13.4024},
{"x":10700.00,"y":5100.00,"v":14.9395},
{"x":7500.00,"y":12900.00,"v":15.2159},
{"x":5500.00,"y":11100.00,"v":14.5777},
{"x":9500.00,"y":9100.00,"v":14.2483},
{"x":15300.00,"y":3100.00,"v":14.4281},
{"x":4700.00,"y":9700.00,"v":15.2606},
{"x":16700.00,"y":15700.00,"v":16.1859},
{"x":19500.00,"y":9700.00,"v":14.2079},
{"x":16900.00,"y":13100.00,"v":16.9583},
{"x":900.00,"y":3700.00,"v":13.8354},
{"x":500.00,"y":11900.00,"v":14.1859},
{"x":9100.00,"y":1300.00,"v":14.0381},
{"x":9100.00,"y":13700.00,"v":14.3685},
{"x":9900.00,"y":12900.00,"v":13.4018},
{"x":6300.00,"y":100.00,"v":15.8953},
{"x":3700.00,"y":5100.00,"v":12.8667},
{"x":16300.00,"y":900.00,"v":15.1039},
{"x":18300.00,"y":13500.00,"v":15.7736},
{"x":9500.00,"y":6900.00,"v":14.1333},
{"x":17900.00,"y":3100.00,"v":13.3369},
{"x":9900.00,"y":15500.00,"v":15.1362},
{"x":7100.00,"y":8900.00,"v":15.0847},
{"x":19300.00,"y":7100.00,"v":14.2498},
{"x":2300.00,"y":5700.00,"v":12.6811},
{"x":7300.00,"y":8900.00,"v":14.9384},
{"x":13900.00,"y":3700.00,"v":15.6005},
{"x":8500.00,"y":10100.00,"v":13.7796},
{"x":8100.00,"y":8700.00,"v":15.2907},
{"x":14700.00,"y":11900.00,"v":15.6881},
{"x":6300.00,"y":2300.00,"v":15.3677},
{"x":11900.00,"y":12900.00,"v":14.3283},
{"x":18100.00,"y":7100.00,"v":14.7374},
{"x":11300.00,"y":7100.00,"v":15.0547},
{"x":12500.00,"y":3100.00,"v":14.8889},
{"x":2700.00,"y":12700.00,"v":14.436},
{"x":2700.00,"y":4300.00,"v":12.1491},
{"x":8500.00,"y":11300.00,"v":13.624},
{"x":1500.00,"y":900.00,"v":14.188},
{"x":7300.00,"y":1300.00,"v":14.9072},
{"x":10700.00,"y":4100.00,"v":15.2029},
{"x":7100.00,"y":1900.00,"v":15.3468},
{"x":3900.00,"y":8500.00,"v":15.939},
{"x":17100.00,"y":6100.00,"v":15.7269},
{"x":14100.00,"y":10100.00,"v":15.3238},
{"x":11500.00,"y":4900.00,"v":14.0445},
{"x":13300.00,"y":15700.00,"v":14.4032},
{"x":1900.00,"y":12100.00,"v":14.3586},
{"x":15100.00,"y":2900.00,"v":14.6007},
{"x":6500.00,"y":900.00,"v":16.1458},
{"x":8900.00,"y":6100.00,"v":15.7727},
{"x":4500.00,"y":2300.00,"v":13.6234},
{"x":12900.00,"y":10300.00,"v":15.1024},
{"x":10900.00,"y":5700.00,"v":15.3546},
{"x":3500.00,"y":700.00,"v":13.8431},
{"x":16300.00,"y":3700.00,"v":14.9427},
{"x":900.00,"y":5100.00,"v":14.4139},
{"x":12900.00,"y":12900.00,"v":13.6177},
{"x":15300.00,"y":9300.00,"v":16.3787},
{"x":7300.00,"y":6900.00,"v":14.258},
{"x":16300.00,"y":12500.00,"v":15.7772},
{"x":100.00,"y":8900.00,"v":14.6553},
{"x":1700.00,"y":11700.00,"v":14.3627},
{"x":17500.00,"y":11100.00,"v":15.9659},
{"x":14900.00,"y":8300.00,"v":16.0095},
{"x":8300.00,"y":10900.00,"v":13.9639},
{"x":4100.00,"y":14500.00,"v":14.2649},
{"x":11100.00,"y":15300.00,"v":15.7684},
{"x":500.00,"y":4900.00,"v":14.591},
{"x":13100.00,"y":1500.00,"v":15.1377},
{"x":18900.00,"y":1700.00,"v":14.095},
{"x":3500.00,"y":7500.00,"v":15.1486},
{"x":3700.00,"y":6900.00,"v":13.9584},
{"x":14500.00,"y":13300.00,"v":14.7381},
{"x":4900.00,"y":9100.00,"v":15.0689},
{"x":9700.00,"y":5700.00,"v":15.8042}] length = len(dataXYV)
distanceMatrix = [[] for i in range(length)]
index = 0
distTotal = 0;
distMin = 1.0e15
distMax = -1.0e15
distAver = 0
for x in dataXYV:
for y in dataXYV:
z = math.sqrt((x['x']-y['x'])*(x['x']-y['x'])+(x['y']-y['y'])*(x['y']-y['y']))
distTotal += z
if z > distMax:
distMax = z
if z < distMin and x != y:
distMin = z
distanceMatrix[index].append(z)
index += 1
distAver = distTotal / (length * length - length)
dataInfo = {'count':(length * length - length), 'distAver':distAver, 'distMin':distMin, 'distMax':distMax}
#print dataInfo '''
for i in range(0, length):
for j in range(0, length):
print(int(lists[i][j])),
print(';')
''' '''
查找点对
'''
def findPairs(dataXYV, distanceMatrix, minValue, maxValue):
totalDistance = 0;
count = 0;
minDistance = 1.0e15
maxDistance = -1.0e15
averageDistance = 0
pairs = []
for i in range(0, length):
for j in range(i+1, length):
if distanceMatrix[i][j]>minValue and distanceMatrix[i][j]<=maxValue:
#if math.fabs(dataXYV[i]['x']-dataXYV[j]['x'])>minValue and math.fabs(dataXYV[i]['y']-dataXYV[j]['y'])>minValue and math.fabs(dataXYV[i]['x']-dataXYV[j]['x'])<=maxValue and math.fabs(dataXYV[i]['y']-dataXYV[j]['y'])<=maxValue:
# print(int(lists[i][j])),
totalDistance += distanceMatrix[i][j]
count += 1
if distanceMatrix[i][j] >= maxDistance:
maxDistance = distanceMatrix[i][j]
if distanceMatrix[i][j] <= minDistance:
minDistance = distanceMatrix[i][j]
pair = {'i':i,'j':j,'iv':dataXYV[i]['v'],'jv':dataXYV[j]['v'],'dist':distanceMatrix[i][j]}
pairs.append(pair)
#print(count)
averageDistance = totalDistance / count
info = {'count':count, 'distAver':averageDistance, 'distMin':minDistance, 'distMax':maxDistance}
#print info
#print pairs
return pairs '''
计算统计信息: 协方差、相关系数、半方变异
'''
def computeStatisticInfo(pairs):
pairCount = len(pairs)
distanceTotal = 0
distanceAverage = 0
#
v1v2Total=0
v1Total=0
v2Total=0
#
v1v1Total=0
v2v2Total=0
#
v1_v2Total=0
#
for x in pairs:
val1 = x['iv']
val2 = x['jv']
distanceTotal = distanceTotal + x['dist']
v1v2Total = v1v2Total + val1 * val2
v1Total = v1Total + val1
v2Total = v2Total + val2
#
v1v1Total = v1v1Total + val1 * val1
v2v2Total = v2v2Total + val2 * val2
#
v1_v2Total = v1_v2Total + math.pow(val1 - val2, 2)
#
distanceAverage = distanceTotal / pairCount
v1v2Covariance = v1v2Total / pairCount - v1Total * v2Total / (pairCount * pairCount)
v1v2Corelation = (v1v2Total*pairCount - v1Total * v2Total) / math.sqrt(v1v1Total * pairCount - v1Total * v1Total) / math.sqrt(v2v2Total * pairCount - v2Total * v2Total)
v1v2Semivariance = v1_v2Total / (pairCount * 2)
statisticInfo = {'covariance':v1v2Covariance, 'corelation':v1v2Corelation, 'semivariance':v1v2Semivariance, 'count':pairCount, 'distAver':distanceAverage} #
# print statisticInfo
return statisticInfo '''
计算各种lagSize下的统计信息: 协方差、相关系数、半方变异
'''
def staticInfoAll(dataXYV, distanceMatrix, lagCellSize, lagCount):
semiLagCellSize = lagCellSize / 2
pairsStaticInfos = []
for i in range(0, lagCount-1): lagSize = lagCellSize * i
lagMin = lagSize - semiLagCellSize
if lagMin < 0:
lagMin = 0
lagMax = lagSize + semiLagCellSize
#print(lagMin, lagMax, lagSize) '''
lagMin = lagCellSize * i
lagMax = lagCellSize * (i + 1)
lagSize = (lagCellSize * i + lagCellSize * (i + 1))/2
#print lagMin, lagMax, lagSize
'''
pairs = findPairs(dataXYV, distanceMatrix, lagMin, lagMax)
statisticInfo = computeStatisticInfo(pairs)
statisticInfo['lagSize'] = lagSize
print(lagMin, lagMax, statisticInfo['lagSize'], statisticInfo['count'], statisticInfo['distAver'], statisticInfo['covariance'], statisticInfo['corelation'], statisticInfo['semivariance'])
pairsStaticInfos.append(statisticInfo)
return pairsStaticInfos
'''
def computeC0(dataXYV):
valueTotal = 0;
valueAver = 0;
variance = 0;
for x in dataXYV:
valueTotal += x['v']
valueAver = valueTotal / length
print valueAver
for x in dataXYV:
variance += math.pow((x['v'] - valueAver),2)
variance = variance / length
# variance = math.sqrt(variance)
print variance computeC0(dataXYV)
''' def optimization(pairsStaticInfos):
aMin = 0
cMin = 0
varianceTotalMin = 1.0e45
hSize = len(pairsStaticInfos)
for aValue in range( 3500, 4500):
for c1Value in range(60, 99):
cValue = c1Value / 100.0
#cValue = 0.78
#print(aValue, cValue)
#print(aValue, cValue)
varianceTotal = 0
for x in pairsStaticInfos:
y = spherical( x['distAver'], aValue, cValue ) # distAver lagSize
#print y, x['semivariance']
varianceTotal = varianceTotal + ((y - x['semivariance'])**2.0) * x['count']
varianceTotal = varianceTotal / hSize
#print varianceTotal
if varianceTotal <= varianceTotalMin:
varianceTotalMin = varianceTotal
aMin = aValue
cMin = cValue
#print(aMin, cMin, varianceTotalMin) para = {"a":aMin, "c0":cMin}
print(para)
return para def spherical( h, a, C0):
if h <= a:
return (C0*( 1.5*h/a - 0.5*(h/a)**3.0 ))
else:
return C0 pairsStaticInfos = staticInfoAll(dataXYV, distanceMatrix, 1000, 12) # 500, 25 para = optimization(pairsStaticInfos) lagSize = []
semivariance = []
modelY = []
modelYY = []
#
lagSize.append(0)
semivariance.append(0)
modelY.append(0)
for x in pairsStaticInfos:
y = spherical( x['distAver'], para['a'], para['c0'] )
#yy= spherical( x['distAver'], 4141, para['c0'] )
lagSize.append(x['distAver'])
semivariance.append(x['semivariance'])
modelY.append(y)
modelYY.append(yy) plot( lagSize, semivariance, 'o' )
plot( lagSize, modelY, '.-' ) ;
title('Spherical Model')
ylabel('Semivariance')
xlabel('Lag [m]')

Kriging插值计算的更多相关文章

  1. Matlab插值计算各时刻磁法勘探日变观测值

    Matlab插值计算各时刻磁法勘探日变观测值 在磁法勘探中,消日变影响的改正称为日变改正.进行日变改正时必须设立日变站,观测日变情况.根据日变数据和测点观测时间,对观测数据进行改正. 在本次磁法实习中 ...

  2. (转)Unity3D 之插值计算

    在unity3D中经常用线性插值函数Lerp()来在两者之间插值,两者之间可以是两个材质之间.两个向量之间.两个浮点数之间.两个颜色之间,其函数原型如下: Material.Lerp 插值 funct ...

  3. Swift字符串插值

    字符串插值是一种全新的构建字符串的方式,可以在其中包含常量.变量.字面量和表达式.您插入的字符串字面量的每一项都被包裹在以反斜线为前缀的圆括号中: let multiplier = let messa ...

  4. Tetrahedron based light probe interpolation(基于四面体的Light Probe插值)

    在当前的游戏引擎中,使用Light Probe来计算全局环境光对于动态物体的影响是一种很主流的方法.在预处理阶段生成完场景的Light Probe之后,传统的方法采用查找最近的8个相邻的Probe然后 ...

  5. 插值技术之Bezier插值(1) -- Bezier Curve

    作者:i_dovelemon 来源:CSDN 日期:2015 / 7 / 11 主题:Interpolate,Bezier Curve 引言 在游戏开发中.诸如动画系统.路径计算等等操作,都会遇到对数 ...

  6. 基于GDAL的栅格图像空间插值预处理

    转自 基于GDAL的栅格图像空间插值预处理——C语言版 基于GDAL的栅格图像预处理 前言 栅格数据和矢量数据构成空间数据的主要来源,怎样以开源方式读取并处理这些空间数据?目前有多种开源支持包,这里只 ...

  7. 从零开始一起学习SLAM | 用四元数插值来对齐IMU和图像帧

    视觉 Vs. IMU 小白:师兄,好久没见到你了啊,我最近在看IMU(Inertial Measurement Unit,惯性导航单元)相关的东西,正好有问题求助啊 师兄:又遇到啥问题啦? 小白:是这 ...

  8. three.js使用gpu选取物体并计算交点位置

    光线投射法 使用three.js自带的光线投射器(Raycaster)选取物体非常简单,代码如下所示: var raycaster = new THREE.Raycaster(); var mouse ...

  9. 【bzoj4559】[JLoi2016]成绩比较(dp+拉格朗日插值)

    bzoj 题意: 有\(n\)位同学,\(m\)门课. 一位同学在第\(i\)门课上面获得的分数上限为\(u_i\). 定义同学\(A\)碾压同学\(B\)为每一课\(A\)同学的成绩都不低于\(B\ ...

随机推荐

  1. Unity 自动生成组件索引类工具

    Unity 自动生成组件索引类工具 需求由来 我们在写UI类时 需要获取预设中的组件 joystick = transform.Find("joystick"); backgrou ...

  2. 【xsy2748】 fly 矩阵快速幂

    题目大意:有$n$个点,$m$条有向边,其中第$i$条边需要在$t_i$秒后才出现在图上. 有一个人刚开始呆在$1$号节点,每秒钟他必须要选择一条从他所在位置走出去的边,走出去(如果没有的话这人就死了 ...

  3. Newtonsoft.Json 序列化 排除指定字段或只序列化指定字段

    using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using System; using System.Collections.G ...

  4. Ejb3 + Jboss8 出现Session id hasn't been set for stateful component

    Ejb 3 + JBoss 8  在使用客户端远程访问有状态的Ejb对象时,出现ERROR: Session id hasn't been set for stateful component 出现该 ...

  5. android Butter Knife 使用详解

    Butter Knife github连接:https://github.com/JakeWharton/butterknife 本文使用的butterknife版本7.0.1 butterknife ...

  6. Chapter 3 Phenomenon——6

    A low oath made me aware that someone was with me, and the voice was impossible not to recognize. 某人 ...

  7. 广州.NET俱乐部简介

    广州.NET俱乐部 简介 广州 .NET 俱乐部自2018年底重新在广州地区活跃. 目前已经成功在广州.深圳.苏州和东莞组织并参与了多长线下技术交流活动. 已经有超过1200+人加入了俱乐部线上社区. ...

  8. centos7 Mariadb5.5升级到Mariadb10.2

    一次升级过程,在此记录下. 原因:新的项目需要新的数据库版本支持. 升级主要步骤: 备份原数据库 --->卸载mariadb --->添加mariadb国内yum源 --->安装ma ...

  9. java.lang.ArithmeticException: Rounding necessary

    这个错误就是精度丢失问题 https://blog.csdn.net/qq496013218/article/details/70792655

  10. 前端JS校验银行卡卡号和身份证号码(附ES6版方法)

    1.银行卡卡号校验方法. function luhnCheck(bankno) { var lastNum = bankno.substr(bankno.length - 1, 1); //取出最后一 ...