{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Import needed packages" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "ExecuteTime": { "end_time": "2018-05-17T13:47:34.829254Z", "start_time": "2018-05-17T13:47:34.793907Z" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%matplotlib inline\n", "from __future__ import division\n", "\n", "# IBM PixieDust for visualizations\n", "#import pixiedust\n", "\n", "import numpy as np # For matrix manipulation\n", "import datetime # For convertim time to date\n", "\n", "import pandas as pd # Used for data handling and manipulation\n", "import matplotlib.pyplot as plt # Used for plotting spectrum\n", "import matplotlib.pylab as pylab # Used for increasing size of plot\n", "from mpl_toolkits.mplot3d import Axes3D # For 3 D plot\n", "\n", "import plotly \n", "from plotly import tools\n", "plotly.tools.set_credentials_file(username='rasp.pi.sensor', api_key='o6as73e2ve')\n", "import plotly.plotly as py # Plotly 3d plot\n", "import plotly.graph_objs as go # Plotly 3d plot\n", "\n", "# Plotly offline\n", "from plotly import __version__\n", "from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\n", "init_notebook_mode(connected=True)\n", "\n", "import scipy as sp\n", "import scipy.interpolate as interpolate # Interpolation\n", "import scipy.optimize as optimize # Finding intersections\n", "\n", "# For low pass filter\n", "from scipy.signal import butter, lfilter, freqz, filtfilt\n", "from scipy import signal # Used for converting from time domain to power spectrum \n", "\n", "# Non-Linear Least-Squares Minimization and Curve-Fitting for Python\n", "from lmfit import minimize, Parameters, Model\n", "\n", "# For Latex equations\n", "from IPython.display import Latex, Image, SVG\n", "\n", "# Statistical data exploration\n", "import statsmodels.api as sm\n", "\n", "# For ribust to outlier regression\n", "import sklearn as sk\n", "\n", "# Peak detection\n", "import peakutils\n", "from peakutils.plot import plot as pplot\n", "\n", "# Plotting regression \n", "# import seaborn as sns\n", "\n", "# For calculating uncertainties\n", "#from uncertainties import ufloat\n", "#from uncertainties.umath import *\n", "\n", "# Fitter package for identifying distributions\n", "from fitter import Fitter\n", "\n", "from statsmodels.sandbox.regression.predstd import wls_prediction_std" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first step is to import all the data for all 5 points and the vessel into dataframes. The 5 points are the \n", "different locations where the markers were placed. Each dataframe contains acceleration (X,Y,Z) and position\n", "(X,Y,Z) with respect to time. The body dataframe contains position (X,Y,Z) and rotations (Roll, Pitch, Yaw) with\n", "respect to time. The sample frequency used during the data collection was 60 Hz. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Read data and specify sample frequency" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-05-17T12:50:16.446022Z", "start_time": "2018-05-17T12:50:16.395417Z" } }, "outputs": [], "source": [ "# READ DATA FROM CSV AND MAKE TIME COLUMN THE INDEX\n", "sample_freq = 60\n", "\n", "for i in range(1,6):\n", " globals()[\"p\"+str(i)] = pd.read_csv('p'+str(i)+'.csv')\n", " globals()[\"p\"+str(i)] = globals()[\"p\"+str(i)].set_index('Time', drop=False)\n", "\n", "# Read body data \n", "body = pd.read_csv('body.csv')\n", "body = body.set_index('Time', drop=False)" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "# Make Positions fixed for entire recording for all markers using positions when there are no waves/no motion (10 secs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "time = 10\n", "t = round(time / 0.016667)\n", "\n", "for i in range(1,6):\n", " globals()[\"p\"+str(i)]['Pos_X'] = globals()[\"p\"+str(i)].iloc[t].Pos_X\n", " globals()[\"p\"+str(i)]['Pos_Y'] = globals()[\"p\"+str(i)].iloc[t].Pos_Y\n", " globals()[\"p\"+str(i)]['Pos_Z'] = globals()[\"p\"+str(i)].iloc[t].Pos_Z" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# View positions of markers on vessel at a time (t) " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2018-05-17T12:50:16.470347Z", "start_time": "2018-05-17T12:50:16.447616Z" } }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "marker": { "line": { "color": "rgba(217, 217, 217, 0.14)", "width": 0.5 }, "opacity": 0.8, "size": 6 }, "mode": "markers+text", "text": [ "p1", "p2", "p3", "p4", "p5(C)" ], "type": "scatter3d", "x": [ 12168.192, 9938.082, 11467.062, 10577.072, 11116.306999999999 ], "y": [ 1976.95, 1942.84, 2109.974, 1878.5539999999999, 1954.557 ], "z": [ -12.225999999999999, 12.388, -17.332, -2.805, -4.445 ] } ], "layout": { "margin": { "b": 0, "l": 0, "r": 0, "t": 0 }, "scene": { "xaxis": { "title": "X Axis [mm]" }, "yaxis": { "range": [ 1800, 3200 ], "title": "Y Axis [mm]" }, "zaxis": { "range": [ -100, 100 ], "title": "Z Axis [mm]" } }, "title": "Position of markers" } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# SHOW POSITIONS OF ACCELEROMETERS on ASV\n", "time = 1 # secs\n", "# Use time to obtain index using sampling freq of 60Hz (period = 1/60)\n", "t = round(time / 0.016667)\n", "\n", "xs = [p1.iloc[t].Pos_X, p2.iloc[t].Pos_X, p3.iloc[t].Pos_X, \n", " p4.iloc[t].Pos_X, p5.iloc[t].Pos_X]\n", "ys = [p1.iloc[t].Pos_Y, p2.iloc[t].Pos_Y, p3.iloc[t].Pos_Y, \n", " p4.iloc[t].Pos_Y, p5.iloc[t].Pos_Y]\n", "zs = [p1.iloc[t].Pos_Z, p2.iloc[t].Pos_Z, p3.iloc[t].Pos_Z,\n", " p4.iloc[t].Pos_Z, p5.iloc[t].Pos_Z]\n", "lbls = ['p1','p2','p3','p4','p5(C)']\n", "\n", "trace1 = go.Scatter3d(x=xs,y=ys,z=zs,text=lbls,mode='markers+text',\n", " marker=dict(size=6,\n", " line=dict(color='rgba(217, 217, 217, 0.14)',\n", " width=0.5),\n", " opacity=0.8))\n", "\n", "data = [trace1]\n", "layout = go.Layout(title = 'Position of markers',\n", " scene = dict(xaxis=dict(title = 'X Axis [mm]'),\n", " #range=[0,3000]),\n", " yaxis=dict(title = 'Y Axis [mm]',\n", " range=[1800,3200]),\n", " zaxis=dict(title = 'Z Axis [mm]',\n", " range=[-100,100])),\n", " margin=dict(l=0,r=0,b=0,t=0))\n", "\n", "fig = go.Figure(data=data, layout=layout)\n", "#py.iplot(fig, filename='simple-3d-scatter')\n", "plotly.offline.iplot(fig, filename='simple-3d-scatter')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the figure above, marker 5 is at the centre of mass of the vessel which was previously calculated based on the\n", "weights in the vessel. Marker p1 is at the stern and p2 is at the bow." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next stage is to view the position, rotation and acceleration plots for all 5 points. Below, only a subset of\n", "the data is used going forward as the developed system is meant to be used when the vessel is in motion" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2018-05-17T12:50:17.423176Z", "start_time": "2018-05-17T12:50:16.472166Z" } }, "outputs": [ { "data": { "text/plain": [ "