使用meshgrid的Python内存错误

时间:2017-08-17 00:44:38

标签: python numpy matplotlib coordinates

我正在导入沿着配置文件收集的地球物理数据,其坐标为UTM格式。数据如下

Easting Northing    Ch1 Ch2 Ch3 Ch4
315467.994  6801358.217 -11.82  -9.12   -6.21   -3.19
315467.995  6801358.204 -11.91  -9.12   -6.21   -2.89
315467.996  6801358.191 -11.82  -9.36   -5.85   -3.18
315467.997  6801358.178 -11.57  -9.11   -6.21   -2.89
315467.998  6801358.165 -11.33  -8.99   -5.85   -2.89

我将数据输入,检查限制,运行插值并因内存错误崩溃(我认为在meshgrid中)。

追踪(最近一次呼叫最后一次):

  

316267 315388 6800805 6800790 -2462 4113   
文件" C:PycharmProjects / testing / EM61 data plot.py",第44行,in   X和Y中的点数 - 3516 60   
X,Y = np.meshgrid(东,北)   
在meshgrid中的文件" \ Python \ Python36 \ lib \ site-packages \ numpy \ lib \ function_base.py",第4679行   
输出= [输出中x的x.copy()]   
文件" C:\ Python \ Python36 \ lib \ site-packages \ numpy \ lib \ function_base.py",第4679行,   
输出= [输出中x的x.copy()]   
的MemoryError

它在显示网格图像的小文件上运行正常,数据点位于顶部,但一旦我找到更大的文件,它就会崩溃。我的文件最多可以有250,000行数据,并且可以在网格中大到1000 x 50点。

示例图片:

example image

是否有一些避免内存错误的简单方法?

from tkinter import filedialog
from tkinter import *
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import mlab, cm
from matplotlib.mlab import griddata

root = Tk()
root.filename = filedialog.askopenfilename( filetypes = ( ("CSV files","*.csv"),("All files", "*.*")))

#Set up root window
root.title ("TestGUI") # the name of the window
root.geometry("400x300")

#Open a file
data = np.genfromtxt(root.filename, delimiter=',', skip_header=2) # Get data from file as list

#Extract data from data list
East = data[:,][:,0]
North = data[:,][:,1]
Ch1 = data[:,][:,2]
Ch2 = data[:,][:,3]
Ch3 = data[:,][:,4]
Ch4 = data[:,][:,5]

# Find the data limits
Maxx=int(max(East))
Minx=int(min(East))
Maxy=int(max(North))
Miny=int(min(North))

#Printing info for tracking program performance
print ("Number of points in file",len(East))
print (Maxx,Minx,Maxy,Miny,int(min(Ch1)),int(max(Ch1)))

#Generate grid
#Produce a list of x coordinates based on the max and min of the data spaced 1 metre apart

xi = np.linspace(Minx, Maxx, (Maxx-Minx))
yi = np.linspace(Miny, Maxy, (Maxy-Miny))

print ("Number of points in X and Y -",len(xi),len(yi))

X,Y= np.meshgrid(East,North)
Z1 = griddata(East, North, Ch1, xi, yi, interp='nn')
cmap = cm.get_cmap(name='rainbow', lut=None) # Change the colour scheme
plt.contourf(xi,yi,Z1,20,cmap=cmap) # Plot the filled contours
# plt.contour(xi,yi,Z1,20) Plots the contour lines on the colour plot
plt.colorbar()

# Plot the points on the grid
plt.scatter(East,North,label="scatter",color="k",s=1,marker="+")

plt.show()

root.mainloop()

0 个答案:

没有答案