使用“matplotlib.mlab.griddata”时程序挂起

时间:2011-04-11 01:31:01

标签: python grid matplotlib contour

我已经编写了一个脚本(Python 2.6)到x,y,z(.csv格式)的网格数据,并显示数据的等高线图。

该脚本适用于某些数据集,但不适用于其他数据集 - 即使两个数据集都是使用相同的脚本创建的。

要绘制的数据集是通过从主数据集中进行二次采样来创建的。

以下是every_4.csv的示例(每4行子采样的主数据集)。

Easting Northing    TMI_nT 
526243.0    5254128.9   62278.8
526259.4    5254128.9   62352.3
526275.9    5254128.9   62303.3
526292.3    5254128.9   62361.9
526308.8    5254128.9   62667.8
526325.2    5254128.9   62668.6
526341.7    5254128.9   61700.1
526358.1    5254128.9   62029.6
526374.6    5254128.9   62042.7

此数据使用我的脚本正确绘制。

“every_3.csv”与every_4.csv的格式相同导致我的脚本在尝试执行时挂起(没有错误消息):

  

zi = griddata(x,y,z,xi,yi)

这是我正在使用的脚本:

### program to test gridding and contouring

import numpy as N
import scipy as S
from matplotlib.mlab import griddata
import matplotlib.pyplot as P
import matplotlib.cm as CM

longarray = N.loadtxt('every_3.csv', skiprows=1, delimiter=',')
x = longarray[:,0]
y = longarray[:,1]
z = longarray[:,2]

max_x = max(x)
min_x = min(x)
max_y = max(y)
min_y = min(y)

##print max_y
##print min_x
##print max_x
##print min_y

xi = N.linspace(min_x, max_x)
yi = N.linspace(min_y, max_y)

zi = griddata(x, y, z, xi, yi)
print zi
CS = P.contourf(xi,yi,zi,15,cmap=CM.RdYlBu)

P.show()

我无法弄清楚为什么这个脚本会挂起某些文件而不是其他文件。

注意:如果我打开excel中的every_3.csv并删除一些行(比如说文件中50%的行),我可以让脚本运行...

更新

这是一个更完整的数据集:

Easting Northing    TMI_nT
526243  5254128.9   62278.8
526247.1    5254128.9   62413.3
526251.2    5254128.9   62398.6
526255.3    5254128.9   62355.7
526259.4    5254128.9   62352.3
526263.6    5254128.9   62327.8
526267.7    5254128.9   62279.6
526271.8    5254128.9   62322.1
526275.9    5254128.9   62303.3
526280  5254128.9   62375.1
526284.1    5254128.9   62561.4
526288.2    5254128.9   62302.4
526292.3    5254128.9   62361.9
526374.6    5254128.9   62042.7
526378.7    5254128.9   62139.6
526382.8    5254128.9   61891.5
526386.9    5254128.9   61937.2
526391  5254128.9   62238.7
526395.1    5254128.9   62344.9
526399.2    5254128.9   62220.4
526403.3    5254128.9   62027
526407.4    5254128.9   62392.2
526411.6    5254128.9   63252.4
526415.7    5254128.9   62951.8
526419.8    5254128.9   62504.5
526423.9    5254128.9   62927.6
526428  5254128.9   62813.9
526432.1    5254128.9   63381.4
526436.2    5254128.9   63458.5
526440.3    5254128.9   63273
526444.4    5254128.9   62945
526448.6    5254128.9   62466.2
526452.7    5254128.9   62300.3
526456.8    5254128.9   62164.3
526460.9    5254128.9   62144.7
526465  5254128.9   62216.7
526469.1    5254128.9   62307.3
526473.2    5254128.9   62437.6
526477.3    5254128.9   62495
526481.4    5254128.9   62256.1
526485.6    5254128.9   61951.2
526489.7    5254128.9   61632
526493.8    5254128.9   61221.6
526497.9    5254128.9   62414.3
526502  5254128.9   64152.7
526506.1    5254128.9   61964.7
526510.2    5254128.9   61952.5
526514.3    5254128.9   62104.2
526518.4    5254128.9   62190.4
526522.6    5254128.9   62334.8
526526.7    5254128.9   62468.8
526530.8    5254128.9   62437.3
526296.4    5253951.8   62138
526300.6    5253951.8   62283.3
526304.7    5253951.8   62336
526308.8    5253951.8   62367.6
526312.9    5253951.8   62416
526317  5253951.8   62395.3
526321.1    5253951.8   62364.1
526325.2    5253951.8   62363.2
526329.3    5253951.8   62292.6
526333.4    5253951.8   62252
526337.6    5253951.8   62179.1
526341.7    5253951.8   62086.8
526345.8    5253951.8   62069.6
526349.9    5253951.8   62108.4
526354  5253951.8   61994
526358.1    5253951.8   61909.1
526362.2    5253951.8   61943.1
526366.3    5253951.8   61918.6
526370.4    5253951.8   61895.9
526374.6    5253951.8   61871.6
526378.7    5253951.8   61821.4
526382.8    5253951.8   61778.1
526386.9    5253951.8   61738.2
526391  5253951.8   61644.5
526395.1    5253951.8   61555.8
526399.2    5253951.8   61540
526403.3    5253951.8   61549.6
526407.4    5253951.8   61596.4
526411.6    5253951.8   61566.5
526415.7    5253951.8   61565.1
526419.8    5253951.8   61287.6
526423.9    5253951.8   61368
526428  5253951.8   61481.5
526432.1    5253951.8   61228.8
526436.2    5253951.8   61024.6
526440.3    5253951.8   60960.9
526444.4    5253951.8   61146.7
526448.6    5253951.8   61240.8
526452.7    5253951.8   61396.5
526456.8    5253951.8   61536.9
526460.9    5253951.8   61677.1
526465  5253951.8   61715.6
526469.1    5253951.8   61749.8
526473.2    5253951.8   61809.1
526477.3    5253951.8   61939.2
526481.4    5253951.8   61913.3
526485.6    5253951.8   62035.7
526489.7    5253951.8   62108.9
526493.8    5253951.8   62025.4
526497.9    5253951.8   61929.1
526502  5253951.8   61947.2
526506.1    5253951.8   62182.8
526510.2    5253951.8   62239.3
526514.3    5253951.8   62071.7
526518.4    5253951.8   62054.5
526522.6    5253951.8   62001.3
526526.7    5253951.8   61993.5
526530.8    5253951.8   62009.3
526534.9    5253951.8   61966.5
526539  5253951.8   61947.2
526543.1    5253951.8   61936.4
526547.2    5253951.8   61974
526551.3    5253951.8   62023.6
526555.4    5253951.8   62068.7
526559.6    5253951.8   62096.1
526563.7    5253951.8   62113.4
526567.8    5253951.8   62085.1
526571.9    5253951.8   62100.7
526576  5253951.8   62180.1
526580.1    5253951.8   62231.8
526584.2    5253951.8   62142.9
526588.3    5253951.8   62137.1
526592.4    5253951.8   62135.4
526596.6    5253951.8   62118.5
526600.7    5253951.8   62104.9
526604.8    5253951.8   62126.5
526608.9    5253951.8   62129.7
526613  5253951.8   62127
526617.1    5253951.8   62122.8
526621.2    5253951.8   62091.5
526625.3    5253951.8   62143.7
526629.4    5253951.8   62144.2
526633.6    5253951.8   62148.1
526637.7    5253951.8   62145.6
526641.8    5253951.8   62247.1
526645.9    5253951.8   62267.5
526650  5253951.8   62131.8
526243  5253955.9   62073.3
526247.1    5253955.9   62018.5
526251.2    5253955.9   61948.4
526255.3    5253955.9   61965.1
526259.4    5253955.9   61980.3
526263.6    5253955.9   61982.2
526267.7    5253955.9   61985.3
526271.8    5253955.9   61979.6
526275.9    5253955.9   61999.4
526280  5253955.9   62025.7
526284.1    5253955.9   62064.8
526288.2    5253955.9   62068.6
526292.3    5253955.9   62099.2
526296.4    5253955.9   62172.6
526300.6    5253955.9   62283.8
526304.7    5253955.9   62440.8
526308.8    5253955.9   62458.1
526312.9    5253955.9   62588.3
526317  5253955.9   62521.1
526321.1    5253955.9   62390.8
526325.2    5253955.9   62310.4
526329.3    5253955.9   62271
526333.4    5253955.9   62214.3
526337.6    5253955.9   62118.8
526341.7    5253955.9   62024.5
526345.8    5253955.9   61989.4
526349.9    5253955.9   61943.5
526354  5253955.9   61835.8

526506.1    5253955.9   61915.8
526510.2    5253955.9   62043
526514.3    5253955.9   62039.2
526518.4    5253955.9   62021.1
526522.6    5253955.9   62014
526526.7    5253955.9   61930.3
526530.8    5253955.9   61880.7
526534.9    5253955.9   61758.4
526539  5253955.9   61733.5
526543.1    5253955.9   61787.5
526547.2    5253955.9   61862.6
526551.3    5253955.9   61934.6
526555.4    5253955.9   61990.5
526559.6    5253955.9   62059.5
526563.7    5253955.9   62092
526567.8    5253955.9   62104.3
526571.9    5253955.9   62146.3
526576  5253955.9   62242.9
526580.1    5253955.9   62420.5
526584.2    5253955.9   62204.1
526588.3    5253955.9   62178.4
526592.4    5253955.9   62159
526596.6    5253955.9   62147.1
526600.7    5253955.9   62159.6
526604.8    5253955.9   62144.3
526608.9    5253955.9   62131.1
526613  5253955.9   62121.7
526617.1    5253955.9   62117.9
526621.2    5253955.9   62084.7
526625.3    5253955.9   62139.2
526629.4    5253955.9   62136.5
526633.6    5253955.9   62142
526637.7    5253955.9   62144.3
526641.8    5253955.9   62250.2
526645.9    5253955.9   62274.5
526650  5253955.9   62119
526243  5253960 62104
526247.1    5253960 62041.8
526251.2    5253960 61978.7
526255.3    5253960 61993.8
526259.4    5253960 61998.6
526263.6    5253960 61981
526267.7    5253960 61982
526271.8    5253960 61995.3
526275.9    5253960 62010.1
526280  5253960 62030.7
526284.1    5253960 62061.3
526288.2    5253960 62089.9
526292.3    5253960 62115.6
526296.4    5253960 62205.4
526300.6    5253960 62319.9
526304.7    5253960 62392.1
526308.8    5253960 62434.8
526312.9    5253960 62466.7
526317  5253960 62479.9
526321.1    5253960 62358.1
526325.2    5253960 62281.7
526329.3    5253960 62214.8
526333.4    5253960 62131.9
526382.8    5253960 61613.3
526386.9    5253960 61591.6
526391  5253960 61406.2
526395.1    5253960 61179.4
526399.2    5253960 61291.8
526403.3    5253960 61307.2
526407.4    5253960 61304.3
526411.6    5253960 61320.5
526415.7    5253960 61376.8
526419.8    5253960 61160.5
526423.9    5253960 61045.8
526428  5253960 61138.2
526432.1    5253960 61113.1
526436.2    5253960 60926.6
526440.3    5253960 60793.8
526444.4    5253960 60775.6
526448.6    5253960 60776.9
526452.7    5253960 60979.6
526456.8    5253960 61309.1
526460.9    5253960 61772.9
526465  5253960 61665.1
526469.1    5253960 61554.1
526473.2    5253960 61569.5
526477.3    5253960 61725.2
526481.4    5253960 61846
526485.6    5253960 61948.4
526489.7    5253960 61944.3
526493.8    5253960 61848
526497.9    5253960 61677.3
526502  5253960 61516.1
526506.1    5253960 61634.4
526510.2    5253960 61884.9
526514.3    5253960 61975.8
526518.4    5253960 61909.8
526522.6    5253960 61905.6
526526.7    5253960 61835
526530.8    5253960 61692.3
526534.9    5253960 61408.4
526539  5253960 61533.9
526543.1    5253960 61670.4
526547.2    5253960 61785.9
526551.3    5253960 61878.6
526555.4    5253960 61963.3
526559.6    5253960 62048.6
526563.7    5253960 62070.7
526567.8    5253960 62099.5
526571.9    5253960 62140.9
526576  5253960 62242.6
526580.1    5253960 62255
526584.2    5253960 62171.5
526588.3    5253960 62180.7
526592.4    5253960 62164.1
526596.6    5253960 62158.9
526600.7    5253960 62147.7
526604.8    5253960 62146.6
526608.9    5253960 62129
526613  5253960 62122.5
526617.1    5253960 62114.6
526621.2    5253960 62080.8
526625.3    5253960 62140.4
526629.4    5253960 62142.5
526633.6    5253960 62149.3
526637.7    5253960 62152
526641.8    5253960 62263.4
526645.9    5253960 62291.9
526650  5253960 62286.3
526243  5253964.1   62092
526247.1    5253964.1   62041.8
526251.2    5253964.1   61978.3
526255.3    5253964.1   62000.1
526259.4    5253964.1   62012.2
526263.6    5253964.1   62027.1
526267.7    5253964.1   62001.6
526271.8    5253964.1   62003.2
526275.9    5253964.1   61988.3
526280  5253964.1   62028.8
526284.1    5253964.1   62056.9
526288.2    5253964.1   62075.6
526292.3    5253964.1   62149.4
526296.4    5253964.1   62248
526300.6    5253964.1   62365.5
526555.4    5253964.1   61980.9
526559.6    5253964.1   62035.4
526563.7    5253964.1   62055.7
526567.8    5253964.1   62100.7
526571.9    5253964.1   62146.3
526576  5253964.1   62199
526580.1    5253964.1   62195.8
526584.2    5253964.1   62152.1
526588.3    5253964.1   62147.5
526592.4    5253964.1   62192.7
526596.6    5253964.1   62123.1
526600.7    5253964.1   62114
526604.8    5253964.1   62115.9
526608.9    5253964.1   62108.7
526613  5253964.1   62106.3
526617.1    5253964.1   62101.6
526621.2    5253964.1   62065.8
526625.3    5253964.1   62131
526629.4    5253964.1   62133.5
526633.6    5253964.1   62139.8
526637.7    5253964.1   62143
526641.8    5253964.1   62245.9
526645.9    5253964.1   62265.8
526650  5253964.1   62302.6
526243  5253968.3   62086
526247.1    5253968.3   62035.9
526251.2    5253968.3   61980
526255.3    5253968.3   61995.1
526259.4    5253968.3   62021.7
526263.6    5253968.3   62012.6
526267.7    5253968.3   61992.3
526271.8    5253968.3   62024.4
526275.9    5253968.3   61968.1
526280  5253968.3   62030.8
526284.1    5253968.3   62045.5
526288.2    5253968.3   62092.9
526292.3    5253968.3   62189.2
526296.4    5253968.3   62316.8
526300.6    5253968.3   62476.9
526304.7    5253968.3   62513.2
526308.8    5253968.3   62437.8
526312.9    5253968.3   62356.8
526317  5253968.3   62305.8
526321.1    5253968.3   62248.8
526325.2    5253968.3   62187.3
526329.3    5253968.3   62115.2
526333.4    5253968.3   62031
526337.6    5253968.3   62028.7
526341.7    5253968.3   61980.8
526345.8    5253968.3   61979.9
526349.9    5253968.3   61825.2
526354  5253968.3   61721.9
526358.1    5253968.3   61733.8
526362.2    5253968.3   61654.4
526366.3    5253968.3   61493.2
526370.4    5253968.3   61363.9
526374.6    5253968.3   61270.6
526378.7    5253968.3   61302.3
526382.8    5253968.3   61352.9
526386.9    5253968.3   61309
526391  5253968.3   61151.5
526395.1    5253968.3   60971.2
526399.2    5253968.3   60867.7
526403.3    5253968.3   60888.3
526407.4    5253968.3   60935
526411.6    5253968.3   60938.5
526415.7    5253968.3   61003.7
526419.8    5253968.3   61103.4
526423.9    5253968.3   60876.9
526428  5253968.3   60551.8
526432.1    5253968.3   60572.6
526436.2    5253968.3   60717
526440.3    5253968.3   60755.9
526444.4    5253968.3   60572.4
526448.6    5253968.3   60121.9
526563.7    5253968.3   62039.3
526567.8    5253968.3   62088.7
526571.9    5253968.3   62134.1
526576  5253968.3   62154.3
526580.1    5253968.3   62181.4
526584.2    5253968.3   62209.6
526588.3    5253968.3   62200.7
526592.4    5253968.3   62210.8
526596.6    5253968.3   62184.9
526600.7    5253968.3   62175.3
526604.8    5253968.3   62120.9
526608.9    5253968.3   62105.4
526613  5253968.3   62100.4
526617.1    5253968.3   62089.4
526621.2    5253968.3   62048.4
526625.3    5253968.3   62109.9
526629.4    5253968.3   62118.6
526633.6    5253968.3   62114.2
526637.7    5253968.3   62122.6
526641.8    5253968.3   62244.9
526645.9    5253968.3   62267.5
526650  5253968.3   62310.7
526243  5253972.4   62069.2
526247.1    5253972.4   62038.8
526251.2    5253972.4   62000.6
526255.3    5253972.4   62021.2
526259.4    5253972.4   62007
526263.6    5253972.4   62003.1
526267.7    5253972.4   62021.6
526271.8    5253972.4   62052.7
526275.9    5253972.4   62073.4
526280  5253972.4   62056.2
526284.1    5253972.4   62089.7
526288.2    5253972.4   62148.2
526292.3    5253972.4   62244.1
526296.4    5253972.4   62372
526300.6    5253972.4   62451.7
526304.7    5253972.4   62476
526308.8    5253972.4   62392.1
526312.9    5253972.4   62354.4
526317  5253972.4   62276.2
526321.1    5253972.4   62209.1
526325.2    5253972.4   62164.2
526329.3    5253972.4   62089.1
526333.4    5253972.4   62038.1
526337.6    5253972.4   61983.1
526341.7    5253972.4   61910.2
526345.8    5253972.4   61794.9
526349.9    5253972.4   61654
526354  5253972.4   61547
526358.1    5253972.4   61532.1
526362.2    5253972.4   61464.3
526366.3    5253972.4   61343.5
526370.4    5253972.4   61173
526374.6    5253972.4   61061.3
526378.7    5253972.4   61041.7
526382.8    5253972.4   61234.2
526386.9    5253972.4   61196.5
526391  5253972.4   61047.1
526395.1    5253972.4   60856.4
526399.2    5253972.4   60764.9
526403.3    5253972.4   60778.6
526407.4    5253972.4   60836.6
526411.6    5253972.4   60887.4
526415.7    5253972.4   61012
526419.8    5253972.4   61134.9
526423.9    5253972.4   60972.7
526428  5253972.4   60599.3
526432.1    5253972.4   60154.9
526436.2    5253972.4   60802.8
526440.3    5253972.4   60958.2
526444.4    5253972.4   60530.1
526448.6    5253972.4   60229.9
526452.7    5253972.4   60197.6
526456.8    5253972.4   60425.8
526460.9    5253972.4   60450.8
526465  5253972.4   59787.6
526469.1    5253972.4   59404.4
526473.2    5253972.4   60447.7
526477.3    5253972.4   61011.9
526481.4    5253972.4   61304
526485.6    5253972.4   61404
526489.7    5253972.4   61431.8
526493.8    5253972.4   61455.5
526497.9    5253972.4   61489.8
526502  5253972.4   61445.9
526506.1    5253972.4   61581.3
526510.2    5253972.4   61723.1
526514.3    5253972.4   61744.5
526518.4    5253972.4   61759.3
526522.6    5253972.4   61651.6
526526.7    5253972.4   61357.4
526530.8    5253972.4   61088.1
526534.9    5253972.4   61505.6
526539  5253972.4   61793.5
526543.1    5253972.4   61846.8
526547.2    5253972.4   61890.7
526551.3    5253972.4   61929
526555.4    5253972.4   61953.5
526559.6    5253972.4   62004
526563.7    5253972.4   62017.1
526567.8    5253972.4   62069.5
526571.9    5253972.4   62119.6
526576  5253972.4   62142.3
526580.1    5253972.4   62190.1
526584.2    5253972.4   62239.9
526588.3    5253972.4   62268.3
526592.4    5253972.4   62257.5
526596.6    5253972.4   62212.8
526600.7    5253972.4   62193.3
526604.8    5253972.4   62137
526608.9    5253972.4   62084.3
526613  5253972.4   62075.9
526617.1    5253972.4   62072.8
526621.2    5253972.4   62030.6
526625.3    5253972.4   62100.9
526629.4    5253972.4   62107.4
526633.6    5253972.4   62124.6
526637.7    5253972.4   62140.9
526641.8    5253972.4   62249.8
526645.9    5253972.4   62275.2
526650  5253972.4   62325
526243  5253976.5   62069.2
526247.1    5253976.5   62037.5
526251.2    5253976.5   61984.2
526255.3    5253976.5   62000.4
526259.4    5253976.5   62020.3
526263.6    5253976.5   62019.6
526267.7    5253976.5   62028.1
526271.8    5253976.5   62079.9
526275.9    5253976.5   62095.9
526280  5253976.5   62084.5
526284.1    5253976.5   62129.4
526288.2    5253976.5   62203.6
526292.3    5253976.5   62304.3
526296.4    5253976.5   62380.6
526300.6    5253976.5   62398
526304.7    5253976.5   62358.6
526308.8    5253976.5   62323.8
526312.9    5253976.5   62283
526317  5253976.5   62240.6
526321.1    5253976.5   62175.5
526325.2    5253976.5   62113.9
526329.3    5253976.5   62021.2
526333.4    5253976.5   61958.1
526337.6    5253976.5   61902.3
526341.7    5253976.5   61846.7
526345.8    5253976.5   61647.2
526349.9    5253976.5   61442.7
526354  5253976.5   61346.2
526358.1    5253976.5   61387.1
526362.2    5253976.5   61324.2
526366.3    5253976.5   61168.7
526370.4    5253976.5   61043.5
526374.6    5253976.5   60854.9
526378.7    5253976.5   60797.1
526382.8    5253976.5   60889.2
526386.9    5253976.5   60915.6
526391  5253976.5   60822.2
526395.1    5253976.5   60760.4
526399.2    5253976.5   60700.1
526403.3    5253976.5   60540.3
526407.4    5253976.5   60525.5
526411.6    5253976.5   60693.8
526415.7    5253976.5   60905.6
526419.8    5253976.5   61065.2
526423.9    5253976.5   60992.9
526428  5253976.5   60873.2
526432.1    5253976.5   60135.2
526436.2    5253976.5   60421.8
526440.3    5253976.5   60699.9
526444.4    5253976.5   60422.8
526448.6    5253976.5   60075.5
526452.7    5253976.5   59948.4
526456.8    5253976.5   60170.3
526460.9    5253976.5   60534
526465  5253976.5   59849.7
526469.1    5253976.5   59221.9
526473.2    5253976.5   59961.2
526477.3    5253976.5   60589
526481.4    5253976.5   60958.8
526485.6    5253976.5   61166
526489.7    5253976.5   61296.1
526493.8    5253976.5   61335.3
526497.9    5253976.5   61448
526502  5253976.5   61423.1
526506.1    5253976.5   61574.7
526510.2    5253976.5   61769.1
526514.3    5253976.5   61774.9
526518.4    5253976.5   61847.8
526522.6    5253976.5   61888.6
526526.7    5253976.5   61915.7
526530.8    5253976.5   61965.2
526534.9    5253976.5   61939
526539  5253976.5   61954.5
526543.1    5253976.5   61935.2
526547.2    5253976.5   61942.9
526551.3    5253976.5   61951.1
526555.4    5253976.5   61998.7
526559.6    5253976.5   61981.4
526563.7    5253976.5   61991.2
526567.8    5253976.5   62052.1
526571.9    5253976.5   62141.2
526576  5253976.5   62167.5
526580.1    5253976.5   62175.5
526584.2    5253976.5   62277.2
526588.3    5253976.5   62363.1
526592.4    5253976.5   62262.3
526596.6    5253976.5   62178.3
526600.7    5253976.5   62151.2
526604.8    5253976.5   62143.3
526608.9    5253976.5   62092.3
526613  5253976.5   62073.4
526617.1    5253976.5   62072.3
526621.2    5253976.5   62030.2
526625.3    5253976.5   62096.5
526629.4    5253976.5   62110.7
526633.6    5253976.5   62115.6
526637.7    5253976.5   62139
526641.8    5253976.5   62251.8
526645.9    5253976.5   62277.1
526650  5253976.5   62337.3
526243  5253980.6   62066.3
526247.1    5253980.6   62048
526251.2    5253980.6   62002.1
526255.3    5253980.6   62005.9
526259.4    5253980.6   62016.9
526263.6    5253980.6   62024
526267.7    5253980.6   62054.9
526271.8    5253980.6   62109.2
526275.9    5253980.6   62090.7
526280  5253980.6   62121.7
526284.1    5253980.6   62169.8
526288.2    5253980.6   62245.1
526292.3    5253980.6   62311.2
526296.4    5253980.6   62336.4
526300.6    5253980.6   62305.7
526304.7    5253980.6   62294.3
526308.8    5253980.6   62252.1
526312.9    5253980.6   62203
526317  5253980.6   62172.3
526321.1    5253980.6   62097.8
526325.2    5253980.6   62031.2
526329.3    5253980.6   61944.4
526333.4    5253980.6   61889.2
526337.6    5253980.6   61820.7
526341.7    5253980.6   61742.6
526345.8    5253980.6   61514
526349.9    5253980.6   61344.2
526354  5253980.6   61245.2
526358.1    5253980.6   61238.2
526362.2    5253980.6   61181.5
526366.3    5253980.6   61034
526370.4    5253980.6   60946.3
526374.6    5253980.6   60761.3
526378.7    5253980.6   60579.3
526382.8    5253980.6   60575.5
526386.9    5253980.6   60797.7
526391  5253980.6   60773.6
526395.1    5253980.6   60771.5
526399.2    5253980.6   60727.6
526403.3    5253980.6   60545.5
526407.4    5253980.6   60405.8
526411.6    5253980.6   60482.8
526415.7    5253980.6   60903.6
526419.8    5253980.6   61087.6
526423.9    5253980.6   61206.6
526428  5253980.6   61175.3
526432.1    5253980.6   60749.5
526436.2    5253980.6   60558.7
526440.3    5253980.6   60418
526444.4    5253980.6   60293.5
526448.6    5253980.6   60012
526452.7    5253980.6   59445.5
526456.8    5253980.6   59617.3
526460.9    5253980.6   60258.1
526465  5253980.6   60222.1
526469.1    5253980.6   59939.5
526473.2    5253980.6   60081.4
526477.3    5253980.6   60348.9
526481.4    5253980.6   60695.2
526485.6    5253980.6   60930.1
526489.7    5253980.6   61133.6
526493.8    5253980.6   61264.2
526497.9    5253980.6   61349.5
526502  5253980.6   61355.8
526506.1    5253980.6   61398.3
526510.2    5253980.6   61698.9
526514.3    5253980.6   61786.7
526518.4    5253980.6   61866.2
526522.6    5253980.6   62075.3
526526.7    5253980.6   62405.3
526530.8    5253980.6   62759.8
526534.9    5253980.6   62307.7
526539  5253980.6   62091.4
526543.1    5253980.6   61996.8
526547.2    5253980.6   61953.2
526551.3    5253980.6   61935.6
526555.4    5253980.6   61932.6
526559.6    5253980.6   61922.5
526563.7    5253980.6   61940.6
526567.8    5253980.6   61991.2
526571.9    5253980.6   62040.7
526576  5253980.6   62075.9
526580.1    5253980.6   62104.3
526584.2    5253980.6   62151.5
526588.3    5253980.6   62193.7
526592.4    5253980.6   62166.6
526596.6    5253980.6   62121.4
526600.7    5253980.6   62098.5
526604.8    5253980.6   62100
526608.9    5253980.6   62070.9
526613  5253980.6   62061.9
526617.1    5253980.6   62064.2
526621.2    5253980.6   62018.3
526625.3    5253980.6   62088.8
526629.4    5253980.6   62102.2
526633.6    5253980.6   62107.7
526637.7    5253980.6   62133.7
526641.8    5253980.6   62251.3
526645.9    5253980.6   62280.6
526650  5253980.6   62348
526243  5253984.7   62070.5
526247.1    5253984.7   62032.9
526251.2    5253984.7   61995.8
526255.3    5253984.7   62013.9
526259.4    5253984.7   62021.1
526263.6    5253984.7   62031.5
526267.7    5253984.7   62062.8
526271.8    5253984.7   62111.6
526275.9    5253984.7   62114.9
526280  5253984.7   62139
526284.1    5253984.7   62200.9
526288.2    5253984.7   62248.8
526292.3    5253984.7   62278.6
526296.4    5253984.7   62268.5
526300.6    5253984.7   62259.9
526304.7    5253984.7   62234.8
526308.8    5253984.7   62189.8
526312.9    5253984.7   62159.2
526317  5253984.7   62085
526321.1    5253984.7   62005
526325.2    5253984.7   61934.3
526329.3    5253984.7   61855.4
526333.4    5253984.7   61811.4
526337.6    5253984.7   61785.8
526341.7    5253984.7   61567.1
526345.8    5253984.7   61412.7
526349.9    5253984.7   61300.2
526354  5253984.7   61168
526358.1    5253984.7   61129.6
526362.2    5253984.7   61029.5
526366.3    5253984.7   60792.3
526370.4    5253984.7   60739
526374.6    5253984.7   60601.2
526378.7    5253984.7   60352.3
526382.8    5253984.7   60250.4
526386.9    5253984.7   60371.7
526391  5253984.7   60576.7
526395.1    5253984.7   60709.4
526399.2    5253984.7   60647.8
526403.3    5253984.7   60407.7
526407.4    5253984.7   60270.3
526411.6    5253984.7   60235.8
526415.7    5253984.7   60576.9
526419.8    5253984.7   60782.5
526423.9    5253984.7   61177.2
526428  5253984.7   61308.1
526432.1    5253984.7   61268.4
526436.2    5253984.7   60831.1
526440.3    5253984.7   60244.9
526444.4    5253984.7   60060.9
526448.6    5253984.7   60139.4
526452.7    5253984.7   59810.3
526456.8    5253984.7   59954
526460.9    5253984.7   60277.9
526465  5253984.7   60327.2
526469.1    5253984.7   60454.4
526473.2    5253984.7   60387.6
526477.3    5253984.7   60202.1
526481.4    5253984.7   60292.2
526485.6    5253984.7   60657.1
526489.7    5253984.7   60909
526493.8    5253984.7   61070.8
526497.9    5253984.7   61128.9
526502  5253984.7   61233.6
526506.1    5253984.7   61286.2
526510.2    5253984.7   61543.5
526514.3    5253984.7   61691.4
526518.4    5253984.7   61822.6
526522.6    5253984.7   62016.1
526526.7    5253984.7   62274.3
526530.8    5253984.7   62299.4
526534.9    5253984.7   62263.7
526539  5253984.7   62161.4
526543.1    5253984.7   62070.3
526547.2    5253984.7   61992.3
526551.3    5253984.7   61919.4
526555.4    5253984.7   61842.4
526559.6    5253984.7   61810.8
526563.7    5253984.7   61862.3
526567.8    5253984.7   61926.4
526571.9    5253984.7   61919
526576  5253984.7   61948.4
526580.1    5253984.7   61989.3
526584.2    5253984.7   62017
526588.3    5253984.7   62065.8
526592.4    5253984.7   62058.4
526596.6    5253984.7   62053.2
526600.7    5253984.7   62041.8
526604.8    5253984.7   62066.9
526608.9    5253984.7   62072.8
526613  5253984.7   62072.4
526617.1    5253984.7   62055.3

对于未对齐的条目感到抱歉,这来自复制出MS Excel ...

数据被排列成一系列线,这些线在组合时构成一个坐标的列表,该坐标由一个由上下点“x”和“y”值限定的区域组成。

导致我的脚本挂起的问题是,我试图网格化以便将它的计数图像与主数据集进行比较的子采样数据集具有错误对齐的行开始和结束点。对于使用奇数子区间创建的所有子采样数据集都是如此。

我通过在'for'循环中使用额外的检查来修复问题,该循环对数据集进行了子采样。

这是固定的“子样本”代码。

 - Note: The plotting code works seamlessly.

    def sub_sample():
        print ""
        print " - This program will sub-sample a dataset for every <n> datapoint."
        print " - <n> should realistically should be between 1 and 10."
        print " - If <n> > 10, interpretation confidence is reduced significantly."
        print ""
        n = raw_input(" - What value should <n> take?: ")

        if int(n) > 0 and int(n) < 2001:
            print ""
            print " - You have chosen to subsample the data every "+str(n)+" datapoints."

            perc = (float(1)/float(n)*int(100))
            print " - This corresponds to "+str(perc)+" percent of the data."

            indataarray = numpy.loadtxt("out.csv", skiprows=1, delimiter=',')

            out_name = "every_"+str(n)+".csv"     

            t = indataarray.shape
            totalrows = t[0]
            totalcolumns = t[1]
            holding_array = numpy.zeros( [totalrows, totalcolumns] )

            for i in range(totalrows):

                if ((i % 100) % int(n) == 0):
                    for j in range(totalcolumns):
                        holding_array[i,j] = indataarray[i,j] 

            no_zeros = (holding_array == 0).sum(1)
            new_holding = holding_array[no_zeros == 0, :]
            numpy.savetxt(out_name, new_holding, delimiter=',', fmt='%f')

            hdr_c1 = 'Easting,'
            hdr_c2 = 'Northing,'
            hdr_c3 = 'TMI_nT'

            f = open(out_name)
            text = f.read()
            f.close()

            f = open(out_name, 'w')
            f.write(hdr_c1+hdr_c2+hdr_c3+'\n')
            f.write(text)
            f.close
            print " - The file "+out_name+" has been created."

        else:
            print ""
            print " - You have entered an unrealistic value for <n>."
            print " - Please try again."
            sub_sample()

1 个答案:

答案 0 :(得分:4)

它失败了,因为你试图在非常奇怪的区域进行插值。

查看输入坐标,您的数据全部在一行,但您正在尝试在2D中进行插值。您的yi坐标都是一样的!

enter image description here

如果你想要1D插值,那么只需使用多个1D插值例程中的一个...(numpy.interp如果你只想要线性插值,或scipy.interp1d如果你需要某种样条曲线。其他几个选项......)。

完整数据集是什么样的?

griddata默认使用delauney三角测量。每当你最终在输入点之间制作非常薄的近零区域三角形时,该算法就会出现问题。

如果确实希望在区域的区域内进行2D插值(请参阅此处的问题!!),请尝试另一种(最好是1D)插值算法。如果您需要帮助,请告诉我们。

如果您确实需要“伪2D”插值,使用线性距离函数的scipy.interpolate.Rbf将是一种选择。请注意,(2D)结果可能不是您所期望的,因为您在y方向上绝对没有变化......

或者,如果您希望Y方向上的所有内容都相同,则可以在y方向上平铺1D插值结果。