From 891744446130946705e18ed6d4dc287967a6c5db Mon Sep 17 00:00:00 2001 From: Brantegger Georg Date: Thu, 15 Sep 2022 11:30:17 +0200 Subject: [PATCH] added code to read validation data txts --- .../read_validation_data_long.ipynb | 183 +++++++++++++++--- .../sighting_validation_data.ipynb | 20 +- 2 files changed, 162 insertions(+), 41 deletions(-) diff --git a/Validation Data/read_validation_data_long.ipynb b/Validation Data/read_validation_data_long.ipynb index 1307bb2..52041ad 100644 --- a/Validation Data/read_validation_data_long.ipynb +++ b/Validation Data/read_validation_data_long.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -15,66 +15,187 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ + "%matplotlib qt5\n", + "\n", "def unpack_line(str):\n", + " time_format = \"%d.%m.%Y %H:%M:%S.%f\"\n", " index_1 = str.find(';')\n", - " index_2 = str.find(';',index_1)\n", - " index_3 = str.find(';',index_2)\n", - " index_4 = str.find(';',index_3)\n", - " index_5 = str.find(';',index_4)\n", + " index_2 = str.find(';',index_1+1)\n", + " index_3 = str.find(';',index_2+1)\n", + " index_4 = str.find(';',index_3+1)\n", + " index_5 = str.find(';',index_4+1)\n", " parameter = str[0:index_1]\n", - " value = str[index_2:index_3]\n", - " timestamp = str[index_5:] \n", + " value = float(str[index_2+1:index_3])\n", + " timestamp = time.mktime(datetime.strptime(str[index_5+1:-2],time_format).timetuple())\n", " return parameter,value,timestamp\n", "\n" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, - "outputs": [ - { - "ename": "KeyboardInterrupt", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", - "\u001b[1;32mv:\\georg\\Documents\\Persönliche Dokumente\\Arbeit\\Kelag\\Coding\\Python\\DT_Slot_3\\Kelag_DT_Slot_3\\Validation Data\\read_validation_data_long.ipynb Cell 3\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m timestamp_old \u001b[39m=\u001b[39m \u001b[39m0.\u001b[39m\n\u001b[0;32m 7\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mopen\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mAugust_1_22.txt\u001b[39m\u001b[39m'\u001b[39m) \u001b[39mas\u001b[39;00m txt_file:\n\u001b[1;32m----> 8\u001b[0m \u001b[39mfor\u001b[39;00m line \u001b[39min\u001b[39;00m txt_file:\n\u001b[0;32m 9\u001b[0m parameter_new, value_new, timestamp_new \u001b[39m=\u001b[39m unpack_line(line)\n", - "File \u001b[1;32mc:\\Users\\georg\\anaconda3\\envs\\DT_Slot_3\\lib\\encodings\\cp1252.py:22\u001b[0m, in \u001b[0;36mIncrementalDecoder.decode\u001b[1;34m(self, input, final)\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[39mclass\u001b[39;00m \u001b[39mIncrementalDecoder\u001b[39;00m(codecs\u001b[39m.\u001b[39mIncrementalDecoder):\n\u001b[1;32m---> 22\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mdecode\u001b[39m(\u001b[39mself\u001b[39m, \u001b[39minput\u001b[39m, final\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m):\n\u001b[0;32m 23\u001b[0m \u001b[39mreturn\u001b[39;00m codecs\u001b[39m.\u001b[39mcharmap_decode(\u001b[39minput\u001b[39m,\u001b[39mself\u001b[39m\u001b[39m.\u001b[39merrors,decoding_table)[\u001b[39m0\u001b[39m]\n", - "\u001b[1;31mKeyboardInterrupt\u001b[0m: " - ] - } - ], + "outputs": [], "source": [ - "df = pd.DataFrame(columns=['Timestamp','M1-LA','M1-Druck','M2-LA','M2-Druck'])\n", + "M1_LA_df = pd.DataFrame(columns=['Timestamp','M1-LA'])\n", + "M2_LA_df = pd.DataFrame(columns=['Timestamp','M2-LA'])\n", + "M1_Druck_df = pd.DataFrame(columns=['Timestamp','M1-Druck'])\n", + "M2_Druck_df = pd.DataFrame(columns=['Timestamp','M2-Druck'])\n", "\n", "\n", "parameter_old = ''\n", - "value_old = 0.\n", - "timestamp_old = 0.\n", "value_list = []\n", "timestamp_list = []\n", - "with open('August_1_22.txt') as txt_file:\n", + "with open('Juni_1_22.txt') as txt_file:\n", " for line in txt_file:\n", " parameter_new, value_new, timestamp_new = unpack_line(line)\n", " if parameter_new != parameter_old:\n", - " if parameter_old islike \"\"\n", + " if 'M1' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", + " M1_LA_df['Timestamp'] = timestamp_list[:]\n", + " M1_LA_df['M1-LA'] = value_list[:]\n", + " if 'M1' in parameter_old and 'Spiraldruck' in parameter_old:\n", + " M1_Druck_df['Timestamp'] = timestamp_list[:]\n", + " M1_Druck_df['M1-Druck'] = value_list[:]\n", + " if 'M2' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", + " M2_LA_df['Timestamp'] = timestamp_list[:]\n", + " M2_LA_df['M2-LA'] = value_list[:]\n", + " if 'M2' in parameter_old and 'Spiraldruck' in parameter_old:\n", + " M2_Druck_df['Timestamp'] = timestamp_list[:]\n", + " M2_Druck_df['M2-Druck'] = value_list[:]\n", " \n", " value_list = []\n", " timestamp_list = []\n", + " value_list.append(value_new)\n", + " timestamp_list.append(timestamp_new)\n", "\n", - "\n" + " parameter_old = parameter_new\n", + " else:\n", + " if value_new != value_list[-1]:\n", + " value_list.append(value_new)\n", + " timestamp_list.append(timestamp_new) \n", + "\n", + " if 'M1' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", + " M1_LA_df['Timestamp'] = timestamp_list[:]\n", + " M1_LA_df['M1-LA'] = value_list[:]\n", + " if 'M1' in parameter_old and 'Spiraldruck' in parameter_old:\n", + " M1_Druck_df['Timestamp'] = timestamp_list[:]\n", + " M1_Druck_df['M1-Druck'] = value_list[:]\n", + " if 'M2' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", + " M2_LA_df['Timestamp'] = timestamp_list[:]\n", + " M2_LA_df['M2-LA'] = value_list[:]\n", + " if 'M2' in parameter_old and 'Spiraldruck' in parameter_old:\n", + " M2_Druck_df['Timestamp'] = timestamp_list[:]\n", + " M2_Druck_df['M2-Druck'] = value_list[:]\n", + "\n", + "M1_LA_df.set_index(['Timestamp'],inplace=True)\n", + "M1_Druck_df.set_index(['Timestamp'],inplace=True)\n", + "M2_LA_df.set_index(['Timestamp'],inplace=True)\n", + "M2_Druck_df.set_index(['Timestamp'],inplace=True)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fig1=plt.figure()\n", + "plt.plot(M1_LA_df['M1-LA'])\n", + "fig2=plt.figure()\n", + "plt.plot(M1_Druck_df['M1-Druck'])\n", + "fig3=plt.figure()\n", + "plt.plot(M2_LA_df['M2-LA'])\n", + "fig4=plt.figure()\n", + "plt.plot(M2_Druck_df['M2-Druck'])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "df = M1_LA_df.join([M2_LA_df,M1_Druck_df,M2_Druck_df],how='outer')\n", + "df.sort_index(axis=0,inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fig1=plt.figure()\n", + "plt.plot(df['M1-LA'])\n", + "fig2=plt.figure()\n", + "plt.plot(df['M1-Druck'])\n", + "fig3=plt.figure()\n", + "plt.plot(df['M2-LA'])\n", + "fig4=plt.figure()\n", + "plt.plot(df['M2-Druck'])" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "t_vec = df.index.to_numpy()\n", + "M1_LA = df['M1-LA'].to_numpy() " + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fig5=plt.figure()\n", + "plt.plot(t_vec,M1_LA)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3.8.13 ('DT_Slot_3')", + "display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "language": "python", "name": "python3" }, @@ -93,7 +214,7 @@ "orig_nbformat": 4, "vscode": { "interpreter": { - "hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48" + "hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" } } }, diff --git a/Validation Data/sighting_validation_data.ipynb b/Validation Data/sighting_validation_data.ipynb index 0d68e59..e071f62 100644 --- a/Validation Data/sighting_validation_data.ipynb +++ b/Validation Data/sighting_validation_data.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 13, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -15,14 +15,14 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "C:\\Users\\georg\\AppData\\Local\\Temp\\ipykernel_34540\\1340824978.py:1: ParserWarning: Length of header or names does not match length of data. This leads to a loss of data with index_col=False.\n", + "C:\\Users\\BRANT\\AppData\\Local\\Temp\\7\\ipykernel_7624\\1340824978.py:1: ParserWarning: Length of header or names does not match length of data. This leads to a loss of data with index_col=False.\n", " raw_data = pd.read_csv(\"2015_08_24 18.00 M1 SS100%.csv\",sep=\";\",header=7,index_col=False)\n" ] } @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -55,23 +55,23 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[]" + "[]" ] }, - "execution_count": 16, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "9c2016ba1ceb4d07a17a483bbf50f9a6", + "model_id": "7cd05b652d4a40ca973b5895a8777a64", "version_major": 2, "version_minor": 0 }, @@ -104,7 +104,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.8.13 ('DT_Slot_3')", + "display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "language": "python", "name": "python3" }, @@ -123,7 +123,7 @@ "orig_nbformat": 4, "vscode": { "interpreter": { - "hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48" + "hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" } } },