initial commit
This commit is contained in:
+189
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import matplotlib as mpl\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def read_oscilloscope_file(file_name, time_div=200):\n",
|
||||
" with open(file_name, 'r') as file:\n",
|
||||
" lines = []\n",
|
||||
" for line in file:\n",
|
||||
" lines.append(line.strip())\n",
|
||||
" print(file.name)\n",
|
||||
"\n",
|
||||
" data = pd.DataFrame()\n",
|
||||
" \n",
|
||||
" data[\"time\"] = np.linspace(0, 12*time_div, 1200)\n",
|
||||
" data[\"CH1\"] = np.float_(lines[5:1205])\n",
|
||||
" data[\"CH2\"] = np.float_(lines[1212:2412])\n",
|
||||
"\n",
|
||||
" return data\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def plot_kurven(data: pd.DataFrame, title=\"\", xStart=0, xStop=0, xStep=200, xStepMinor=100, vlines=[]):\n",
|
||||
" fig, ax = plt.subplots(figsize=(10, 4))\n",
|
||||
"\n",
|
||||
" # time offset\n",
|
||||
" if xStop > xStart:\n",
|
||||
" data[\"time\"] -= xStart\n",
|
||||
"\n",
|
||||
" ax.plot(\"time\", \"CH1\", data=data, label=\"Anfang\", ls=\"-\", marker='.')\n",
|
||||
" ax.plot(\"time\", \"CH2\", data=data, label=\"Ende\", ls=\"-\", marker='.')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" # Beschriftungen setzen\n",
|
||||
" ax.set_xlabel(\"Zeit t [ns]\")\n",
|
||||
" ax.set_ylabel(\"Spannung U [V]\")\n",
|
||||
" if title != \"\": ax.set_title(title, fontsize=16, pad=10)\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" # ax.set_xticks(np.arange(data[\"time\"].iloc[0], data[\"time\"].iloc[-1], xStepMinor), minor=True)\n",
|
||||
" ax.set_xticks(np.arange(data[\"time\"].iloc[0], data[\"time\"].iloc[-1], xStep))\n",
|
||||
"\n",
|
||||
" if xStop > xStart:\n",
|
||||
" ax.set_xlim(left=0, right=xStop-xStart)\n",
|
||||
" else:\n",
|
||||
" ax.set_xlim(left=data[\"time\"].iloc[0], right=data[\"time\"].iloc[-1])\n",
|
||||
"\n",
|
||||
" if xStepMinor != 0:\n",
|
||||
" ax.grid(which=\"major\", ls=\"-\", linewidth=0.5)\n",
|
||||
" # ax.grid(which=\"minor\", ls=\"-\", linewidth=0.1)\n",
|
||||
" else: \n",
|
||||
" ax.grid(which=\"major\")\n",
|
||||
"\n",
|
||||
" ax.legend()\n",
|
||||
" # plt.vlines(x=25, ymin=ax.get_ylim()[0], ymax=ax.get_ylim()[1], linestyles=\":\", label=\"t1\")\n",
|
||||
" # plt.show()\n",
|
||||
"\n",
|
||||
" return fig"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%matplotlib widget"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"lel = read_oscilloscope_file(\"Messungen/Rohdaten/Messung 2.1/Reflexion bei Kurzschluss.txt\", time_div=200)\n",
|
||||
"# plot_kurven(lel)\n",
|
||||
"plot_kurven(lel, 1000, 1400)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Alles plotten und als Bilder abspeichern\n",
|
||||
"current_directory = os.getcwd()\n",
|
||||
"\n",
|
||||
"# iterate over all files in the directory \"Messungen/Rohdaten/\"\n",
|
||||
"for root, dirs, files in os.walk(os.path.join(current_directory, \"Messungen/Rohdaten/\")):\n",
|
||||
" for file in files:\n",
|
||||
" if file.endswith(\".txt\"):\n",
|
||||
" file_path = os.path.join(root, file)\n",
|
||||
" messung = read_oscilloscope_file(file_path, 200)\n",
|
||||
" plot_kurven(messung, title=file[0:-4])\n",
|
||||
" plot_kurven(messung, title=file[0:-4], start=1000, stop=1500)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Diagramme für 3.2 Kurzschluss\n",
|
||||
"kurzschluss = read_oscilloscope_file(\"Messungen/Rohdaten/Messung 2.1/Reflexion bei Kurzschluss.txt\")\n",
|
||||
"# kurzschluss.set_index(\"time\", inplace=True)\n",
|
||||
"\n",
|
||||
"kurzschluss_fig = plot_kurven(kurzschluss, start=1060, stop=1232, title=\"Reflexion bei Kurzschluss\", xStep=10, xStepMinor=5)\n",
|
||||
"kurzschluss_fig.savefig(\"Reflexion_bei_Kurzschluss\", dpi=250)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Leerlauf\n",
|
||||
"leerlauf = read_oscilloscope_file(\"Messungen/Rohdaten/Messung 2.1/Reflexion im Leerlauf.txt\")\n",
|
||||
"\n",
|
||||
"leerlauf_fig = plot_kurven(leerlauf, title=\"Relfexion bei Leerlauf\", start=1120, stop=1370, xStep=20)\n",
|
||||
"leerlauf_fig.savefig(\"Reflexion_bei_Leerlauf\", dpi=250)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Endwiderstand\n",
|
||||
"endwiderstand = read_oscilloscope_file(\"Messungen/Rohdaten/Messung 2.1/Reflexion mit Endwiderstand.txt\")\n",
|
||||
"\n",
|
||||
"endwiderstand_fig = plot_kurven(endwiderstand, title=\"Relfexion mit Endwiderstand\", start=1120, stop=1340, xStep=20)\n",
|
||||
"endwiderstand_fig.savefig(\"Reflexion_mit_Endwiderstand\", dpi=250)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"kurzschluss.set_index(\"time\", inplace=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"kurzschluss[0:150].to_csv(\"text\")\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.4"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user