Poincare-Plot/Abtastrate
Verfasst: Donnerstag 3. November 2022, 14:51
Hallo Zusammen,
ich habe relativ frisch mit Python begonnen.
Die Idee ist, einen Poincare-Plot zu erstellen. Bedeutet, ich möchte meinen Graphen mit einer bestimmen Samplinrate abtasten und den vorhandenen Wert als Punkt in meinem Plot darstellen lassen.
Über Hilfe wäre ich sehr dankbar!
Im Anhang befindet sich mein aktuelles Skript.
Viele Grüße
import numpy as np
from nptdms import TdmsFile, TdmsWriter, ChannelObject
import numpy as np
from glob import glob
import os
import matplotlib.pyplot as plt
from scipy import signal
import pandas as pd
#Locale settings
import locale
# Set to German locale to get comma decimal separater
locale.setlocale(locale.LC_NUMERIC, "de_DE")
plt.rcParams['axes.formatter.use_locale'] = True
def explore_tdms(pathname):
"""
Explore data from TDMS file
Args:
pathname: name of the tdms file, which will be read
"""
tdms_file = TdmsFile.read(pathname)
print("Groups:")
for index, group in enumerate(tdms_file.groups()):
print("\tGroup {}: {}".format(index, group.name))
for idx, channel in enumerate(group.channels()):
print("\t\tChannel {}: {}".format(idx,channel.name))
print("Properties:")
for name, value in tdms_file.properties.items():
print("{0}: {1}".format(name, value))
def read_tdms(pathname, keys = [], groupname="", verbose=False):
"""
Read data from TDMS file
Args:
pathname: name of the tdms file, which will be read
keys: list of channel names for each column
groupname: name of group, under which the channels are placed (default is first group)
Returns:
numpy array containing a column for each channel
"""
tdms_file = TdmsFile.read(pathname)
group = tdms_file[groupname] if groupname != "" else tdms_file.groups()[0] # defaults to first group found, if none explicitly given
keys = keys if len(keys) != 0 else [channel.name for channel in group.channels()] # use all channels if none given
if verbose:
print(keys)
return [group[key][:] for key in keys]
files = glob('./34pcutFFT.tdms')
for file in files:
filename = os.path.basename(file)
output = filename[:-4] + 'npz'
if os.path.exists(output) and os.path.getmtime(filename) < os.path.getmtime(output):
print('Skipping {}...'.format(filename), flush=True)
continue
ata = np.transpose(read_tdms(filename,["CopyXt","CopyYdy","CopyYdx"]))
data =pd.DataFrame(data, columns=["CopyXt","CopyYdy","CopyYdx"])
plt.figure(figsize=(3.1,2))
plt.plot(data["CopyYdx"], data["CopyYdy"],c='midnightblue')
plt.xlabel('Auslenkung dx ',fontname='Arial',fontsize=11)
plt.ylabel('Auslenkung dy ',fontname='Arial',fontsize=11)
#plt.xlim(0,150)
plt.xticks([-0.08,-0.06,-0.04, -0.02,0,0.02,0.04],('-80','-60','-40','-20','0','mm','40'),fontname='Arial',fontsize=11)
plt.yticks([-0.08,-0.06,-0.04, -0.02,0,0.02,0.04],('-80','-60','-40','-20','0','mm','40'),fontname='Arial',fontsize=11)
plt.grid()
plt.legend()
plt.show()
ich habe relativ frisch mit Python begonnen.
Die Idee ist, einen Poincare-Plot zu erstellen. Bedeutet, ich möchte meinen Graphen mit einer bestimmen Samplinrate abtasten und den vorhandenen Wert als Punkt in meinem Plot darstellen lassen.
Über Hilfe wäre ich sehr dankbar!
Im Anhang befindet sich mein aktuelles Skript.
Viele Grüße
import numpy as np
from nptdms import TdmsFile, TdmsWriter, ChannelObject
import numpy as np
from glob import glob
import os
import matplotlib.pyplot as plt
from scipy import signal
import pandas as pd
#Locale settings
import locale
# Set to German locale to get comma decimal separater
locale.setlocale(locale.LC_NUMERIC, "de_DE")
plt.rcParams['axes.formatter.use_locale'] = True
def explore_tdms(pathname):
"""
Explore data from TDMS file
Args:
pathname: name of the tdms file, which will be read
"""
tdms_file = TdmsFile.read(pathname)
print("Groups:")
for index, group in enumerate(tdms_file.groups()):
print("\tGroup {}: {}".format(index, group.name))
for idx, channel in enumerate(group.channels()):
print("\t\tChannel {}: {}".format(idx,channel.name))
print("Properties:")
for name, value in tdms_file.properties.items():
print("{0}: {1}".format(name, value))
def read_tdms(pathname, keys = [], groupname="", verbose=False):
"""
Read data from TDMS file
Args:
pathname: name of the tdms file, which will be read
keys: list of channel names for each column
groupname: name of group, under which the channels are placed (default is first group)
Returns:
numpy array containing a column for each channel
"""
tdms_file = TdmsFile.read(pathname)
group = tdms_file[groupname] if groupname != "" else tdms_file.groups()[0] # defaults to first group found, if none explicitly given
keys = keys if len(keys) != 0 else [channel.name for channel in group.channels()] # use all channels if none given
if verbose:
print(keys)
return [group[key][:] for key in keys]
files = glob('./34pcutFFT.tdms')
for file in files:
filename = os.path.basename(file)
output = filename[:-4] + 'npz'
if os.path.exists(output) and os.path.getmtime(filename) < os.path.getmtime(output):
print('Skipping {}...'.format(filename), flush=True)
continue
ata = np.transpose(read_tdms(filename,["CopyXt","CopyYdy","CopyYdx"]))
data =pd.DataFrame(data, columns=["CopyXt","CopyYdy","CopyYdx"])
plt.figure(figsize=(3.1,2))
plt.plot(data["CopyYdx"], data["CopyYdy"],c='midnightblue')
plt.xlabel('Auslenkung dx ',fontname='Arial',fontsize=11)
plt.ylabel('Auslenkung dy ',fontname='Arial',fontsize=11)
#plt.xlim(0,150)
plt.xticks([-0.08,-0.06,-0.04, -0.02,0,0.02,0.04],('-80','-60','-40','-20','0','mm','40'),fontname='Arial',fontsize=11)
plt.yticks([-0.08,-0.06,-0.04, -0.02,0,0.02,0.04],('-80','-60','-40','-20','0','mm','40'),fontname='Arial',fontsize=11)
plt.grid()
plt.legend()
plt.show()