Grid Data

mit matplotlib, NumPy, pandas, SciPy, SymPy und weiteren mathematischen Programmbibliotheken.
Antworten
Lienz20013
User
Beiträge: 88
Registriert: Freitag 26. September 2014, 14:42

Hi,
und zwar habe ich ein Problem mit dem gridden von xyz-Daten. Ich habe einen sehr große txt-Datei mit xyz Werten. Wenn ich nur einen kleinen Ausschnitt der Datei gridde geht das Problem los aber bei allen Daten bekomme ich eine Fehlermeldung. Mein Code:

Code: Alles auswählen

from matplotlib import cm
import numpy as np
import scipy as sp
import matplotlib.mlab as ml
from mayavi.mlab import *
from numpy.random import uniform, seed
from scipy.interpolate import griddata

file_name = "test2.xyz"#RG_north_10m.xyz

x,y,z = np.genfromtxt(file_name, usecols=(0,1,2), unpack=True) 
xi = np.linspace(min(x), max(x))
yi = np.linspace(min(y), max(y))

X, Y = np.meshgrid(xi, yi)
Z = ml.griddata(x, y, z, X, Y, interp='nn')
Und als Fehler erhalte ich:

Code: Alles auswählen

  File "<ipython-input-2-6f2cddf7ec36>", line 1, in <module>
    runfile('/home/mayavi_bath.py', wdir='/home')

  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
    execfile(filename, namespace)

  File "/home/mayavi_bath.py", line 32, in <module>
    Z = ml.griddata(x, y, z, X, Y, interp='nn')

  File "/usr/lib/pymodules/python2.7/matplotlib/mlab.py", line 2607, in griddata
    tri = delaunay.Triangulation(x,y)

  File "/usr/lib/pymodules/python2.7/matplotlib/delaunay/triangulate.py", line 124, in __init__
    self.hull = self._compute_convex_hull()

  File "/usr/lib/pymodules/python2.7/matplotlib/delaunay/triangulate.py", line 160, in _compute_convex_hull
    hull.append(edges.pop(hull[-1]))

KeyError: 950
Kann mir da jemand weiter helfen?
Bob Billsworth
User
Beiträge: 11
Registriert: Freitag 12. Juni 2015, 00:01

Hoffentlich nicht zu spät und hoffentlich hilfreich:

Meine momentane Vermutung ist, dass es wegen der Importe Konflikte gibt.

Wenn ich es so

Code: Alles auswählen

import numpy as np
import matplotlib.mlab as ml

file_name = "grid.txt"		#wieder in "test2.xyz" ändern

x,y,z = np.genfromtxt(file_name, usecols=(0,1,2), unpack=True)
xi = np.linspace(min(x), max(x))
yi = np.linspace(min(y), max(y))

X, Y = np.meshgrid(xi, yi)
# Z = ml.griddata(x, y, z, X, Y, interp='nn')	Natural Neighbor interpolation funktionierte bei mir nicht, da ein Modul nicht installiert ist.
Z = ml.griddata(x, y, z, X, Y, interp='linear')
mache, dann funktioniert es bei mir.

Meine "grid.txt" sieht ausschnittsweise so aus:

...
161.2627 146.4434 16.0064
158.4494 145.9363 68.3517
31.7919 154.6149 52.8114
186.7323 45.3153 8.6572
28.0206 116.0185 82.6458
128.0838 50.6859 57.8555
25.3413 19.4728 190.0439
175.9606 66.5732 148.1757
72.8659 148.4336 127.9173
107.6864 193.4771 58.2796
194.8461 1.5338 160.6041
...
Antworten