Seite 1 von 2
Messwertauswertung
Verfasst: Dienstag 20. September 2011, 17:08
von Lateiner
Hallo!
Ich führe Versuche auf dem Gebiet der Aerodynamik durch und benutze LabView zur Erfassung der Sensordaten. Diese speichert Lab View in eine Messwertdatei. Diese enthält, neben einem Header, lediglich durch Tabulatoren getrennte Messwerte, zB so:
Code: Alles auswählen
Zeit Temperatur Geschwindigkeit
0.01 21.2 12,7
0.02 20.3 13,8
Das Problem ist: Ich habe ungefähr 100.000 Datensätze (also in y-Richtung gesehen

) und jeweils 5 in x-Richtung, also rund 500.000 Werte in dieser Datei.
Visualisieren, mitteln und Plotten mit Excel scheidet aus, da mein Rechner das einfach nicht schafft.
Also habe ich mal einen Freund gefragt und der sagte mir: "Excel kannst du vergessen, das geht mit Python ganz einfach."
Sowas mit einer Programmiersprache zu lösen war mir noch gar nicht gekommen.
Doch ich habe vorher mit Python bis auf ein paar Spielereien noch wenig gemacht.
Wie würdet ihr da rangehen? Aus der Dokumentation werde ich nicht ganz schlau.
Danke,
Lateiner.
Re: LVM mittels Python auswerten
Verfasst: Dienstag 20. September 2011, 17:11
von Dauerbaustelle
Re: LVM mittels Python auswerten
Verfasst: Dienstag 20. September 2011, 17:22
von Lateiner
Hm. Ich verstehe nicht ganz, wie ich die Werte aus meiner Tabulator-getrennten Datei in Python reinbekomme und ab da plotten kann.
Re: LVM mittels Python auswerten
Verfasst: Dienstag 20. September 2011, 17:34
von Hyperion
z.B. mit dem `csv`-Modul aus der Standard-Lib.
Re: LVM mittels Python auswerten
Verfasst: Dienstag 20. September 2011, 17:39
von Lateiner
Hm, ich habe schon versucht, damit was zu basteln.
Habe mal folgenden Beispiel-Quellcode verwendet (aus einem Python-Buch):
Code: Alles auswählen
import csv
reader = csv.reader(open("Werte.csv", "rb"), delimiter=";")
for row in reader:
print row
Da bekomm' ich nur folgende Meldung von Python:
Code: Alles auswählen
raceback (most recent call last):
File "/Users/***/Documents/PYTHON/Datenauswertung.py", line 3, in <module>
for row in reader:
Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
Wo ist da der Fehler? Mache das zum ersten Mal

Danke,
Lateiner
Re: LVM mittels Python auswerten
Verfasst: Dienstag 20. September 2011, 18:26
von Bats
Der Delimiter sollte natürlich \t sein. Anonsten ersetze mal 'rb' durch 'rU'.
Re: LVM mittels Python auswerten
Verfasst: Dienstag 20. September 2011, 18:41
von gkuhl
Ich würde bei solchen Daten ``numpy.loadtxt`` empfehlen. Damit wird das ganze zu einem Einzeiler.
Edit: Hier mal ein kleines Beispiel (ungetestet):
Code: Alles auswählen
import numpy as np
import matplotlib.pyplot as plt
zeit, temp = np.loadtxt('data.lvm', skiprows=1, usecols=(0,1), unpack=True, delimiter='\t')
plt.plot(zeit, temp)
plt.show()
PS: Enthalten deine Geschwindigkeiten wirklich ein Komma?
Re: LVM mittels Python auswerten
Verfasst: Mittwoch 21. September 2011, 19:51
von Lateiner
Ich würde das gerne ausprobieren, leider kommt folgende Meldung:
Code: Alles auswählen
Traceback (most recent call last):
File "/Users/***/Documents/PYTHON/Datenauswertung.py", line 2, in <module>
import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot
Alle Versuche, matplotlib auf meinem Mac zu installieren, schlugen fehl.
Gibt es dafür ein Tut?
Re: LVM mittels Python auswerten
Verfasst: Mittwoch 21. September 2011, 19:57
von Hyperion
Lateiner hat geschrieben:
Alle Versuche, matplotlib auf meinem Mac zu installieren, schlugen fehl.
Ohne das Modul wird gkuhls Beispiel natürlich nicht laufen

Was bedeutet denn "die Installationsversuche schlugen fehl"? Was hast Du genau versucht und was kam für eine Meldung?
Re: LVM mittels Python auswerten
Verfasst: Mittwoch 21. September 2011, 21:07
von Lateiner
Code: Alles auswählen
easy_install matplotlib
Searching for matplotlib
Reading http://pypi.python.org/simple/matplotlib/
Reading http://matplotlib.sourceforge.net
Reading https://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.0.1/
Reading http://sourceforge.net/project/showfiles.php?group_id=80706&package_id=82474
Reading http://sourceforge.net/project/showfiles.php?group_id=80706
Reading https://sourceforge.net/project/showfiles.php?group_id=80706&package_id=82474
Reading https://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-0.99.1/
Reading https://sourceforge.net/project/showfiles.php?group_id=80706&package_id=278194
Reading https://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-0.99.3/
Reading https://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.0
Best match: matplotlib 1.0.1
Downloading http://pypi.python.org/packages/source/m/matplotlib/matplotlib-1.0.1.tar.gz#md5=2196c0482d5b33dc8d33f67bbafc1323
Processing matplotlib-1.0.1.tar.gz
Running matplotlib-1.0.1/setup.py -q bdist_egg --dist-dir /var/folders/p4/p4XSiDkHFSOWMc0q8z09bE+++TQ/-Tmp-/easy_install-WSlnlX/matplotlib-1.0.1/egg-dist-tmp-FL8Q4z
basedirlist is: []
============================================================================
BUILDING MATPLOTLIB
matplotlib: 1.0.1
python: 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC
4.2.1 (Apple Inc. build 5646)]
platform: darwin
REQUIRED DEPENDENCIES
numpy: 1.2.1
freetype2: found, but unknown version (no pkg-config)
* WARNING: Could not find 'freetype2' headers in any
* of '.', './freetype2'.
OPTIONAL BACKEND DEPENDENCIES
libpng: found, but unknown version (no pkg-config)
* Could not find 'libpng' headers in any of '.'
Tkinter: Tkinter: 67083, Tk: 8.5, Tcl: 8.5
wxPython: no
* wxPython not found
Gtk+: no
* Building for Gtk+ requires pygtk; you must be able
* to "import gtk" in your build/install environment
Mac OS X native: yes
Qt: no
Qt4: no
Cairo: no
OPTIONAL DATE/TIMEZONE DEPENDENCIES
datetime: present, version unknown
dateutil: present, version unknown
pytz: matplotlib will provide
adding pytz
OPTIONAL USETEX DEPENDENCIES
dvipng: 1.14
ghostscript: 9.02
latex: 3.1415926
[Edit setup.cfg to suppress the above messages]
============================================================================
pymods ['pylab']
packages ['matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor', 'matplotlib.projections', 'matplotlib.testing', 'matplotlib.testing.jpl_units', 'matplotlib.tests', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid', 'mpl_toolkits.axes_grid1', 'mpl_toolkits.axisartist', 'matplotlib.sphinxext', 'matplotlib.numerix', 'matplotlib.numerix.mlab', 'matplotlib.numerix.ma', 'matplotlib.numerix.linear_algebra', 'matplotlib.numerix.random_array', 'matplotlib.numerix.fft', 'matplotlib.tri', 'matplotlib.delaunay', 'pytz']
warning: no files found matching 'MANIFEST'
warning: no files found matching 'examples/data/*'
warning: no files found matching 'lib/mpl_toolkits'
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++
In file included from src/ft2font.cpp:1:
src/ft2font.h:14:22: error: ft2build.h: No such file or directory
src/ft2font.h:15:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:16:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
In file included from src/ft2font.cpp:1:
src/ft2font.h:33: error: ‘FT_Bitmap’ has not been declared
src/ft2font.h:33: error: ‘FT_Int’ has not been declared
src/ft2font.h:33: error: ‘FT_Int’ has not been declared
src/ft2font.h:89: error: expected ‘,’ or ‘...’ before ‘&’ token
src/ft2font.h:89: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
src/ft2font.h:95: error: expected ‘,’ or ‘...’ before ‘&’ token
src/ft2font.h:95: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
src/ft2font.h:137: error: ‘FT_Face’ does not name a type
src/ft2font.h:138: error: ‘FT_Matrix’ does not name a type
src/ft2font.h:139: error: ‘FT_Vector’ does not name a type
src/ft2font.h:140: error: ‘FT_Error’ does not name a type
src/ft2font.h:141: error: ‘FT_Glyph’ was not declared in this scope
src/ft2font.h:141: error: template argument 1 is invalid
src/ft2font.h:141: error: template argument 2 is invalid
src/ft2font.h:142: error: ‘FT_Vector’ was not declared in this scope
src/ft2font.h:142: error: template argument 1 is invalid
src/ft2font.h:142: error: template argument 2 is invalid
src/ft2font.h:148: error: ‘FT_BBox’ does not name a type
src/ft2font.cpp:45: error: ‘FT_Library’ does not name a type
src/ft2font.cpp:108: error: variable or field ‘draw_bitmap’ declared void
src/ft2font.cpp:108: error: ‘FT_Bitmap’ was not declared in this scope
src/ft2font.cpp:108: error: ‘bitmap’ was not declared in this scope
src/ft2font.cpp:109: error: ‘FT_Int’ was not declared in this scope
src/ft2font.cpp:110: error: ‘FT_Int’ was not declared in this scope
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/core/include/numpy/__multiarray_api.h:958: warning: ‘int _import_array()’ defined but not used
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++
In file included from src/ft2font.cpp:1:
src/ft2font.h:14:22: error: ft2build.h: No such file or directory
src/ft2font.h:15:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:16:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
In file included from src/ft2font.cpp:1:
src/ft2font.h:33: error: ‘FT_Bitmap’ has not been declared
src/ft2font.h:33: error: ‘FT_Int’ has not been declared
src/ft2font.h:33: error: ‘FT_Int’ has not been declared
src/ft2font.h:89: error: expected ‘,’ or ‘...’ before ‘&’ token
src/ft2font.h:89: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
src/ft2font.h:95: error: expected ‘,’ or ‘...’ before ‘&’ token
src/ft2font.h:95: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
src/ft2font.h:137: error: ‘FT_Face’ does not name a type
src/ft2font.h:138: error: ‘FT_Matrix’ does not name a type
src/ft2font.h:139: error: ‘FT_Vector’ does not name a type
src/ft2font.h:140: error: ‘FT_Error’ does not name a type
src/ft2font.h:141: error: ‘FT_Glyph’ was not declared in this scope
src/ft2font.h:141: error: template argument 1 is invalid
src/ft2font.h:141: error: template argument 2 is invalid
src/ft2font.h:142: error: ‘FT_Vector’ was not declared in this scope
src/ft2font.h:142: error: template argument 1 is invalid
src/ft2font.h:142: error: template argument 2 is invalid
src/ft2font.h:148: error: ‘FT_BBox’ does not name a type
src/ft2font.cpp:45: error: ‘FT_Library’ does not name a type
src/ft2font.cpp:108: error: variable or field ‘draw_bitmap’ declared void
src/ft2font.cpp:108: error: ‘FT_Bitmap’ was not declared in this scope
src/ft2font.cpp:108: error: ‘bitmap’ was not declared in this scope
src/ft2font.cpp:109: error: ‘FT_Int’ was not declared in this scope
src/ft2font.cpp:110: error: ‘FT_Int’ was not declared in this scope
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/core/include/numpy/__multiarray_api.h:958: warning: ‘int _import_array()’ defined but not used
src/ft2font.cpp:2189: fatal error: error closing -: Broken pipe
compilation terminated.
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++
In file included from src/ft2font.cpp:1:
src/ft2font.h:14:22: error: ft2build.h: No such file or directory
src/ft2font.h:15:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:16:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
In file included from src/ft2font.cpp:1:
src/ft2font.h:33: error: ‘FT_Bitmap’ has not been declared
src/ft2font.h:33: error: ‘FT_Int’ has not been declared
src/ft2font.h:33: error: ‘FT_Int’ has not been declared
src/ft2font.h:89: error: expected ‘,’ or ‘...’ before ‘&’ token
src/ft2font.h:89: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
src/ft2font.h:95: error: expected ‘,’ or ‘...’ before ‘&’ token
src/ft2font.h:95: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
src/ft2font.h:137: error: ‘FT_Face’ does not name a type
src/ft2font.h:138: error: ‘FT_Matrix’ does not name a type
src/ft2font.h:139: error: ‘FT_Vector’ does not name a type
src/ft2font.h:140: error: ‘FT_Error’ does not name a type
src/ft2font.h:141: error: ‘FT_Glyph’ was not declared in this scope
src/ft2font.h:141: error: template argument 1 is invalid
src/ft2font.h:141: error: template argument 2 is invalid
src/ft2font.h:142: error: ‘FT_Vector’ was not declared in this scope
src/ft2font.h:142: error: template argument 1 is invalid
src/ft2font.h:142: error: template argument 2 is invalid
src/ft2font.h:148: error: ‘FT_BBox’ does not name a type
src/ft2font.cpp:45: error: ‘FT_Library’ does not name a type
src/ft2font.cpp:108: error: variable or field ‘draw_bitmap’ declared void
src/ft2font.cpp:108: error: ‘FT_Bitmap’ was not declared in this scope
src/ft2font.cpp:108: error: ‘bitmap’ was not declared in this scope
src/ft2font.cpp:109: error: ‘FT_Int’ was not declared in this scope
src/ft2font.cpp:110: error: ‘FT_Int’ was not declared in this scope
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/core/include/numpy/__multiarray_api.h:958: warning: ‘int _import_array()’ defined but not used
lipo: can't open input file: /var/folders/p4/p4XSiDkHFSOWMc0q8z09bE+++TQ/-Tmp-//ccsBLq1i.out (No such file or directory)
error: Setup script exited with error: command 'gcc-4.2' failed with exit status 1
Exception OSError: (2, 'No such file or directory', 'src/image.cpp') in <bound method CleanUpFile.__del__ of <setupext.CleanUpFile instance at 0x101715638>> ignored
Exception OSError: (2, 'No such file or directory', 'src/path.cpp') in <bound method CleanUpFile.__del__ of <setupext.CleanUpFile instance at 0x1017146c8>> ignored
Exception OSError: (2, 'No such file or directory', 'src/backend_agg.cpp') in <bound method CleanUpFile.__del__ of <setupext.CleanUpFile instance at 0x101715440>> ignored
Leider sagt mir das alles nichts....
Re: LVM mittels Python auswerten
Verfasst: Mittwoch 21. September 2011, 21:13
von Hyperion
Du hast
diesen Abschnitt aber schon gelesen?
Re: LVM mittels Python auswerten
Verfasst: Donnerstag 22. September 2011, 17:42
von Lateiner
So, ich habe es nun nach einem Update auf 2.7 geschafft, matplotlib zu installieren.
Doch wenn ich nun in python import matplotlib eingebe, erscheint folgende Fehlermeldung:
Code: Alles auswählen
>>> import matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py", line 135, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/colors.py", line 52, in <module>
import numpy as np
ImportError: No module named numpy
Numpy zu installieren geht nicht, da es 2.6 benötigt...
Re: LVM mittels Python auswerten
Verfasst: Donnerstag 22. September 2011, 17:49
von Lateiner
Numpy konnte ich nun doch installieren.
Doch nun kam das:
Code: Alles auswählen
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper
>>>
Re: LVM mittels Python auswerten
Verfasst: Freitag 23. September 2011, 09:34
von CM
Und wie hast Du installiert? (shared object files müssen für Deine Architektur und im Zweifel auch für Deine Pythonversion kompiliert sein. Wenn Du Dir sicher bist alles richtig gemacht zu haben, solltest Du auf der numpy-Mailingliste Bescheid geben, dass es ein Problem gibt.)
PS Im Übrigen wird das Arbeiten mit matplotlib kein Spaß, wenn kein graphisches Backend und viele Bildformate nicht unterstützt werden.
PPS Vielleicht ist die
EPD etwas für Dich, wenn Du Deine Installationsprobleme nicht in den Griff bekommst.
Re: LVM mittels Python auswerten
Verfasst: Samstag 24. September 2011, 06:40
von Lateiner
Habe nun EPD installiert, immer noch der gleiche Fehler, Komodo wirft mir stets das Folgende aus:
Code: Alles auswählen
Traceback (most recent call last):
File "/Users/***/Documents/PYTHON/Datenauswertung.py", line 2, in <module>
import mathplotlib.pyplot as plt
ImportError: No module named mathplotlib.pyplot
:K
Re: LVM mittels Python auswerten
Verfasst: Samstag 24. September 2011, 08:42
von gkuhl
Ich denke EPD wird als Distribution neben der "normalen" Python installiert. Du musst also den Python Interpreter aus dem EPD Installationspfad neben.
Re: LVM mittels Python auswerten
Verfasst: Samstag 24. September 2011, 09:00
von Lateiner
Wenn ich jedoch ins Terminal gehe, dort python lade und dann
eingebe, schluckt der das ohne Fehlermeldung. Mein Editor ist Komodo IDE.
Re: LVM mittels Python auswerten
Verfasst: Samstag 24. September 2011, 11:21
von Lateiner
So, habe EPD nun mit Komodo zum Laufen gebracht und den Quelltext, der oben freundlicherweise geboten wurde, ein wenig "aufgebort":
Code: Alles auswählen
#!/usr/bin/python
#Variablendefinitionen
mittel=0
anzahlElemente=0
kommentarZeilen=0
dateiName="Messung.lvm"
auszuwertendeSpalte=0
augewerteteSpalte=0
import numpy as np
import matplotlib.pyplot as plt
print "Es wird die Datei ", dateiName, "ausgewertet."
kommentarZeilen = input("Bitte geben Sie an, wie viele Zeilen als Kommentar uebersprungen werden sollen (normalerweise 32): ")
auszuwertendeSpalten = input("Bitte geben Sie ein, wie viele Spalten vorhanden sind: ")
while augewerteteSpalte != auszuwertendeSpalte:
zeit, a = np.loadtxt(dateiName, skiprows=kommentarZeilen, usecols=(0,ausgewerteteSpalte), unpack=True, delimiter='\t')
plt.plot(zeit, a, linewidth=0.02)
plt.show()
ausgewerteteSpalte = ausgewerteteSpalte + 1
Leider zeigt der mir die Plots nicht an. Was habe ich falsch gemacht?
Re: LVM mittels Python auswerten
Verfasst: Sonntag 25. September 2011, 13:41
von Lateiner
Die Auswertung klappt soweit nun, außer dass die Schleife oben scheinbar nicht abgearbeitet wird. Hat da jemand ne Idee?
Re: LVM mittels Python auswerten
Verfasst: Sonntag 25. September 2011, 14:40
von BlackJack
@Lateiner: Lass Dir doch einfach mal die beiden Werte ausgeben die da verglichen werden. Und dann musst Du nur noch einmal *genau* auf den Quelltext zu schauen um fest zu stellen warum die beide an der Stelle immer 0 sind.
Wenn man eine Laufvariable hat und die Anzahl der Durchläufe vor Schleifeneintritt bereits kennt, sollte man ausserdem eine ``for``-Schleife anstelle einer ``while``-Schleife verwenden.
PS: Der Fehler wäre Dir übrigens selbst sehr schnell aufgefallen wenn Du nicht alle möglichen Namen am Anfang an teilweise sinnlose Werte bindest.