Übersicht:
PhyPraKit ist eine Sammlung von Funktionen in der Sprache python (vers. 2.7) zur Visualisierung und Auswertung von Daten in den physikalischen Praktika. Beispiele illustrieren jeweils die Anwendung.
Version der Dokumentation vom Okt. 2016
In allen Praktika zur Physik werden Methoden zur Darstelllung und Auswertung von Messdaten benötigt. Die Script- und Programmiersprache python mit den Zusatzpaketen numpy und matplotlib ist ein universelles Werkzeug, um die Wiederholbarkeit und Reprodzierbarkeit von Datenauswertungen zu gewährleiseten.
In der Veranstaltung “Computergestützte Datenauswertung” (http://www.ekp.kit.edu/~quast/CgDA), die im neuen Studienplan für den Bachelorstudiengang Physik am KIT seit dem Sommersemester 2016 angeboten wird, werden Methoden und Software zur grafischen Darstellung von Daten, deren Modellierung und Auswertung eingeführt.
Die folgen Links erlauben einen schnellen Überblick:
- Zusammenfassung der Vorlesung und Dokumentation der Code-Beispiele
http://www.ekp.kit.edu/~quast/CgDA/CgDA-html/CgDA_ZusFas.html
- Installation der Software auf verschiedenen Platformen
- Dokumentation in html: http://www.ekp.kit.edu/~quast/CgDA/CgDA-SoftwareInstallation-html
- Dokumentation in pdf: http://www.ekp.kit.edu/~quast/CgDA/CgDA-SoftwareInstallation.pdf
- Softwarepakete: http://www.ekp.kit.edu/~quast/CgDA/Software
Speziell für das “Praktikum zur klassischen Physik” finden sich eine kurze Einführung (http://www.ekp.kit.edu/~quast/CgDA/PhysPrakt/CgDA_APraktikum.pdf) sowie die hier dokumentierten einfachen Beispiele als Startpunkt für eigene Auswertungen (http://www.ekp.kit.edu/~quast/CgDA/PhysPrakt/).
zum import in eigene Beispielen mittels:
import PhyPraKit as ppk from PhyPraKit import ...
Weitere python-Skripte als Beisepiele zur Anwendung von Modulen in PhyPraKit:
kfitf.py ist ein Kommandozeilen-Werkzeug, mit dem man komfortabel Anpassungen ausführen kann, bei denen Daten und Fit-Funktion in einer einzigen Datei angegeben werden. Beispiele finden sich in den Dateien mit der Endung .fit.
Beispiel_Drehpendel.py demonstriert die Analyse von am Drehpendel mit CASSY aufgenommenen Daten. Enthalten sind einfache Funktionen zum Filtern und bearbeiten der Daten, Suche nach Extrema, zur Anpassung einer Einhüllenden, zur diskreten Fourier-Transformation und zur Interpolation von Messdaten mit kubischen Spline-Funktionen.
Beispiel_Hysterese.py demonstriert die Analyse von Daten, die mit einem USB-Oszilloskop der Marke PicoScope am Versuch zur Hysterese aufgenommen wurden. Die aufgezeichneten Werte für Strom und B-Feld werden in einen Zweig für steigenden und fallenden Strom aufgeteilt, mit Hilfe von kubischen Splines interpoliert und dann integriert.
periodischer Daten am Beispiel der akustischen Anregung eines Metallstabs. Genutzt werden Fourier-Transformation und eine Suche nach charakteristischen Extrema. Die Zeitdifferenzen zwischen deren Auftreten im Muster werden bestimmt, als Häufgkeitsverteilung dargestellt und die Verteilungen statistisch ausgewertet.
Die übrigen python-Scripte im Verzeichnis wurden zur Erstellung der in der einführenden Vorlesung gezeigten Grafiken verwendet.
Für die Erstellung von Protokollen mit Tabellen, Grafiken und Formeln bietet sich das Textsatz-System LaTeX an. Die Datei Protokollvorlage.zip enthält eine sehr einfach gehaltene Vorlage, die für eigene Protokolle verwendet werden kann. Eine sehr viel umfangreichere Einführung sowie ein ausführliches Beispiel bietet die Fachschaft Physik unter dem Link https://fachschaft.physik.kit.edu/drupal/content/latex-vorlagen
Collection of Tools for Data Analysis, contains the follwoing functions:
- Data input:
- readColumnData() read data and meta-data from text file
- readPicoScope() read data from PicoScope
- readCassy() read CASSY output file in .txt format
- labxParser() read CASSY output file, .labx format
- signal processing:
- offsetFilter subtract an offset in array a
- meanFilter apply sliding average to smoothen data
- resample average over n samples
- Fourier_fft fast Fourier transformation of an array
- FourierSpectrum Fourier transformation of an array (slow, preferably use fft version)
- simplePeakfinder find peaks and dips in an array comparing neighbouring samples use convolutionPeakfinder
- convolutionPeakfinder find peaks and dips in an array
- statistics:
- wmean() weighted mean
- histograms tools:
- barstat() statistical information bar chart
- nhist() histogram plot based on np.historgram() and plt.bar() use matplotlib.pyplot.hist() instead
- histstat() statistical information from 1d-histogram
- nhist2d() 2d-histotram plot based on np.histrogram2d, plt.colormesh() use matplotlib.pyplot.hist2d() instead
- hist2dstat() statistical information from 1d-histogram
- profile2d() “profile plot” for 2d data
- chi2p_indep2d() chi2 test on independence of data
- linear regression:
- linRegression() linear regression, y=ax+b, with analytical formula
- linRegressionXY() linear regression, y=ax+b, with x and y errors ! deprecated, use `odFit` with linear model instead
- odFit() fit function with x and y errors (scipy ODR)
- kRegression() regression, y=ax+b, with x-, y- and correlated errors ! deprecated, use `kFit` with linear model instead
- kFit() fit function with x-, y- and correlated errors (kafe)
- simulated data with MC-method:
- smearData() add random deviations to input data
- generateXYdata() generate simulated data
(a simple implementaion for didactical purpose only, consider using Fourier_fft() )
- Args:
- t: np-array of time values
- a: np-array amplidude a(t)
- Returns:
- arrays freq, amp: frequencies and amplitudes
Fourier transform of the amplitude spectrum a(t)
uses numpy.fft and numpy.fftfreq; output amplitude is normalised to number of samples;
statistics from a bar chart (histogram) with given bin contents and bin centres
perform a chi2-test on independence of x and y
Generate measurement data according to some model assumes xdata is measured within the given uncertainties; the model function is evaluated at the assumed “true” values xtrue, and a sample of simulated measurements is obtained by adding random deviations according to the uncertainties given as arguments.
calculate statistical information from 2d Histogram
calculate mean of a histogram with bincontents binc and bin edges bine
fit function func with errors on x and y; uses package kafe
- Args:
- func: function to fit
- x: np-array, independent data
- y: np-array, dependent data
- the following are single floats or arrays of length of x
- sx: uncertainty(ies) on x
- sy: uncertainty(ies) on y
- p0: array-like, initial guess of parameters
- p0e: array-like, initial guess of parameter uncertainties
- xabscor: absolute, correlated error(s) on x
- yabscor: absolute, correlated error(s) on y
- xrelcor: relative, correlated error(s) on x
- yrelcor: relative, correlated error(s) on y
- title: string, title of gaph
- axis_labels: List of strings, axis labels x and y
- plot: flag to switch off graphical ouput
- quiet: flag to suppress text and log output
linear regression y(x) = ax + b with errors on x and y; uses package kafe
- Args:
- x: np-array, independent data
- y: np-array, dependent data
- the following are single floats or arrays of length of x
- sx: uncertainty(ies) on x
- sy: uncertainty(ies) on y
- xabscor: absolute, correlated error(s) on x
- yabscor: absolute, correlated error(s) on y
- xrelcor: relative, correlated error(s) on x
- yrelcor: relative, correlated error(s) on y
- title: string, title of gaph
- axis_labels: List of strings, axis labels x and y
- plot: flag to switch off graphical ouput
- quiet: flag to suppress text and log output
read files in xml-format produced with Leybold CASSY
linear regression y(x) = ax + b
linear regression y(x) = ax + b with errors on x and y uses numerical “orthogonal distance regression” from package scipy.odr
apply a sliding average to smoothen data,
value at index i and int(width/2) neighbours are averaged to from the new value at index i
Histogram.hist show a one-dimensional histogram
Histrogram.hist2d create and plot a 2-dimensional histogram
fit an arbitrary function with errors on x and y uses numerical “orthogonal distance regression” from package scipy.odr
- Args:
- fitf: function to fit, arguments (array:P, float:x)
- x: np-array, independent data
- y: np-array, dependent data
- sx: np-array, uncertainty on x
- sy: np-array, uncertainty on y
- p0: none, scalar or array, initial guess of parameters
correct an offset in array a (assuming a symmetric signal around zero) by subtracting the mean
read Data exported from Cassy in .txt format
read Data exported from PicoScope in .txt or .csv format
perform average over n data points of array a, return reduced array, eventually with corresponding time values
value at index i and int(width/2) neighbours are averaged to from the new value at index i
this only works for very smooth data with well defined extrema use convolutionPeakfinder instead
- Args:
- x: np-array of values
- a: np-array of values at postion x
- th: float, threshold for peaks
- Returns:
- np-array: x position of peak as weighted mean over neighbours
- np-array: y posiion
weighted mean of np-array x with uncertainties sx
test_readColumnData.py
test data input from text file with module PhyPraKit.readColumnData
test_readPicoSocpe.py
Einlesen von Daten aus einer mit PicoScope erstellten Datei
cassylabxParser.py
read files in xml-format produced with the Leybold Cassy system
uses PhyPraPit.labxParser()
test_Historgram.py
test histogram functionality in PhyPraKit
test_generateDate
test generation of simulated data this simulates a measurement with given x-values with uncertainties; random deviations are then added to arrive at the true values, from which the true y-values are then calculated according to a model function. In the last step, these true y-values are smeared by adding random deviations to obtain a sample of measured values
kfitf.py
Perform a fit with the kafe package driven by input file
usage: kfitf.py [-h] [-n] [-s] [-c] [–noinfo] [-f FORMAT] filename
-h, --help | show this help message and exit |
-n, --noplot | suppress ouput of plots on screen |
-s, --saveplot | save plot(s) in file(s) |
-c, --contour | plot contours and profiles |
--noinfo | suppress fit info on plot |
--noband | suppress 1-sigma band around function |
--format FMT | graphics output format, default FMT = pdf |
Beispliel_Drehpendel.py
Auswertung der Daten aus einer im CASSY labx-Format gespeicherten Datei am Beispiel des Drehpendels
- Einlesen der Daten im .labx-Format
- Säubern der Daten durch verschiedene Filterfunktionen: - offset-Korrektur - Glättung durch gleitenden Mittelwert - Zusammenfassung benachberter Daten durch Mittelung
- Fourier-Transformation (einfach und fft)
- Suche nach Extrema (peaks und dips)
- Anpassung von Funkionen an Einhüllende der Maxima und Minima
- Interpolation durch Spline-Funktionen
- numerische Ableitung und Ableitung der Splines
- Phasenraum-Darstellung (aufgezeichnete Wellenfunktion gegen deren Ableitung nach der Zeit)
Beispiel_Hysterese.py
Auswertung der Daten aus einer mit PicoScope erstellten Datei im txt-Format am Beispiel des Hystereseversuchs
- Einlesen der Daten aus PicoScope-Datei vom Typ .txt
- Darstellung Kanal_a vs. Kanal_b
- Auftrennung in zwei Zweige für steigenden bzw. abnehmenden Strom
- Interpolation durch kubische Splines
- Integration der Spline-Funktionen
test_readPicoSocpe.py
Einlesen von Daten aus dem mit PicoScope erstellten Dateien am Beispiel der akustischen Anregung eines Stabes