-
Notifications
You must be signed in to change notification settings - Fork 0
Solutions (So Far)
By Brendon and Jasmine
The ride identification number for this experiment was 14888. This can be used to look up the "ride session" on the Smartfin website where you can download the data for your own analysis. Oceanographers at SIO let us use the CDIP buoy calibrator, and we got a really nice-looking sine wave for this experiment.
Data was recorded at a sampling rate of 5 Hz, and the buoy calibrator was set to generate "waves" with a 6.25 second period, corresponding to a peak frequency at 0.16 Hz. The vertical displacement (or “wave height”) was set to be 1.8m.
Image 1. A portion of the acceleration in the vertical direction obtained from the buoy calibrator experiment.
-
(All included in cell 10):
-
Step 1: Detrend the data
-
Step 2: Take the FFT of acceleration
-
Step 3: Shift the FFT of acceleration
-
Step 4: Normalize the FFT of acceleration
-
Step 5: Multiply the FFT of acceleration signal by 1/w^2 where w = 2pif (f is the peak frequency that we got from the FFT of acceleration, in this case it was approx 0.16)
-
Image 2. Graph of vertical displacement in the frequency domain, produced from the buoy calibrator experiment.
Our algorithm produced the following results: a reported peak frequency of 0.159651669086 and a reported wave height of 1.74061502787. Again, the actual expected value for peak frequency was 0.16 and for wave height was 1.8m. We calculate the percent error in the table below.
Peak Frequency (Hz) | Wave Height (m) | |
Actual | 0.16 | 1.8 |
Calculated | 0.159651669086 | 1.74061502787 |
Standard Error | 0.00217706818 | 0.03299165118 |
% Standard Error | 0.22% | 3.30% |
We can use a method of doubly integrating our vertical acceleration data to obtain vertical displacement data. We can then use this data to determine significant wave height. Significant wave height is a statistical measurement for determining wave height from irregular waves; it is calculated as the mean of the largest one third, or 33%, of all waves.
Image 3. Using a peak picking algorithm to determine the largest 1/3 of wave heights.
Significant Wave Height [m] | |
Actual | 1.8 |
Calculated | 1.8887834075897778 |
Standard Error | 0.04932411532 |
% Standard Error | 4.93% |
In this experiment, we see that our double integration wave analysis performs similarly to our spectral analysis when determining wave height.
When analyzing near-perfect waves, our methodology for determining wave height and period closely matches what we expected. These experiments demonstrate that our methodologies are basically correct (<5% error) for each of these statistics in this best-case scenario. However, real world ocean data does not look exactly like the near-perfect data that we tested in this experiment, as exemplified by the image below.
Image 4. Theoretical perfect ocean waves (pictured above) and actual irregular ocean waves (pictured below). Source: https://cdip.ucsd.edu/m/documents/wave_measurement.html
Since ocean waves will always have irregular waves due to fundamental variability on the sea surface [CDIP], we will have to calculate wave characteristics using statistical terms. For significant wave height, we will take the mean of the largest ⅓ of waves recorded during the sampling period. CDIP normally calculates these characteristics over a short-term period, for example, for one hour or less. The majority of CDIP’s parameters are calculated over a 30 minute time period.
The next test that we did was a controlled pool experiment in the UCSD Canyonview pool. This corresponds to ride ID number 14827 on the Smartfin website. Our experiment contained 3 sub-experiments, each with the Smartfin mounted onto a pole vertically. We simulated different wave heights by vertically displacing the Smartfin in the pool different distances and speeds. This was done to collect data in a controlled environment that more closely mirrored the type of data that we would expect to obtain from the ocean. We viewed the raw acceleration readings in a graph and then processed the data to get the resulting displacement as well as FFT. Notes for each of the sub-experiments are included below.
We collected data at a sampling rate of 30Hz for each experiment.
The first controlled experiment that we did was creating a sinusoidal wave with a total vertical displacement of 1.8m (amplitude of 0.9m) and** period of 6 seconds (corresponding to a frequency of 0.16Hz).**
The second controlled experiment that we did was creating a wave with a total vertical displacement of 1.5m (amplitude of 0.75m) and** period of 4 seconds (corresponding to a frequency of 0.25Hz).**
The third controlled experiment that we did was creating al wave with a total vertical displacement of 0.9m (amplitude of 0.45m) and period of 2 seconds (corresponding to a frequency of 0.5Hz).
Image 4. Vertical Acceleration vs. time for each of the controlled pool sub-experiments.
After doubly integrating, detrending, and filtering the results of each integration step, we obtain the following graphs of Vertical displacement vs. Time for each of the sub-experiments.
Again, we can view the wave heights that were produced in order to analyze our standard error in calculating the significant wave height using each of these methods.
Actual Wave Height [m] | Calculated Wave Height [m] | Standard Error | |
Experiment #1 | 1.8 | 2.0632722103091106 | 0.1462633906 |
Experiment #2 | 1.5 | 2.0850691485538615 | 0.39004609903 |
Experiment #3 | 0.9 | 0.8514080931935583 | 0.05399100756 |
Here, we see that we often overestimate the actual wave height when computing significant wave height. However, because significant wave height is a statistical measure that takes into account only the top 33% of waves, this is to be expected. In particular, it seems like we have a great standard error for our second experiment; this is because of the unexpected large wave that we see in the middle of the graph. Because we were only sampling waves for a short period of time, this wave dominates our series. When we take more waves into consideration, for example looking at the top 50% of waves rather than the top 33% of waves (to account for errors in the manual creation of our waves), these errors drop significantly. The following table demonstrates the standard error present in this new wave height metric, which can be compared to the previous significant wave height metric.
Actual Wave Height [m] | Calculated Wave Height [m] | Standard Error | |
Experiment #1 | 1.8 | 1.9848564307387153 | 0.10269801707 |
Experiment #2 | 1.5 | 1.619954942662752 | 0.07996996177 |
Experiment #3 | 0.9 | 0.8514080931935583 | 0.05399100756 |
In order to determine how our methodology would perform in an actual real world setting, we had a surfer float in the ocean on their surfboard. We then calculated the significant wave height from that data, and attempted to compare it against CDIP data taken from the same day.
#Samprith Kalakata
#May, 2019
#Attempting to calculate significant wave height from data generated from SmartFin (https://smartfin.org/)
#Research consulted: https://journals.ametsoc.org/doi/pdf/10.1175/2010JTECHO724.1
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from mpl_toolkits.basemap import Basemap
import pandas as pd
import numpy as np
from scipy import stats
from scipy import constants
from scipy import signal #added
from scipy.interpolate import CubicSpline
from scipy.interpolate import interp1d
from scipy.integrate import simps
from scipy.integrate import cumtrapz
from scipy.signal import butter, lfilter, freqz
import os
import datetime
import pytz
import re
import peakutils
import statsmodels.api as sm
import requests
import mpld3
import folium
#import cmocean
import skinematics as skin
from skinematics import quat, vector, misc, rotmat, imus, view
import pygame
from plotly import tools #added all the plotly's
import plotly.offline
import plotly.graph_objs as go
import math #added
import re #added
# For the definition of the abstract base class IMU_Base
import abc
import sys
# %matplotlib notebook
%matplotlib inline
ride_ids = ['15218']
# 14743 - Motion Control July 10th
# 14750 - Magnetometer Control July 11th
# 14814 - Pool Displacement Control July 17th
# 14815 - Compass Orientation (Lying on Charger Side) July 19th
# 14816 - Orientation w Higher Sampling (Lying on Charger Side) July 20th
# 14827 - Pool Displacement Control w Higher Sampling (Jul 23)
# 14888 - First Buoy Calibration Experiment (July 30)
# 15218 - Jasmine's Second Ride Sesh filmed with GoPro (Aug 29)
#%% Fin ID scraper
# Input fin ID, get all ride IDs
# base URL to which we'll append given fin IDs
fin_url_base = 'http://surf.smartfin.org/fin/'
# Look for the following text in the HTML contents in fcn below
str_id_ride = 'rideId = \'' # backslash allows us to look for single quote
str_id_date = 'var date = \'' # backslash allows us to look for single quote
#%% Ride ID scraper
# Input ride ID, get ocean and motion CSVs
# Base URL to which we'll append given ride IDs
ride_url_base = 'https://surf.smartfin.org/ride/'
# Look for the following text in the HTML contents in fcn below
str_id_csv = 'img id="temperatureChart" class="chart" src="'
def get_csv_from_ride_id(rid):
# Build URL for each individual ride
ride_url = ride_url_base+str(rid)
print(ride_url)
# Get contents of ride_url
html_contents = requests.get(ride_url).text
# Find CSV identifier
loc_csv_id = html_contents.find(str_id_csv)
# Different based on whether user logged in with FB or Google
offset_googleOAuth = [46, 114]
offset_facebkOAuth = [46, 112]
if html_contents[loc_csv_id+59] == 'f': # Facebook login
off0 = offset_facebkOAuth[0]
off1 = offset_facebkOAuth[1]
else: # Google login
off0 = offset_googleOAuth[0]
off1 = offset_googleOAuth[1]
csv_id_longstr = html_contents[loc_csv_id+off0:loc_csv_id+off1]
# print(csv_id_longstr)
# Stitch together full URL for CSV
if ("media" in csv_id_longstr) & ("Calibration" not in html_contents): # other junk URLs can exist and break everything
ocean_csv_url = 'https://surf.smartfin.org/'+csv_id_longstr+'Ocean.CSV'
motion_csv_url = 'https://surf.smartfin.org/'+csv_id_longstr+'Motion.CSV'
print(ocean_csv_url)
# Go to ocean_csv_url and grab contents (theoretically, a CSV)
ocean_df_small = pd.read_csv(ocean_csv_url, parse_dates = [0])
elapsed_timedelta = (ocean_df_small['UTC']-ocean_df_small['UTC'][0])
ocean_df_small['elapsed'] = elapsed_timedelta/np.timedelta64(1, 's')
motion_df_small = pd.read_csv(motion_csv_url, parse_dates = [0])
# Reindex on timestamp if there are at least a few rows
if len(ocean_df_small) > 1:
ocean_df_small.set_index('UTC', drop = True, append = False, inplace = True)
motion_df_small.set_index('UTC', drop = True, append = False, inplace = True)
#print(ocean_df_small)
#May need to change this sampling interval:
sample_interval = '33ms'
ocean_df_small_resample = ocean_df_small.resample(sample_interval).mean()
motion_df_small_resample = motion_df_small.resample(sample_interval).mean()
# No need to save many extra rows with no fix
motion_df_small = motion_df_small[~np.isnan(motion_df_small.Latitude)]
return ocean_df_small_resample, motion_df_small_resample
else:
ocean_df_small_resample = pd.DataFrame() # empty DF just so something is returned
motion_df_small_resample = pd.DataFrame()
return ocean_df_small_resample, motion_df_small_resample
appended_ocean_list = [] # list of DataFrames from original CSVs
appended_motion_list = []
appended_multiIndex = [] # fin_id & ride_id used to identify each DataFrame
## Nested loops (for each fin ID, find all ride IDs, then build a DataFrame from all ride CSVs)
## (Here, ride IDS are either ocean or motion dataframes)
count_good_fins = 0
# Loop over ride_ids and find CSVs
for rid in ride_ids:
try:
new_ocean_df, new_motion_df = get_csv_from_ride_id(rid) # get given ride's CSV from its ride ID using function above
#print(len(new_ocean_df))
#print(len(new_motion_df))
if not new_ocean_df.empty: # Calibration rides, for example
# Append only if DF isn't empty. There may be a better way to control empty DFs which are created above
appended_multiIndex.append(str(rid)) # build list to be multiIndex of future DataFrame
appended_ocean_list.append(new_ocean_df)
appended_motion_list.append(new_motion_df)
print("Ride data has been uploaded.")
#print("Ride: ", rid, "data has been uploaded.")
count_good_fins += 1
except:
print("Ride threw an exception!")
#print("Ride ", rid, "threw an exception!")
#%% Build the "Master" DataFrame
# appended_ocean_df.summary()
df_keys = tuple(appended_multiIndex) # keys gotta be a tuple, a list which data in it cannot be changed
ocean_df = pd.concat(appended_ocean_list, keys = df_keys, names=['ride_id'])
motion_df = pd.concat(appended_motion_list, keys = df_keys, names = ['ride_id'])
##Here, maybe just use info from the motion_df and don't worry about ocean_df data for now.
##If you do want ocean_df data, look at how Phil was getting it from "July 10th and 11th Calibration" jupyter notebook file.
#print(motion_df)
print("finished fetching data frame")
https://surf.smartfin.org/ride/15218
https://surf.smartfin.org/media/201808/google_105349665704999793400_0006667E229D_180829164842_Ocean.CSV
Ride data has been uploaded.
finished fetching data frame
#print(motion_df)
saved_copy_motion_df = motion_df.copy(deep=True) #make a copy of the dataframe with raw data
#Reading data from ride_ids = ['xxxxx']
#The name of the motion dataframe is: motion_df
#Get times from the "Time" column to create time_o_list and time_e_list.
#Get imus from the "IMU A[*]" column to create the imu acc arrays.
#Drop the "nan" values from the columns that we care about.
dropped_motion_df = motion_df.dropna(subset=['Time', 'IMU A1', 'IMU A2', 'IMU A3'])
#Can test that this works by printing this one:
#dropped_motion_df = motion_df.dropna(subset=['Time', 'IMU A1', 'IMU A2', 'IMU A3', 'Latitude'])
#print(dropped_df)
time_e_list = []
time_o_list = []
#Remove all nan instances in time:
time_array_nans = np.array(dropped_motion_df.loc[:,"Time"], dtype=float)
time_array = []
imu1_array_nans = np.array(dropped_motion_df.loc[:,"IMU A1"], dtype=float)
imu_array1 = []
imu2_array_nans = np.array(dropped_motion_df.loc[:,"IMU A2"], dtype=float)
imu_array2 = []
imu3_array_nans = np.array(dropped_motion_df.loc[:,"IMU A3"], dtype=float)
imu_array3 = []
#Get all the times and imus where time, imu1, imu2, and imu3 are NOT nan values:
for t,x,y,z in zip(time_array_nans, imu1_array_nans, imu2_array_nans, imu3_array_nans):
if (np.isnan(t)==0 and np.isnan(x)==0 and np.isnan(y)==0 and np.isnan(z)==0):
time_array.append(t)
imu_array1.append(x)
imu_array2.append(y)
imu_array3.append(z)
#for x in time_array:
# print(x)
start_time = time_array[0]
time_len = len(time_array)
i = 0
while (i < time_len - 1):
prev = time_array[i]
after = time_array[i+1]
#print(prev, " ", after)
#print(after - prev)
offset = after - prev
#if (np.isnan(offset)==0):
time_o_list.append(offset)
elapsed = time_array[i] - start_time
#if (np.isnan(elapsed)==0):
time_e_list.append(elapsed)
i = i + 1
##Check to make sure there are no "nan" values:
i = 0
while (i < len(time_o_list)):
if (np.isnan(time_o_list[i])):
print("Error! Value at index: ", i, " is nan")
i = i + 1
#Drop the last value from each of the imu lists to make it match the time list.
del(imu_array1[-1])
del(imu_array2[-1])
del(imu_array3[-1])
print(len(time_e_list))
print(len(time_o_list))
print(len(imu_array1))
print(len(imu_array2))
print(len(imu_array3))
8348
8348
8348
8348
8348
## Convert raw units to actual units (acc to [m/s^2]) and (time to [s])
#Raw acceleration constant 512 = 1g (accelerometer's measured force due to gravity)
g_const = 512
#Approximate measurement for gravity:
gravity = -9.80665
# Correct the IMU Acceleration columns into units of meters
# Dividing by 512 is equivalent to muliplying by 4 to correct the bit shifting by 2 places and dividing by 2048 to convert bits to G's
# Multiplying by the 9.81 afterwards is simply to convert G's into m/s^2
def convert_acc_units(acc_array):
ret_array = []
for a in acc_array:
#Acceleration is now in m/s^2, need to subtract gravity from vertical axis. (??)
new_a = a / g_const * gravity - gravity
ret_array.append(new_a)
return ret_array
imu1_array = convert_acc_units(imu_array1) #new units in m/s^2
imu2_array = convert_acc_units(imu_array2) #new units in m/s^2
imu3_array = convert_acc_units(imu_array3) #new units in m/s^2
##To check:
#for x,y in zip(imu2_array, imu_array2):
# print(x,y)
def convert_time_units(time_array):
ret_array = []
for t in time_array:
new_t = t * (10**(-3)) #converting units in milliseconds to seconds
ret_array.append(new_t)
return ret_array
time_o_array = convert_time_units(time_o_list) #new units in seconds
time_e_array = convert_time_units(time_e_list) #new units in seconds
#Seperate each of the subexperiments into its own acc lists.
#i.e. subexperiment1 corresponds to acc1, (subexperiment2 => acc2), etc.
time_e_list1 = []
time_e_list2 = []
time_e_list3 = []
acc_list = []
acc_list1 = []
acc_list2 = []
acc_list3 = []
time_array = []
acc_array = []
gravity = -9.80665
#For our controlled experiments, we know that imu2 is the vertical axis
acc_list = imu2_array
########## new db ##########
acc_list_FB = imu1_array
acc_list_SD = imu3_array
i = 0
while (i < (len(acc_list)) - 1):
if (time_e_array[i] > 300 and time_e_array[i] <= 450):
acc_list1.append(acc_list[i])
time_e_list1.append(time_e_array[i])
if (time_e_array[i] > 450 and time_e_array[i] <= 670):
acc_list2.append(acc_list[i])
time_e_list2.append(time_e_array[i])
if (time_e_array[i] > 670 and time_e_array[i] <= 850):
acc_list3.append(acc_list[i])
time_e_list3.append(time_e_array[i])
i = i + 1
print
#Plot the subexperiments to verify correctness:
for a,t in zip(acc_list,time_e_array): #acc_array becomes only acc values we care about
if t > 300 and t <= 850:
acc_array.append(a)
time_array.append(t)
time_array = np.array(time_array)
acc_array = np.array(acc_array)
time_array1 = np.array(time_e_list1)
acc_array1 = np.array(acc_list1)
time_array2 = np.array(time_e_list2)
acc_array2 = np.array(acc_list2)
time_array3 = np.array(time_e_list3)
acc_array3 = np.array(acc_list3)
##PSD Step 2: Detrend the data
dacc_array1 = signal.detrend(acc_array1)
dacc_array2 = signal.detrend(acc_array2)
dacc_array3 = signal.detrend(acc_array3)
########## new db ##########
dacc_array_FB = signal.detrend(acc_list_FB)
dacc_array_SD = signal.detrend(acc_list_SD)
std1_FB = np.std(dacc_array_FB)*3
std3_SD = np.std(dacc_array_SD)*3
##Remove outliers--points greater than 3x the standard deviation
std1 = np.std(dacc_array1)*3
std2 = np.std(dacc_array2)*3
std3 = np.std(dacc_array3)*3
#Returns a new array that is the same as the array passed in, with its outliers removed.
def removed_outliers(a_array, time_array, std):
i = 0
count = 0
ret_accs = []
ret_times = []
while i < (len(a_array)):
#if smaller than std, keep that value (larger ones get removed)
if abs(a_array[i]) < std:
ret_accs.append(a_array[i])
ret_times.append(time_array[i])
else:
count = count + 1 #could help with debugging to know how many outliers removed
i = i + 1
return count, ret_accs, ret_times;
count1, ro_array1, ro_time1 = removed_outliers(dacc_array1, time_array1, std1)
count2, ro_array2, ro_time2 = removed_outliers(dacc_array2, time_array2, std2)
count3, ro_array3, ro_time3 = removed_outliers(dacc_array3, time_array3, std3)
########## new db ##########
count1_FB, ro_array1_FB, ro_time1_FB = removed_outliers(dacc_array_FB, time_e_array, std1_FB)
count3_SD, ro_array3_SD, ro_time3_SD = removed_outliers(dacc_array_SD, time_e_array, std3_SD)
#print(len(dacc_array1))
#print(count1)
#print(len(ro_array1))
##Set up data interpolation (using Cubic Splines) for use in next step
cs1 = CubicSpline(ro_time1, ro_array1)
cs2 = CubicSpline(ro_time2, ro_array2)
cs3 = CubicSpline(ro_time3, ro_array3)
########## new db ##########
cs1_FB = CubicSpline(ro_time1_FB, ro_array1_FB)
cs3_SD = CubicSpline(ro_time3_SD, ro_array3_SD)
##interpld returns a function that relates y=ro_array (without outliers) to x=time:
#cs1 = interp1d(ro_time1, ro_array1)
#cs2 = interp1d(ro_time2, ro_array2)
#cs3 = interp1d(ro_time3, ro_array3)
#Now, use this interpolation to put points back into the original graph:
def add_interpolated_pts(a_array, time_array, std, cs):
i = 0
ret_acc = []
while i < (len(a_array)):
if abs(a_array[i]) > std:
ret_acc.append(cs(time_array[i]))
else:
ret_acc.append(a_array[i])
i = i + 1
return ret_acc;
#These are the new arrays with the interpolated points (which we will
#feed into a Kalman filter later).
interp_array1 = add_interpolated_pts(dacc_array1, time_array1, std1, cs1)
interp_array2 = add_interpolated_pts(dacc_array2, time_array2, std2, cs2)
interp_array3 = add_interpolated_pts(dacc_array3, time_array3, std3, cs3)
########## new db ##########
interp_array1_FB = add_interpolated_pts(dacc_array_FB, time_e_array, std1_FB, cs1_FB)
interp_array3_SD = add_interpolated_pts(dacc_array_SD, time_e_array, std3_SD, cs3_SD)
#print(len(interp_array1))
#print(len(dacc_array1))
##To verify that the two arrays are different(i.e. pts were actually interpolated):
j = 0
count = 0
while (j < (len(interp_array1) - 1)):
if interp_array1[j] != dacc_array1[j]:
count = count + 1
j = j + 1
#print(count)
##Now, feed interpolated arrays through a Kalman filter:
##(Actually I'm going to use a LOWESS filter for simplicity)
#print("\n")
#print("Here, I'm implementing a lowess filter instead of a Kalman \n filter right now because it seems simpler to implement.")
#print("\n")
lowess = sm.nonparametric.lowess
#Parameters: takes in (y,x, ...)
filtered1 = lowess(interp_array1, time_array1, frac=0.005, is_sorted=True, return_sorted=False)
filtered2 = lowess(interp_array2, time_array2, frac=0.002, is_sorted=True, return_sorted=False)
filtered3 = lowess(interp_array3, time_array3, frac=0.002, is_sorted=True, return_sorted=False)
########## new db ##########
filtered1_FB = lowess(interp_array1_FB, time_e_array, frac=0.002, is_sorted=True, return_sorted=False)
filtered3_SD = lowess(interp_array3_SD, time_e_array, frac=0.002, is_sorted=True, return_sorted=False)
#First, find peaks and valleys of the waveforms:
#(Found that this works better when the data has been detrended.)
indexes0 = peakutils.indexes(acc_array, thres=0.02/max(acc_array), min_dist=100)
indexes1 = peakutils.indexes(dacc_array1, thres=0.02/max(dacc_array1), min_dist=100)
indexes2 = peakutils.indexes(dacc_array2, thres=0.02/max(dacc_array2), min_dist=100)
indexes3 = peakutils.indexes(dacc_array3, thres=0.02/max(dacc_array3), min_dist=100)
########## new db ##########
indexes1_FB = peakutils.indexes(dacc_array_FB, thres=0.02/max(dacc_array_FB), min_dist=100)
indexes3_SD = peakutils.indexes(dacc_array_SD, thres=0.02/max(dacc_array_SD), min_dist=100)
col_0t = time_array # First column data
col_0a = acc_array # Second column data
col_1t = time_array1 # First column data
col_1a = dacc_array1 # Second column data
col_2t = time_array2 # First column data
col_2a = dacc_array2 # Second column data
col_3t = time_array3 # First column data
col_3a = dacc_array3 # Second column data
#Index1 gets the peaks, while index2 gets the valleys
index_max0 = peakutils.indexes(col_0a, thres=0.66, min_dist=25)
index_min0 = peakutils.indexes(-col_0a, thres=0.66, min_dist=25)
index_max1 = peakutils.indexes(col_1a, thres=0.66, min_dist=25)
index_min1 = peakutils.indexes(-col_1a, thres=0.66, min_dist=25)
index_max2 = peakutils.indexes(col_2a, thres=0.66, min_dist=25)
index_min2 = peakutils.indexes(-col_2a, thres=0.66, min_dist=25)
index_max3 = peakutils.indexes(col_3a, thres=0.66, min_dist=25)
index_min3 = peakutils.indexes(-col_3a, thres=0.66, min_dist=25)
#First integral of acc to get velocity:
from scipy import integrate
def calculate_new_range(time_array, array_of_values, low_time, high_time):
new_time_array = []
new_value_array = []
for t,v in zip(time_array, array_of_values):
if (t > low_time and t < high_time):
new_time_array.append(t)
new_value_array.append(v)
return new_time_array, new_value_array
new_time_array2, new_dacc_array2 = calculate_new_range(time_array2, dacc_array2, 500, 640)
############################# new dr ##########################
new_time_array_FB, new_dacc_array_FB = calculate_new_range(time_e_array, dacc_array_FB, 0, 200)
new_time_array_SD, new_dacc_array_SD = calculate_new_range(time_e_array, dacc_array_SD, 0, 200)
############################# new dr ##########################
int1_FB = integrate.cumtrapz(x=new_time_array_FB, y=new_dacc_array_FB, initial=0) #First integral is the velocity:
dint1_FB = signal.detrend(int1_FB)
int2_FB = integrate.cumtrapz(x=new_time_array_FB, y=dint1_FB, initial=0) #Second integral is the displacment:
dint2_FB = signal.detrend(int2_FB)
int1_SD = integrate.cumtrapz(x=new_time_array_SD, y=new_dacc_array_SD, initial=0) #First integral is the velocity:
dint1_SD = signal.detrend(int1_SD)
int2_SD = integrate.cumtrapz(x=new_time_array_SD, y=dint1_SD, initial=0) #Second integral is the displacment:
dint2_SD = signal.detrend(int2_SD)
#First integral is the velocity:
int1 = integrate.cumtrapz(x=new_time_array2, y=new_dacc_array2, initial=0)
dint1 = signal.detrend(int1)
#Second integral is the displacment:
int2 = integrate.cumtrapz(x=new_time_array2, y=dint1, initial=0)
dint2 = signal.detrend(int2)
f1 = plt.figure(figsize=(12,5))
ax1 = f1.add_subplot(121)
ax2 = f1.add_subplot(122)
f2 = plt.figure(figsize=(12,5))
ax3 = f2.add_subplot(121)
ax4 = f2.add_subplot(122)
ax1.plot(new_time_array2, int1)
ax1.set_title('Velocity vs. Time')
ax1.set_xlabel('Time [s]')
ax1.set_ylabel('Velocity [m/s]')
ax1.axhline(0, color="orange", ls='--')
ax2.plot(new_time_array2, dint1)
ax2.set_title('Detrended Velocity vs. Time')
ax2.set_xlabel('Time [s]')
ax2.set_ylabel('Velocity [m/s]')
ax2.axhline(0, color="orange",ls='--')
ax3.plot(new_time_array2, int2)
ax3.set_title('Displacement vs. Time')
ax3.set_xlabel('Time [s]')
ax3.set_ylabel('Displacement [m]')
ax4.plot(new_time_array2, dint2)
ax4.set_title('Detrended Displacement vs. Time')
ax4.set_xlabel('Time [s]')
ax4.set_ylabel('Displacement [m]')
plt.show()
print(dint2_FB)
print(dint2_SD)
[ 2.44213007e+01 2.41713897e+01 2.39480902e+01 2.37479998e+01
2.35507814e+01 2.33350190e+01 2.30935765e+01 2.28422136e+01
2.26004016e+01 2.23601409e+01 2.21048245e+01 2.18418421e+01
2.15781352e+01 2.13019413e+01 2.10098608e+01 2.06830724e+01
2.03422975e+01 2.00006795e+01 1.96621083e+01 1.93090088e+01
1.89419107e+01 1.85659152e+01 1.81822587e+01 1.77953100e+01
1.74059191e+01 1.70078464e+01 1.66251497e+01 1.62471358e+01
1.58788091e+01 1.55076189e+01 1.51333438e+01 1.47541767e+01
1.43671038e+01 1.39700162e+01 1.35653304e+01 1.31581778e+01
1.27537897e+01 1.23539520e+01 1.19745419e+01 1.15943255e+01
1.12235763e+01 1.08636515e+01 1.05145679e+01 1.01802701e+01
9.85378893e+00 9.53422222e+00 9.22492026e+00 8.92703552e+00
8.64501966e+00 8.37680585e+00 8.11433131e+00 7.86634267e+00
7.63856282e+00 7.44185498e+00 7.28128801e+00 7.15393349e+00
7.06115242e+00 6.98225802e+00 6.91769644e+00 6.86789685e+00
6.82986589e+00 6.79625111e+00 6.73451040e+00 6.62989863e+00
6.52261353e+00 6.43393051e+00 6.32986075e+00 6.16614178e+00
5.88539505e+00 5.50640831e+00 5.08387885e+00 4.76030794e+00
4.44176449e+00 4.04959790e+00 3.61193993e+00 3.17458998e+00
2.72881700e+00 2.25910107e+00 1.81045166e+00 1.39778501e+00
1.00475865e+00 6.12204472e-01 2.03159427e-01 -2.11172555e-01
-6.32607784e-01 -1.06661950e+00 -1.51863490e+00 -1.98834935e+00
-2.45370595e+00 -2.93191695e+00 -3.39132753e+00 -3.84505657e+00
-4.29448188e+00 -4.71180844e+00 -5.11377471e+00 -5.55725987e+00
-6.00224134e+00 -6.39732256e+00 -6.73214341e+00 -7.05442083e+00
-7.37474609e+00 -7.67671287e+00 -7.92332936e+00 -8.13088304e+00
-8.32933464e+00 -8.52641277e+00 -8.68003439e+00 -8.75911833e+00
-8.80092947e+00 -8.84238984e+00 -8.83086806e+00 -8.73408035e+00
-8.58896134e+00 -8.38977370e+00 -8.13459708e+00 -7.83098321e+00
-7.42209991e+00 -6.91944551e+00 -6.38970730e+00 -5.87735006e+00
-5.38923953e+00 -4.93140169e+00 -4.48394811e+00 -4.04628180e+00
-3.60500658e+00 -3.17318959e+00 -2.75369590e+00 -2.34906838e+00
-1.96051077e+00 -1.58077994e+00 -1.20293996e+00 -8.29505721e-01
-4.63940827e-01 -8.23110549e-02 3.30110483e-01 7.53392883e-01
1.22797804e+00 1.75249961e+00 2.27875101e+00 2.79321183e+00
3.27555891e+00 3.73050412e+00 4.16202217e+00 4.58743272e+00
4.98494220e+00 5.34788887e+00 5.66981626e+00 5.99411761e+00
6.35389264e+00 6.79203471e+00 7.26274122e+00 7.73705439e+00
8.20683196e+00 8.65035634e+00 9.05822372e+00 9.43479626e+00
9.77658535e+00 1.00703793e+01 1.03267496e+01 1.05686497e+01
1.08125640e+01 1.10732946e+01 1.13526358e+01 1.15967072e+01
1.18014829e+01 1.19738962e+01 1.21049177e+01 1.21895151e+01
1.22421716e+01 1.22934328e+01 1.23362412e+01 1.23601251e+01
1.23902265e+01 1.24310520e+01 1.24797809e+01 1.25503646e+01
1.26611311e+01 1.27930780e+01 1.29271321e+01 1.30626949e+01
1.31973159e+01 1.33190272e+01 1.34300048e+01 1.35424283e+01
1.36736843e+01 1.38244033e+01 1.40007135e+01 1.42194657e+01
1.45002470e+01 1.47321854e+01 1.48445886e+01 1.48822207e+01
1.48942728e+01 1.49077805e+01 1.49328807e+01 1.49659405e+01
1.49852425e+01 1.49470536e+01 1.48214851e+01 1.46114541e+01
1.43519642e+01 1.40749213e+01 1.37997021e+01 1.35369693e+01
1.32943484e+01 1.30653145e+01 1.28403536e+01 1.26015699e+01
1.23497793e+01 1.20934188e+01 1.18492855e+01 1.16394837e+01
1.14318081e+01 1.11842062e+01 1.09453436e+01 1.08115930e+01
1.07691748e+01 1.07579193e+01 1.07154781e+01 1.06208903e+01
1.04979537e+01 1.03263361e+01 1.00797353e+01 9.76213806e+00
9.40371474e+00 9.04320458e+00 8.69771608e+00 8.37932650e+00
8.06303116e+00 7.72991305e+00 7.40018921e+00 7.09002380e+00
6.79601329e+00 6.51617972e+00 6.24723702e+00 5.98380008e+00
5.72197928e+00 5.46995624e+00 5.22176752e+00 4.97110952e+00
4.69772761e+00 4.39233427e+00 4.11236329e+00 3.86164866e+00
3.60504611e+00 3.32470826e+00 3.03890501e+00 2.77147156e+00
2.53447784e+00 2.31490801e+00 2.06317714e+00 1.68734851e+00
1.17206185e+00 5.79696345e-01 -9.19514975e-03 -5.39696971e-01
-1.06268845e+00 -1.61533840e+00 -2.22156385e+00 -2.86128314e+00
-3.49043786e+00 -4.09589883e+00 -4.68294176e+00 -5.27332302e+00
-5.86179511e+00 -6.42323286e+00 -6.95879050e+00 -7.51822861e+00
-8.08178790e+00 -8.64247316e+00 -9.20216227e+00 -9.75586111e+00
-1.03190136e+01 -1.08837926e+01 -1.14427569e+01 -1.19970283e+01
-1.25697534e+01 -1.31543129e+01 -1.37155856e+01 -1.41853340e+01
-1.45638544e+01 -1.49199139e+01 -1.52861596e+01 -1.56586799e+01
-1.60415010e+01 -1.64488029e+01 -1.68992509e+01 -1.73745693e+01
-1.78648790e+01 -1.83697908e+01 -1.89247261e+01 -1.94793398e+01
-2.00354354e+01 -2.05510438e+01 -2.10045378e+01 -2.13669495e+01
-2.15567082e+01 -2.16350393e+01 -2.17185829e+01 -2.18081850e+01
-2.19003478e+01 -2.20150447e+01 -2.21533236e+01 -2.22912199e+01
-2.24281266e+01 -2.25685319e+01 -2.26227728e+01 -2.25317069e+01
-2.23795479e+01 -2.22296520e+01 -2.21263010e+01 -2.21095815e+01
-2.21571756e+01 -2.22557084e+01 -2.24143471e+01 -2.26866591e+01
-2.30796721e+01 -2.34920557e+01 -2.38421300e+01 -2.41131326e+01
-2.43334055e+01 -2.45504761e+01 -2.48014473e+01 -2.50712323e+01
-2.53320743e+01 -2.55800486e+01 -2.58160399e+01 -2.60318107e+01
-2.62195938e+01 -2.63944900e+01 -2.65929678e+01 -2.67942471e+01
-2.69603143e+01 -2.70818142e+01 -2.71670288e+01 -2.72346042e+01
-2.73134133e+01 -2.74629760e+01 -2.76423012e+01 -2.77490578e+01
-2.78000647e+01 -2.78242798e+01 -2.78002811e+01 -2.77461007e+01
-2.77157138e+01 -2.77140314e+01 -2.77021343e+01 -2.76750228e+01
-2.76136462e+01 -2.75043221e+01 -2.74135815e+01 -2.73875435e+01
-2.73787255e+01 -2.73508110e+01 -2.73229146e+01 -2.73206400e+01
-2.73385449e+01 -2.73517852e+01 -2.73128410e+01 -2.72044409e+01
-2.70481891e+01 -2.68739506e+01 -2.66911668e+01 -2.64679743e+01
-2.61992184e+01 -2.59089906e+01 -2.56463611e+01 -2.54585273e+01
-2.53838299e+01 -2.53822779e+01 -2.53198979e+01 -2.51728192e+01
-2.49899107e+01 -2.48066633e+01 -2.46553533e+01 -2.45266258e+01
-2.43720175e+01 -2.42054749e+01 -2.40904595e+01 -2.40310692e+01
-2.39904337e+01 -2.39446090e+01 -2.38656592e+01 -2.37441248e+01
-2.35978329e+01 -2.34742723e+01 -2.33512684e+01 -2.31925886e+01
-2.29837495e+01 -2.27491838e+01 -2.25278045e+01 -2.23226255e+01
-2.21352470e+01 -2.19634508e+01 -2.17093932e+01 -2.13218181e+01
-2.08884176e+01 -2.04165096e+01 -1.99515528e+01 -1.95210562e+01
-1.91053891e+01 -1.87010660e+01 -1.83014471e+01 -1.79327751e+01
-1.76224994e+01 -1.73289860e+01 -1.70127127e+01 -1.66914699e+01
-1.63319740e+01 -1.59560445e+01 -1.55790639e+01 -1.52288899e+01
-1.49475137e+01 -1.47778072e+01 -1.47339138e+01 -1.46900767e+01
-1.45261618e+01 -1.43000283e+01 -1.40881731e+01 -1.38910041e+01
-1.37011422e+01 -1.35451762e+01 -1.34516959e+01 -1.34072290e+01
-1.33666868e+01 -1.33368146e+01 -1.33800560e+01 -1.35573461e+01
-1.38037805e+01 -1.39751262e+01 -1.40445884e+01 -1.40501208e+01
-1.40026230e+01 -1.39379412e+01 -1.38936937e+01 -1.38862834e+01
-1.39157583e+01 -1.39591863e+01 -1.39903187e+01 -1.40060680e+01
-1.40084096e+01 -1.39991108e+01 -1.39902607e+01 -1.40339240e+01
-1.41912477e+01 -1.44445462e+01 -1.46564795e+01 -1.47568400e+01
-1.48373335e+01 -1.48975027e+01 -1.48568823e+01 -1.47112075e+01
-1.45046467e+01 -1.42806620e+01 -1.40584703e+01 -1.38701454e+01
-1.36979597e+01 -1.35345851e+01 -1.33545405e+01 -1.31473721e+01
-1.29308989e+01 -1.27368335e+01 -1.26307027e+01 -1.24962186e+01
-1.21201812e+01 -1.15449788e+01 -1.08581710e+01 -1.00344603e+01
-9.16230098e+00 -8.34247023e+00 -7.51851955e+00 -6.70851997e+00
-5.92787692e+00 -5.15619638e+00 -4.39531743e+00 -3.62275356e+00
-2.83114531e+00 -2.04550455e+00 -1.30501076e+00 -6.29097065e-01
-5.23084858e-02 3.87390006e-01 7.31940626e-01 9.48334491e-01
1.19629339e+00 1.63559092e+00 2.24752275e+00 2.95480908e+00
3.63295682e+00 4.18753834e+00 4.62552991e+00 5.02918768e+00
5.38526695e+00 5.67657524e+00 5.90281383e+00 6.08027606e+00
6.25256310e+00 6.46224419e+00 6.71500849e+00 6.99494411e+00
7.27838321e+00 7.53158370e+00 7.78723206e+00 8.01897898e+00
8.15382344e+00 8.16191584e+00 8.20874980e+00 8.39854934e+00
8.68329804e+00 9.02663180e+00 9.38799398e+00 9.75514816e+00
1.01001234e+01 1.04132653e+01 1.07294343e+01 1.10749695e+01
1.14190485e+01 1.16984661e+01 1.19375686e+01 1.21605436e+01
1.23346005e+01 1.23937507e+01 1.23561887e+01 1.23374533e+01
1.23808603e+01 1.24458581e+01 1.25173548e+01 1.25779661e+01
1.26242875e+01 1.26577193e+01 1.26795727e+01 1.26817419e+01
1.26606546e+01 1.26022197e+01 1.24993467e+01 1.23532454e+01
1.21638492e+01 1.19388874e+01 1.17018108e+01 1.14914772e+01
1.13318313e+01 1.12188607e+01 1.11438065e+01 1.10919401e+01
1.10439410e+01 1.09889549e+01 1.09317205e+01 1.08933928e+01
1.08881986e+01 1.08540052e+01 1.06889244e+01 1.04006212e+01
1.01850589e+01 1.01421057e+01 1.01632294e+01 1.02227707e+01
1.03480524e+01 1.05386840e+01 1.07562767e+01 1.09490454e+01
1.10818307e+01 1.11412879e+01 1.11463387e+01 1.11130748e+01
1.10664124e+01 1.10324180e+01 1.10243100e+01 1.10330368e+01
1.10472111e+01 1.10744341e+01 1.11113370e+01 1.11645954e+01
1.12353710e+01 1.12924439e+01 1.12645745e+01 1.10555134e+01
1.07041597e+01 1.04636599e+01 1.04249980e+01 1.04760114e+01
1.05892439e+01 1.07799115e+01 1.10112143e+01 1.12439524e+01
1.14449580e+01 1.15965257e+01 1.17046440e+01 1.17851278e+01
1.18330467e+01 1.18465780e+01 1.18247766e+01 1.17900576e+01
1.17753531e+01 1.17971260e+01 1.18474868e+01 1.18984470e+01
1.19216942e+01 1.19215144e+01 1.19456129e+01 1.20899671e+01
1.23422262e+01 1.25876523e+01 1.28415592e+01 1.31346299e+01
1.34181613e+01 1.36553521e+01 1.38459036e+01 1.39994723e+01
1.41177628e+01 1.42112676e+01 1.42936831e+01 1.43763060e+01
1.44820306e+01 1.46131471e+01 1.47403297e+01 1.48166722e+01
1.47726509e+01 1.45248854e+01 1.41354885e+01 1.38783833e+01
1.38938514e+01 1.40732929e+01 1.43269416e+01 1.46326966e+01
1.48854281e+01 1.50258113e+01 1.51134155e+01 1.51832072e+01
1.52081083e+01 1.51417900e+01 1.49978307e+01 1.48069172e+01
1.46208459e+01 1.44759651e+01 1.43783726e+01 1.42824000e+01
1.41478943e+01 1.39594003e+01 1.37650232e+01 1.36235875e+01
1.35019141e+01 1.33737048e+01 1.32630639e+01 1.31698948e+01
1.31097404e+01 1.30835220e+01 1.30619136e+01 1.30354104e+01
1.30327873e+01 1.30760827e+01 1.31186129e+01 1.31592646e+01
1.33103221e+01 1.36203189e+01 1.39652697e+01 1.42978148e+01
1.45618669e+01 1.45931591e+01 1.44009353e+01 1.41683330e+01
1.38808258e+01 1.34806671e+01 1.30307157e+01 1.25539016e+01
1.20529430e+01 1.15679653e+01 1.10746083e+01 1.05909331e+01
1.01233243e+01 9.68701123e+00 9.25426189e+00 8.83027106e+00
8.41111993e+00 7.91822309e+00 7.25401089e+00 6.62374639e+00
6.36439061e+00 6.41887203e+00 6.55437207e+00 6.66980920e+00
6.74283510e+00 6.79940818e+00 6.81439257e+00 6.75913219e+00
6.64087015e+00 6.50274881e+00 6.35532972e+00 6.13516917e+00
5.85487874e+00 5.64886316e+00 5.50919583e+00 5.34616269e+00
5.28644992e+00 5.38366410e+00 5.54188288e+00 5.69095175e+00
5.83896210e+00 5.96728895e+00 6.04389566e+00 6.09100301e+00
6.12027647e+00 6.14616962e+00 6.16868197e+00 6.18948793e+00
6.20867466e+00 6.21950348e+00 6.22460848e+00 6.20473140e+00
6.14021738e+00 6.02273059e+00 5.89088829e+00 5.81960872e+00
5.81002421e+00 5.82469706e+00 5.84009532e+00 5.82139528e+00
5.78855202e+00 5.75132911e+00 5.70088947e+00 5.65497382e+00
5.61837347e+00 5.58390873e+00 5.52315140e+00 5.42831449e+00
5.33547220e+00 5.24200217e+00 5.14312740e+00 5.04563424e+00
4.94360220e+00 4.84941539e+00 4.76991724e+00 4.67534376e+00
4.57692439e+00 4.59363548e+00 4.82261907e+00 5.20874850e+00
5.59753139e+00 5.87007241e+00 6.01096513e+00 6.06755553e+00
6.09144506e+00 6.09684174e+00 6.09941669e+00 6.10025273e+00
6.09994251e+00 6.10277338e+00 6.09156446e+00 6.03699219e+00
5.93250807e+00 5.79267477e+00 5.60810759e+00 5.37309125e+00
5.10109607e+00 4.79715350e+00 4.48550188e+00 4.13397097e+00
3.74046601e+00 3.32248706e+00 2.88275730e+00 2.42096982e+00
1.95070591e+00 1.48554386e+00 1.06742936e+00 6.44038776e-01
8.89708312e-02 -5.85637924e-01 -1.28498050e+00 -1.95060989e+00
-2.61301259e+00 -3.27812996e+00 -3.96563237e+00 -4.64070424e+00
-5.29187214e+00 -5.90618384e+00 -6.51888607e+00 -7.14384054e+00
-7.78997243e+00 -8.43004189e+00 -9.09707654e+00 -9.75654292e+00
-1.04298478e+01 -1.11278206e+01 -1.18547189e+01 -1.25786555e+01
-1.32704866e+01 -1.39648038e+01 -1.46680063e+01 -1.53819056e+01
-1.60926222e+01 -1.67699824e+01 -1.74372592e+01 -1.81014131e+01
-1.87769456e+01 -1.94669798e+01 -2.01450741e+01 -2.08114847e+01
-2.14507626e+01 -2.20830945e+01 -2.26967250e+01 -2.32918310e+01
-2.38752931e+01 -2.44508186e+01]
[ -5.82752874 -6.04743522 -6.24729896 -6.42791912 -6.60625005
-6.7801578 -6.93201078 -7.06614583 -7.18164436 -7.27123292
-7.33676167 -7.38234845 -7.4073677 -7.40576369 -7.37169486
-7.30876285 -7.22939781 -7.14182494 -7.05461875 -6.95565583
-6.83121047 -6.69064931 -6.53391056 -6.35183251 -6.15289446
-5.94194536 -5.7183582 -5.45438758 -5.15510967 -4.82739235
-4.47900899 -4.10782564 -3.71201004 -3.28761817 -2.8313094
-2.34306149 -1.82064045 -1.25816212 -0.68072593 -0.05198119
0.61009054 1.30574316 2.05257412 2.85383207 3.72101676
4.6577705 5.66594356 6.78020149 7.99329529 9.24647578
10.57427674 11.90825111 13.16925827 14.35219197 15.48016488
16.56328861 17.36204445 18.09436183 18.74679215 19.30938344
19.77191958 20.17765158 20.49284695 20.72220356 20.85626248
20.86178315 20.75844728 20.56311332 20.21704941 19.65917879
18.71265328 17.6052084 16.41882026 15.20776825 14.01202532
12.89784209 11.90405482 10.92651743 9.98467599 9.09947569
8.2258109 7.3471708 6.46912399 5.6259342 4.80271783
3.99897684 3.21714687 2.46539533 1.78165687 1.09793395
0.43595862 -0.20159027 -0.82864707 -1.45435252 -2.03795725
-2.57260097 -3.04577538 -3.47886173 -3.89495344 -4.35899113
-4.8861053 -5.48196905 -6.0483259 -6.56071801 -7.04779848
-7.50602737 -7.94896237 -8.46168349 -9.06800108 -9.74183569
-10.38381854 -10.97705827 -11.53855671 -12.14122099 -12.83840135
-13.55231248 -14.24304573 -14.81569878 -15.29198221 -15.76555434
-16.25390045 -16.73738165 -17.22802733 -17.70790602 -18.1801389
-18.6243856 -19.02805842 -19.40166856 -19.74881387 -20.06977378
-20.3698467 -20.65636527 -20.9283938 -21.170415 -21.3644898
-21.50917616 -21.63033493 -21.72974098 -21.79716169 -21.85683859
-21.94110941 -22.03733196 -22.11473143 -22.16839308 -22.20407342
-22.23718053 -22.26956029 -22.2966604 -22.30425941 -22.30760709
-22.32714025 -22.33327259 -22.30184794 -22.243101 -22.18389995
-22.16188741 -22.17289988 -22.15832955 -22.08800462 -21.98087211
-21.87154283 -21.80020194 -21.74433232 -21.66116873 -21.55316578
-21.43331209 -21.33092476 -21.2639538 -21.21186312 -21.14672717
-21.05512315 -20.95378842 -20.86035817 -20.77162431 -20.68452201
-20.59816807 -20.49604747 -20.37150114 -20.23163583 -20.08450042
-19.93042857 -19.77269024 -19.60486968 -19.42842196 -19.23674711
-19.04976928 -18.9104895 -18.81791745 -18.74860813 -18.71709821
-18.70714517 -18.69067673 -18.6685729 -18.65164575 -18.66768294
-18.72303913 -18.78239619 -18.8437845 -18.90741618 -18.94929037
-18.96623086 -18.96602033 -18.93743821 -18.87100921 -18.79803432
-18.74925086 -18.71897645 -18.69440385 -18.65612692 -18.58524092
-18.50024577 -18.42003892 -18.34439316 -18.29201149 -18.24733347
-18.17621537 -18.09353565 -18.06709477 -18.1253855 -18.20442117
-18.24603861 -18.26693782 -18.27775011 -18.26390733 -18.22116379
-18.16087864 -18.0848514 -17.99575639 -17.90475712 -17.82080934
-17.72912163 -17.60621678 -17.45801273 -17.2996084 -17.13080898
-16.95820866 -16.77653898 -16.5716882 -16.33697521 -16.08841339
-15.84246817 -15.60677672 -15.37506055 -15.13232577 -14.93315295
-14.75825522 -14.53194542 -14.24575445 -13.9449112 -13.64313139
-13.31970318 -12.97121089 -12.6244589 -12.28173387 -11.9544856
-11.63725089 -11.29343831 -10.95269 -10.63133867 -10.33777907
-10.06761304 -9.8092025 -9.57631402 -9.37727242 -9.20101897
-9.02134587 -8.83541518 -8.65355254 -8.48504704 -8.31044232
-8.11607816 -7.89547063 -7.65013643 -7.39619729 -7.13172698
-6.85359609 -6.5656389 -6.28741414 -6.01655169 -5.7431534
-5.49024142 -5.28023811 -5.07232374 -4.83533624 -4.59234855
-4.36753482 -4.13899836 -3.87393153 -3.57680141 -3.28983185
-2.99988348 -2.71847072 -2.46352163 -2.24718766 -2.04951555
-1.79765125 -1.47527523 -1.23624041 -1.10955571 -0.99759757
-0.87873913 -0.75183995 -0.61570056 -0.46891481 -0.29994018
-0.11806709 0.06630626 0.25531677 0.41613186 0.4801292
0.47139273 0.48678675 0.54133997 0.59715912 0.63922735
0.66068336 0.67758472 0.71717227 0.77721446 0.84366744
0.92334167 1.04885516 1.24677748 1.48696342 1.71030709
1.89873025 2.08929498 2.31250698 2.57610681 2.84630726
3.10328492 3.35986633 3.62512395 3.89998503 4.16091616
4.42103368 4.69655318 4.99906269 5.30393091 5.57836791
5.82998318 6.05698891 6.21747461 6.34158014 6.4893212
6.6924853 6.95290473 7.21458473 7.44321223 7.67133309
7.92063224 8.16833332 8.375379 8.53028829 8.65276144
8.74414206 8.80055168 8.84240403 8.92517894 9.05384228
9.19681514 9.33993923 9.49615143 9.69253491 9.92666338
10.18527832 10.46370654 10.77089621 11.10115766 11.45532233
11.86455522 12.33333772 12.84506256 13.31599552 13.71237131
14.07554154 14.4622736 14.88618037 15.32204403 15.75729819
16.20346481 16.65517356 17.07303369 17.44292511 17.83186737
18.22716565 18.63556561 19.07649009 19.55086634 20.03971111
20.54636506 21.0874425 21.66496648 22.25621954 22.89173581
23.58803899 24.22003272 24.78137829 25.32227742 25.86584336
26.42601713 27.01902667 27.66148627 28.35733994 29.09303458
29.86829073 30.69730932 31.54277416 32.45574903 33.39691073
34.38106352 35.40303253 36.44693081 37.491008 38.46419913
39.28818515 39.95315474 40.62422426 41.30583305 41.86764367
42.31777468 42.73415213 43.15563248 43.59030645 44.06908465
44.60506443 45.21636847 45.88642694 46.48873428 46.95499852
47.3087965 47.54075702 47.63561331 47.66276372 47.67843619
47.70330489 47.73112832 47.7615154 47.80384028 47.86064426
47.93320939 48.03913232 48.20057223 48.3812956 48.52087035
48.56264127 48.62456393 48.88596414 49.30523309 49.68024563
49.87244175 49.88354464 49.83416762 49.79005063 49.74077059
49.71189448 49.72396058 49.76762739 49.83090916 49.9134074
50.00427186 50.09759278 50.20257106 50.32736275 50.46814413
50.60208489 50.5517257 50.17054807 49.61975565 49.0779435
48.53386726 47.98210535 47.4098391 46.84432554 46.31842379
45.81514676 45.34395948 44.93129119 44.57272094 44.25365117
43.96728793 43.71654492 43.46797566 43.21798549 43.00061065
42.81205204 42.57612653 42.32137936 42.05786986 41.73274022
41.36203405 40.93953581 40.5030252 40.09355213 39.73104934
39.40045534 39.09527289 38.80581395 38.50845783 38.19280777
37.86422147 37.54492447 37.20662196 36.90540753 36.63745601
36.40577759 36.15526958 35.78571604 35.358742 34.8295069
34.12009435 33.27119674 32.38339075 31.53673972 30.72564002
29.9198869 29.10453867 28.32009336 27.57021808 26.86441513
26.14171911 25.40740513 24.62617337 23.7447545 22.89981792
22.11192252 21.20986659 20.13541738 19.03068843 18.03628934
17.04231522 16.09308301 15.20044911 14.33901569 13.4777773
12.60710259 11.73428199 10.87485322 10.06544163 9.31158563
8.59924134 7.91809259 7.27533575 6.67055983 6.05144094
5.45352018 4.90176237 4.38621803 3.89380551 3.44268403
3.06451919 2.73120462 2.33921953 1.82659933 1.27979878
0.68161738 -0.07006056 -1.04051871 -2.1447807 -3.26847134
-4.33841259 -5.35788315 -6.41496836 -7.45461051 -8.44473378
-9.39125273 -10.2968004 -11.18277652 -12.02160646 -12.84062785
-13.64413719 -14.43041176 -15.15742338 -15.82301318 -16.43159708
-17.0772732 -17.72864975 -18.31551589 -18.83916363 -19.31703773
-19.81953902 -20.40291437 -21.02645165 -21.62976458 -22.19113741
-22.70880896 -23.1824579 -23.62505202 -24.04549163 -24.47467575
-24.84436573 -25.13046191 -25.36551983 -25.58124059 -25.79363902
-25.98889476 -26.16999798 -26.34353485 -26.5061773 -26.69272562
-26.92739962 -27.17879121 -27.42690494 -27.68138822 -27.94739392
-28.2252015 -28.51780545 -28.80497137 -29.05244669 -29.26563489
-29.4635964 -29.64316517 -29.79811341 -29.90570504 -29.96754859
-30.00138527 -30.02765147 -30.09206136 -30.29257554 -30.63128351
-30.98749335 -31.27068058 -31.43587853 -31.58369921 -31.77529721
-31.94838669 -32.07009629 -32.12514993 -32.14994726 -32.17454928
-32.21039738 -32.24363484 -32.25442453 -32.23909624 -32.17962145
-32.06376325 -31.90445806 -31.68783447 -31.43231893 -31.19556308
-30.99756016 -30.8081638 -30.58431614 -30.30024154 -29.94525819
-29.56679807 -29.19775942 -28.82159839 -28.4287477 -28.01352914
-27.56394964 -27.06223513 -26.5328694 -26.00699823 -25.52653211
-25.1324765 -24.91705962 -24.96710888 -25.21994094 -25.46297201
-25.56996729 -25.56817939 -25.51387624 -25.39527032 -25.23074152
-25.04862499 -24.82238518 -24.53967348 -24.18758407 -23.81703035
-23.4468737 -23.06774447 -22.64764298 -22.1951531 -21.73330752
-21.22325842 -20.65261468 -20.13063966 -19.75265273 -19.46834405
-19.20523551 -18.90357523 -18.56705552 -18.21646968 -17.85662224
-17.46939054 -17.03755691 -16.56201941 -16.05687781 -15.5290898
-15.02782 -14.56297886 -14.21481994 -13.93846118 -13.74054311
-13.5866495 -13.36028199 -13.01206912 -12.5536147 -12.0103756
-11.44390272 -10.87251652 -10.31498317 -9.73307852 -9.14177692
-8.59671342 -8.05991548 -7.4863042 -6.89041721 -6.3166903
-5.78169333 -5.29134726 -4.85540995 -4.51123851 -4.24333681
-4.05105649 -3.89314359 -3.73609573 -3.55908039 -3.36054752
-3.12371566 -2.79110192 -2.33096107 -1.7506189 -1.0889516
-0.3767371 0.37864504 1.19130591 2.04470237 2.8836246
3.6522338 4.42502387 5.14250161 5.66609687 5.90080449
5.91640943 5.75637234 5.41430698 5.02667179 4.69720752
4.41274485 4.18824945 4.05304182 3.9515199 3.76497763
3.45297204 3.01085458 2.4595578 1.89572893 1.37578101
0.9222021 0.53035079 0.18618321 -0.16486978 -0.52779904
-0.9132655 -1.25649558 -1.50919917 -1.68627713 -1.84113933
-2.04508349 -2.36505907 -2.81243286 -3.28168306 -3.67225568
-4.09506362 -4.64814741 -5.27474113 -5.99362324 -6.80570532
-7.68295999 -8.51958415 -9.29118607 -9.96219883 -10.49511683
-10.87925986 -11.21558565 -11.5531984 -11.86208204 -12.08779362
-12.23235577 -12.28210381 -12.28421066 -12.23601452 -12.02096765
-11.59268002 -11.03323625 -10.38351721 -9.64795233 -8.85806054
-7.9410321 -6.86435535 -5.69733419 -4.53926475 -3.46167671
-2.39882682 -1.30685299 -0.09857721 1.2492944 2.70663918
4.18279881 5.64663953]
#print(motion_df)
saved_copy_motion_df = motion_df.copy(deep=True) #make a copy of the dataframe with raw data
dropped_motion_df = motion_df.dropna(subset=['Latitude', 'Longitude'])
#print(saved_copy_motion_df)
#Create arrays with just the longitude and the latitude
lat_array = np.array(dropped_motion_df.loc[:,"Latitude"], dtype=float)
lon_array = np.array(dropped_motion_df.loc[:,"Longitude"], dtype=float)
#confirm that these two arrays are the same length
print(len(lat_array))
print(len(lon_array))
#Account for how data is represented divide lat by 10^5 and lon by 10^4
lat_array[:] = [x / 10.0**5 for x in lat_array]
lon_array[:] = [x / 10.0**5 for x in lon_array]
print(lat_array[0])
print(lon_array[0])
357
357
32.85846
-117.25781
# Place map
gmap = gmplot.GoogleMapPlotter(lat_array[0], lon_array[0], 13)
gmap.scatter(lat_array, lon_array, '#3B0B39', size=5, marker=False)
gmap.plot(lat_array, lon_array, 'cornflowerblue', edge_width = 3.0)
# Draw
gmap.draw("dead-reckoning-IA.html")
By Howard Wang
"The method I came up with to calculate and determine the direction of waves in the general surf region can be described simply as a physical analysis of the overall movement of the Smartfin, currently using buoy calibrated data for controlled behaviour. Basically, the movement of the Smartfin emulates the movement of the waves." - Howard Wang
# Howard Wang 05/14/19
# CSE 145: Embedded systems and design
# Main Database: https://surf.smartfin.org/
# Analyzing data from Buoy Calibration experiment to get wave direction.
# First, parse the data from the .CSV file containing ocean and wave motion data.
# This data comes from a controlled experiment (CE3), so we are assuming that
# all of the vertical accelerations are contained in IMUA2.
# MATPLOTLIB
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
#from mpl_toolkits.basemap import Basemap
# DATAFRAMES
import pandas as pd
import numpy as np
# SCIPY
from scipy import stats
from scipy import constants
from scipy import signal #added
from scipy.interpolate import CubicSpline
from scipy.interpolate import interp1d
from scipy.integrate import simps
from scipy.integrate import cumtrapz
import pylab as pylab
# SYSTEM and CONVERSION TOOLS
import math
import abc
import sys
import csv
import io
import os
import datetime
import pytz
import re
# MODELING AND GRAPHS
import peakutils
import statsmodels.api as sm
# URL REQUESTS
import requests
# VECTORS AND GRAPHICS
import mpld3
import folium
# import cmocean
import skinematics as skin
from skinematics import quat, vector, misc, rotmat, imus, view
import pygame
# PLOTTING TOOLS
from plotly import tools
import plotly.offline
import plotly.graph_objs as go
%matplotlib notebook
%matplotlib inline
print("Done!")
Done!
ride_ids = ['14888']
# 14743 - Motion Control July 10th
# 14750 - Magnetometer Control July 11th
# 14814 - Pool Displacement Control July 17th
# 14815 - Compass Orientation (Lying on Charger Side) July 19th
# 14816 - Orientation w Higher Sampling (Lying on Charger Side) July 20th
# 14827 - Pool Displacement Control w Higher Sampling (Jul 23)
# 14888 - First Buoy Calibration Experiment (July 30)
print("Done!")
Done!
#%% Fin ID scraper
# Input fin ID, get all ride IDs
# base URL to which we'll append given fin IDs
fin_url_base = 'http://surf.smartfin.org/fin/'
# Look for the following text in the HTML contents in fcn below
str_id_ride = 'rideId = \'' # backslash allows us to look for single quote
str_id_date = 'var date = \'' # backslash allows us to look for single quote
#%% Ride ID scraper
# Input ride ID, get ocean and motion CSVs
# Base URL to which we'll append given ride IDs
ride_url_base = 'https://surf.smartfin.org/ride/'
# Look for the following text in the HTML contents in fcn below
str_id_csv = 'img id="temperatureChart" class="chart" src="'
def get_csv_from_ride_id(rid):
# Build URL for each individual ride
ride_url = ride_url_base+str(rid)
print(ride_url)
# Get contents of ride_url
html_contents = requests.get(ride_url).text
# Find CSV identifier
loc_csv_id = html_contents.find(str_id_csv)
# Different based on whether user logged in with FB or Google
offset_googleOAuth = [46, 114]
offset_facebkOAuth = [46, 112]
if html_contents[loc_csv_id+59] == 'f': # Facebook login
off0 = offset_facebkOAuth[0]
off1 = offset_facebkOAuth[1]
else: # Google login
off0 = offset_googleOAuth[0]
off1 = offset_googleOAuth[1]
csv_id_longstr = html_contents[loc_csv_id+off0:loc_csv_id+off1]
# Stitch together full URL for CSV
if ("media" in csv_id_longstr) & ("Calibration" not in html_contents): # other junk URLs can exist and break everything
ocean_csv_url = 'https://surf.smartfin.org/'+csv_id_longstr+'Ocean.CSV'
motion_csv_url = 'https://surf.smartfin.org/'+csv_id_longstr+'Motion.CSV'
print(ocean_csv_url)
# Go to ocean_csv_url and grab contents (theoretically, a CSV)
oceanCSV = requests.get(ocean_csv_url).content
ocean_df_small = pd.read_csv(io.StringIO(oceanCSV.decode('utf-8')))
# Grab CSV from motion url
motionCSV = requests.get(motion_csv_url).content
motion_df_small = pd.read_csv(io.StringIO(motionCSV.decode('utf-8')))
return ocean_df_small, motion_df_small
else:
ocean_df_small_resample = pd.DataFrame() # empty DF just so something is returned
motion_df_small_resample = pd.DataFrame()
return ocean_df_small_resample, motion_df_small_resample
print("Done!")
Done!
appended_ocean_list = [] # list of DataFrames from original CSVs
appended_motion_list = []
appended_multiIndex = [] # fin_id & ride_id used to identify each DataFrame
## Nested loops (for each fin ID, find all ride IDs, then build a DataFrame from all ride CSVs)
## (Here, ride IDS are either ocean or motion dataframes)
count_good_fins = 0
# Loop over ride_ids and find CSVs
for rid in ride_ids:
try:
new_ocean_df, new_motion_df = get_csv_from_ride_id(rid) # get given ride's CSV from its ride ID using function above
#print(len(new_ocean_df))
#print(len(new_motion_df))
if not new_ocean_df.empty: # Calibration rides, for example
# Append only if DF isn't empty. There may be a better way to control empty DFs which are created above
appended_multiIndex.append(str(rid)) # build list to be multiIndex of future DataFrame
appended_ocean_list.append(new_ocean_df)
appended_motion_list.append(new_motion_df)
print("Ride data has been uploaded.")
#print("Ride: ", rid, "data has been uploaded.")
count_good_fins += 1
except:
print("Ride threw an exception!")
#print("Ride ", rid, "threw an exception!")
#%% Build the "Master" DataFrame
# appended_ocean_df.summary()
df_keys = tuple(appended_multiIndex) # keys gotta be a tuple, a list which data in it cannot be changed
ocean_df = pd.concat(appended_ocean_list, keys = df_keys, names=['ride_id'])
motion_df = pd.concat(appended_motion_list, keys = df_keys, names = ['ride_id'])
# Print motion and Ocean dataframes
print(motion_df)
print(ocean_df)
https://surf.smartfin.org/ride/14888
https://surf.smartfin.org/media/201807/google_117589279598321562176_000666D321BE_180730171718_Ocean.CSV
Ride data has been uploaded.
UTC Time IMU A1 IMU A2 \
ride_id
14888 0 2018-07-30T17:17:24.3320+00:00 2067196596 -34.0 -520.0
1 2018-07-30T17:17:24.3650+00:00 2067196629 -30.0 -517.0
2 2018-07-30T17:17:24.3990+00:00 2067196662 -28.0 -517.0
3 2018-07-30T17:17:24.4320+00:00 2067196695 -28.0 -518.0
4 2018-07-30T17:17:24.4650+00:00 2067196728 -30.0 -517.0
5 2018-07-30T17:17:24.4980+00:00 2067196761 -31.0 -518.0
6 2018-07-30T17:17:24.5310+00:00 2067196794 -33.0 -520.0
7 2018-07-30T17:17:24.5650+00:00 2067196828 -30.0 -519.0
8 2018-07-30T17:17:24.5970+00:00 2067196860 -30.0 -517.0
9 2018-07-30T17:17:24.6310+00:00 2067196894 -29.0 -517.0
10 2018-07-30T17:17:24.6630+00:00 2067196926 -30.0 -518.0
11 2018-07-30T17:17:24.6960+00:00 2067196959 -32.0 -520.0
12 2018-07-30T17:17:24.7300+00:00 2067196992 -32.0 -518.0
13 2018-07-30T17:17:24.7630+00:00 2067197025 -30.0 -517.0
14 2018-07-30T17:17:24.7960+00:00 2067197058 -28.0 -516.0
15 2018-07-30T17:17:24.8290+00:00 2067197091 -27.0 -516.0
16 2018-07-30T17:17:24.8620+00:00 2067197124 -31.0 -518.0
17 2018-07-30T17:17:24.8950+00:00 2067197157 -34.0 -518.0
18 2018-07-30T17:17:24.9290+00:00 2067197191 -33.0 -519.0
19 2018-07-30T17:17:24.9610+00:00 2067197223 -30.0 -517.0
20 2018-07-30T17:17:24.9950+00:00 2067197257 -27.0 -516.0
21 2018-07-30T17:17:25.0280+00:00 2067197290 -28.0 -516.0
22 2018-07-30T17:17:25.0620+00:00 2067197323 7.0 -516.0
23 2018-07-30T17:17:25.0950+00:00 2067197356 -50.0 -518.0
24 2018-07-30T17:17:25.1280+00:00 2067197389 -38.0 -517.0
25 2018-07-30T17:17:25.1610+00:00 2067197422 -39.0 -516.0
26 2018-07-30T17:17:25.1940+00:00 2067197455 -29.0 -517.0
27 2018-07-30T17:17:25.2280+00:00 2067197489 -29.0 -517.0
28 2018-07-30T17:17:25.2600+00:00 2067197521 -29.0 -517.0
29 2018-07-30T17:17:25.2930+00:00 2067197554 -30.0 -517.0
... ... ... ... ...
7559 2018-07-30T17:30:50.4950+00:00 2068000375 -58.0 -553.0
7560 2018-07-30T17:30:50.6940+00:00 2068000574 -65.0 -549.0
7561 2018-07-30T17:30:50.8930+00:00 2068000772 -73.0 -539.0
7562 2018-07-30T17:30:51.0920+00:00 2068000971 -73.0 -530.0
7563 2018-07-30T17:30:51.2910+00:00 2068001169 -76.0 -522.0
7564 2018-07-30T17:30:51.4910+00:00 2068001368 -78.0 -510.0
7565 2018-07-30T17:30:51.6900+00:00 2068001567 -73.0 -497.0
7566 2018-07-30T17:30:51.8890+00:00 2068001765 -73.0 -494.0
7567 2018-07-30T17:30:52.0980+00:00 2068001974 -64.0 -480.0
7568 2018-07-30T17:30:52.2970+00:00 2068002172 -57.0 -480.0
7569 2018-07-30T17:30:52.4960+00:00 2068002371 -50.0 -477.0
7570 2018-07-30T17:30:52.6960+00:00 2068002570 -40.0 -472.0
7571 2018-07-30T17:30:52.8950+00:00 2068002768 -32.0 -469.0
7572 2018-07-30T17:30:53.0930+00:00 2068002966 -20.0 -469.0
7573 2018-07-30T17:30:53.3030+00:00 2068003175 -14.0 -472.0
7574 2018-07-30T17:30:53.5020+00:00 2068003374 -4.0 -475.0
7575 2018-07-30T17:30:53.7020+00:00 2068003573 3.0 -480.0
7576 2018-07-30T17:30:53.9010+00:00 2068003771 8.0 -491.0
7577 2018-07-30T17:30:54.1000+00:00 2068003970 12.0 -498.0
7578 2018-07-30T17:30:54.3000+00:00 2068004169 14.0 -509.0
7579 2018-07-30T17:30:54.4980+00:00 2068004367 17.0 -514.0
7580 2018-07-30T17:30:54.6980+00:00 2068004566 16.0 -523.0
7581 2018-07-30T17:30:54.9080+00:00 2068004775 14.0 -530.0
7582 2018-07-30T17:30:54.9970+00:00 2068004864 NaN NaN
7583 2018-07-30T17:31:00.4840+00:00 2068010335 NaN NaN
7584 2018-07-30T17:31:05.5020+00:00 2068015338 NaN NaN
7585 2018-07-30T17:31:10.9830+00:00 2068020803 NaN NaN
7586 2018-07-30T17:31:16.0010+00:00 2068025806 NaN NaN
7587 2018-07-30T17:31:21.4850+00:00 2068031274 NaN NaN
7588 2018-07-30T17:31:26.5000+00:00 2068036274 NaN NaN
IMU A3 IMU G1 IMU G2 IMU G3 IMU M1 IMU M2 IMU M3 \
ride_id
14888 0 -48.0 82.0 -19.0 12.0 208.0 394.0 438.0
1 -57.0 32.0 -14.0 9.0 220.0 400.0 438.0
2 -59.0 -7.0 -11.0 6.0 218.0 398.0 430.0
3 -62.0 -27.0 -9.0 5.0 210.0 400.0 428.0
4 -62.0 64.0 -13.0 9.0 212.0 394.0 426.0
5 -54.0 157.0 -24.0 17.0 215.0 399.0 433.0
6 -41.0 29.0 -14.0 9.0 220.0 400.0 432.0
7 -46.0 -101.0 -3.0 2.0 216.0 406.0 432.0
8 -55.0 -121.0 -1.0 1.0 213.0 401.0 429.0
9 -63.0 -26.0 -8.0 6.0 218.0 396.0 428.0
10 -57.0 -7.0 -11.0 5.0 209.0 407.0 427.0
11 -54.0 -3.0 -11.0 6.0 212.0 398.0 440.0
12 -57.0 -22.0 -8.0 7.0 220.0 400.0 432.0
13 -60.0 -27.0 -9.0 6.0 208.0 400.0 434.0
14 -58.0 11.0 -12.0 9.0 216.0 396.0 430.0
15 -58.0 -4.0 -10.0 6.0 213.0 403.0 437.0
16 -55.0 -32.0 -8.0 4.0 211.0 405.0 441.0
17 -62.0 -71.0 -7.0 3.0 209.0 403.0 437.0
18 -62.0 -32.0 -9.0 5.0 203.0 395.0 433.0
19 -66.0 -68.0 14.0 5.0 213.0 395.0 441.0
20 -66.0 -97.0 25.0 3.0 218.0 392.0 436.0
21 -68.0 -60.0 10.0 6.0 216.0 392.0 440.0
22 -71.0 -24.0 4.0 5.0 217.0 397.0 441.0
23 -73.0 -47.0 13.0 5.0 217.0 399.0 445.0
24 -72.0 -43.0 6.0 8.0 210.0 396.0 442.0
25 -74.0 -29.0 -1.0 7.0 219.0 389.0 441.0
26 -73.0 -7.0 -11.0 6.0 214.0 396.0 448.0
27 -75.0 -53.0 9.0 6.0 210.0 402.0 440.0
28 -77.0 -40.0 6.0 7.0 208.0 392.0 442.0
29 -76.0 -11.0 -9.0 5.0 224.0 386.0 440.0
... ... ... ... ... ... ... ...
7559 -65.0 -9.0 -10.0 5.0 199.0 405.0 439.0
7560 -66.0 -7.0 -10.0 5.0 199.0 409.0 459.0
7561 -65.0 -8.0 -10.0 4.0 201.0 395.0 469.0
7562 -63.0 -9.0 -9.0 3.0 205.0 387.0 467.0
7563 -61.0 -8.0 -9.0 4.0 197.0 381.0 465.0
7564 -63.0 -8.0 -9.0 4.0 209.0 377.0 457.0
7565 -65.0 -9.0 -10.0 5.0 201.0 383.0 445.0
7566 -62.0 -8.0 -9.0 5.0 211.0 377.0 441.0
7567 -60.0 -7.0 -9.0 5.0 208.0 384.0 438.0
7568 -57.0 -6.0 -9.0 6.0 204.0 374.0 434.0
7569 -62.0 -7.0 -10.0 5.0 207.0 385.0 435.0
7570 -56.0 -6.0 -10.0 6.0 210.0 396.0 432.0
7571 -56.0 -6.0 -11.0 4.0 203.0 397.0 429.0
7572 -56.0 -7.0 -11.0 5.0 196.0 396.0 438.0
7573 -56.0 -6.0 -11.0 8.0 205.0 389.0 433.0
7574 -58.0 -7.0 -12.0 5.0 211.0 397.0 429.0
7575 -57.0 -6.0 -12.0 4.0 201.0 395.0 429.0
7576 -58.0 -6.0 -12.0 4.0 210.0 392.0 432.0
7577 -57.0 -6.0 -12.0 5.0 216.0 402.0 426.0
7578 -55.0 -6.0 -13.0 7.0 208.0 394.0 424.0
7579 -59.0 -7.0 -12.0 7.0 207.0 389.0 433.0
7580 -56.0 -8.0 -11.0 6.0 213.0 395.0 429.0
7581 -60.0 -8.0 -13.0 5.0 212.0 400.0 424.0
7582 NaN NaN NaN NaN NaN NaN NaN
7583 NaN NaN NaN NaN NaN NaN NaN
7584 NaN NaN NaN NaN NaN NaN NaN
7585 NaN NaN NaN NaN NaN NaN NaN
7586 NaN NaN NaN NaN NaN NaN NaN
7587 NaN NaN NaN NaN NaN NaN NaN
7588 NaN NaN NaN NaN NaN NaN NaN
Latitude Longitude
ride_id
14888 0 NaN NaN
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 NaN NaN
5 NaN NaN
6 NaN NaN
7 NaN NaN
8 NaN NaN
9 NaN NaN
10 NaN NaN
11 NaN NaN
12 NaN NaN
13 NaN NaN
14 NaN NaN
15 NaN NaN
16 NaN NaN
17 NaN NaN
18 NaN NaN
19 NaN NaN
20 NaN NaN
21 NaN NaN
22 NaN NaN
23 NaN NaN
24 NaN NaN
25 NaN NaN
26 NaN NaN
27 NaN NaN
28 NaN NaN
29 NaN NaN
... ... ...
7559 NaN NaN
7560 NaN NaN
7561 NaN NaN
7562 NaN NaN
7563 NaN NaN
7564 NaN NaN
7565 NaN NaN
7566 NaN NaN
7567 NaN NaN
7568 NaN NaN
7569 NaN NaN
7570 NaN NaN
7571 NaN NaN
7572 NaN NaN
7573 NaN NaN
7574 NaN NaN
7575 NaN NaN
7576 NaN NaN
7577 NaN NaN
7578 NaN NaN
7579 NaN NaN
7580 NaN NaN
7581 NaN NaN
7582 3286943.0 -11725208.0
7583 3286942.0 -11725208.0
7584 3286941.0 -11725207.0
7585 3286941.0 -11725206.0
7586 3286941.0 -11725206.0
7587 3286942.0 -11725206.0
7588 3286943.0 -11725207.0
[7589 rows x 13 columns]
UTC Time Temperature 1 \
ride_id
14888 0 2018-07-30T17:17:23.8620+00:00 2067196127 463
1 2018-07-30T17:17:29.9020+00:00 2067202149 464
2 2018-07-30T17:17:35.9400+00:00 2067208169 464
3 2018-07-30T17:17:41.9790+00:00 2067214190 464
4 2018-07-30T17:17:48.0180+00:00 2067220212 464
5 2018-07-30T17:17:54.0550+00:00 2067226231 464
6 2018-07-30T17:18:00.0930+00:00 2067232251 464
7 2018-07-30T17:18:06.1310+00:00 2067238271 464
8 2018-07-30T17:18:12.1690+00:00 2067244291 464
9 2018-07-30T17:18:18.2070+00:00 2067250311 464
10 2018-07-30T17:18:24.2440+00:00 2067256331 465
11 2018-07-30T17:18:30.2830+00:00 2067262352 465
12 2018-07-30T17:18:36.3230+00:00 2067268374 465
13 2018-07-30T17:18:42.3610+00:00 2067274394 465
14 2018-07-30T17:18:48.3980+00:00 2067280413 465
15 2018-07-30T17:18:54.4350+00:00 2067286432 466
16 2018-07-30T17:19:00.4730+00:00 2067292452 466
17 2018-07-30T17:19:06.5100+00:00 2067298472 466
18 2018-07-30T17:19:12.5480+00:00 2067304492 465
19 2018-07-30T17:19:18.5890+00:00 2067310515 465
20 2018-07-30T17:19:24.6280+00:00 2067316536 466
21 2018-07-30T17:19:30.6670+00:00 2067322557 466
22 2018-07-30T17:19:36.7050+00:00 2067328577 466
23 2018-07-30T17:19:42.7430+00:00 2067334597 467
24 2018-07-30T17:19:48.7800+00:00 2067340617 467
25 2018-07-30T17:19:54.8210+00:00 2067346640 467
26 2018-07-30T17:20:00.8600+00:00 2067352661 468
27 2018-07-30T17:20:06.8980+00:00 2067358681 468
28 2018-07-30T17:20:12.9350+00:00 2067364700 468
29 2018-07-30T17:20:18.9740+00:00 2067370721 468
... ... ... ...
110 2018-07-30T17:28:28.0700+00:00 2067858371 465
111 2018-07-30T17:28:34.1090+00:00 2067864393 465
112 2018-07-30T17:28:40.1460+00:00 2067870412 465
113 2018-07-30T17:28:46.1850+00:00 2067876433 464
114 2018-07-30T17:28:52.2230+00:00 2067882453 464
115 2018-07-30T17:28:58.2610+00:00 2067888473 464
116 2018-07-30T17:29:04.3000+00:00 2067894494 464
117 2018-07-30T17:29:10.3380+00:00 2067900515 465
118 2018-07-30T17:29:16.3760+00:00 2067906535 464
119 2018-07-30T17:29:22.4140+00:00 2067912555 465
120 2018-07-30T17:29:28.4510+00:00 2067918574 464
121 2018-07-30T17:29:34.4900+00:00 2067924595 464
122 2018-07-30T17:29:40.5290+00:00 2067930616 465
123 2018-07-30T17:29:46.5680+00:00 2067936637 464
124 2018-07-30T17:29:52.6040+00:00 2067942656 464
125 2018-07-30T17:29:58.6410+00:00 2067948675 464
126 2018-07-30T17:30:04.6800+00:00 2067954696 464
127 2018-07-30T17:30:10.7180+00:00 2067960716 464
128 2018-07-30T17:30:16.7560+00:00 2067966736 464
129 2018-07-30T17:30:22.7940+00:00 2067972756 464
130 2018-07-30T17:30:28.8350+00:00 2067978779 464
131 2018-07-30T17:30:34.8720+00:00 2067984799 464
132 2018-07-30T17:30:40.9120+00:00 2067990821 465
133 2018-07-30T17:30:46.9500+00:00 2067996841 465
134 2018-07-30T17:30:52.9890+00:00 2068002862 465
135 2018-07-30T17:30:59.0290+00:00 2068008884 465
136 2018-07-30T17:31:05.0680+00:00 2068014905 465
137 2018-07-30T17:31:11.1050+00:00 2068020925 465
138 2018-07-30T17:31:17.1430+00:00 2068026945 465
139 2018-07-30T17:31:23.1810+00:00 2068032965 465
Calibrated Temperature 1 Temperature 1 Stable Temperature 2 \
ride_id
14888 0 28.938 False 7189
1 29.000 False 7307
2 29.000 False 7284
3 29.000 False 7276
4 29.000 False 7268
5 29.000 False 7265
6 29.000 False 7256
7 29.000 False 7256
8 29.000 False 7253
9 29.000 False 7251
10 29.062 False 7249
11 29.062 False 7287
12 29.062 False 7339
13 29.062 False 7359
14 29.062 False 7358
15 29.125 False 7347
16 29.125 False 7330
17 29.125 False 7303
18 29.062 False 7295
19 29.062 False 7286
20 29.125 False 7291
21 29.125 False 7288
22 29.125 False 7355
23 29.188 False 7414
24 29.188 False 7414
25 29.188 False 7416
26 29.250 False 7416
27 29.250 False 7437
28 29.250 False 7501
29 29.250 False 7489
... ... ... ...
110 29.062 False 7095
111 29.062 False 7087
112 29.062 False 7082
113 29.000 False 7080
114 29.000 False 7079
115 29.000 False 7066
116 29.000 False 7069
117 29.062 False 7075
118 29.000 False 7073
119 29.062 False 7065
120 29.000 False 7065
121 29.000 False 7067
122 29.062 False 7062
123 29.000 False 7054
124 29.000 False 7059
125 29.000 False 7062
126 29.000 False 7065
127 29.000 False 7073
128 29.000 False 7075
129 29.000 False 7078
130 29.000 False 7082
131 29.000 False 7094
132 29.062 False 7093
133 29.062 False 7099
134 29.062 False 7103
135 29.062 False 7108
136 29.062 False 7102
137 29.062 False 7100
138 29.062 False 7096
139 29.062 False 7099
Calibrated Temperature 2 Temperature 2 Stable salinity \
ride_id
14888 0 28.271 False NaN
1 28.733 False NaN
2 28.643 False NaN
3 28.612 False NaN
4 28.580 False NaN
5 28.569 False NaN
6 28.533 False NaN
7 28.533 False NaN
8 28.522 False NaN
9 28.514 False NaN
10 28.506 False NaN
11 28.655 False NaN
12 28.859 False NaN
13 28.937 False NaN
14 28.933 False NaN
15 28.890 False NaN
16 28.824 False NaN
17 28.718 False NaN
18 28.686 False NaN
19 28.651 False NaN
20 28.671 False NaN
21 28.659 False NaN
22 28.922 False NaN
23 29.153 False NaN
24 29.153 False NaN
25 29.161 False NaN
26 29.161 False NaN
27 29.243 False NaN
28 29.494 False NaN
29 29.447 False NaN
... ... ... ...
110 27.902 False NaN
111 27.871 False NaN
112 27.851 False NaN
113 27.843 False NaN
114 27.839 False NaN
115 27.788 False NaN
116 27.800 False NaN
117 27.824 False NaN
118 27.816 False NaN
119 27.784 False NaN
120 27.784 False NaN
121 27.792 False NaN
122 27.773 False NaN
123 27.741 False NaN
124 27.761 False NaN
125 27.773 False NaN
126 27.784 False NaN
127 27.816 False NaN
128 27.824 False NaN
129 27.835 False NaN
130 27.851 False NaN
131 27.898 False NaN
132 27.894 False NaN
133 27.918 False NaN
134 27.933 False NaN
135 27.953 False NaN
136 27.930 False NaN
137 27.922 False NaN
138 27.906 False NaN
139 27.918 False NaN
Calibrated Salinity Salinity Stable pH Calibrated pH \
ride_id
14888 0 NaN NaN NaN NaN
1 NaN NaN NaN NaN
2 NaN NaN NaN NaN
3 NaN NaN NaN NaN
4 NaN NaN NaN NaN
5 NaN NaN NaN NaN
6 NaN NaN NaN NaN
7 NaN NaN NaN NaN
8 NaN NaN NaN NaN
9 NaN NaN NaN NaN
10 NaN NaN NaN NaN
11 NaN NaN NaN NaN
12 NaN NaN NaN NaN
13 NaN NaN NaN NaN
14 NaN NaN NaN NaN
15 NaN NaN NaN NaN
16 NaN NaN NaN NaN
17 NaN NaN NaN NaN
18 NaN NaN NaN NaN
19 NaN NaN NaN NaN
20 NaN NaN NaN NaN
21 NaN NaN NaN NaN
22 NaN NaN NaN NaN
23 NaN NaN NaN NaN
24 NaN NaN NaN NaN
25 NaN NaN NaN NaN
26 NaN NaN NaN NaN
27 NaN NaN NaN NaN
28 NaN NaN NaN NaN
29 NaN NaN NaN NaN
... ... ... .. ...
110 NaN NaN NaN NaN
111 NaN NaN NaN NaN
112 NaN NaN NaN NaN
113 NaN NaN NaN NaN
114 NaN NaN NaN NaN
115 NaN NaN NaN NaN
116 NaN NaN NaN NaN
117 NaN NaN NaN NaN
118 NaN NaN NaN NaN
119 NaN NaN NaN NaN
120 NaN NaN NaN NaN
121 NaN NaN NaN NaN
122 NaN NaN NaN NaN
123 NaN NaN NaN NaN
124 NaN NaN NaN NaN
125 NaN NaN NaN NaN
126 NaN NaN NaN NaN
127 NaN NaN NaN NaN
128 NaN NaN NaN NaN
129 NaN NaN NaN NaN
130 NaN NaN NaN NaN
131 NaN NaN NaN NaN
132 NaN NaN NaN NaN
133 NaN NaN NaN NaN
134 NaN NaN NaN NaN
135 NaN NaN NaN NaN
136 NaN NaN NaN NaN
137 NaN NaN NaN NaN
138 NaN NaN NaN NaN
139 NaN NaN NaN NaN
pH Stable
ride_id
14888 0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 NaN
6 NaN
7 NaN
8 NaN
9 NaN
10 NaN
11 NaN
12 NaN
13 NaN
14 NaN
15 NaN
16 NaN
17 NaN
18 NaN
19 NaN
20 NaN
21 NaN
22 NaN
23 NaN
24 NaN
25 NaN
26 NaN
27 NaN
28 NaN
29 NaN
... ...
110 NaN
111 NaN
112 NaN
113 NaN
114 NaN
115 NaN
116 NaN
117 NaN
118 NaN
119 NaN
120 NaN
121 NaN
122 NaN
123 NaN
124 NaN
125 NaN
126 NaN
127 NaN
128 NaN
129 NaN
130 NaN
131 NaN
132 NaN
133 NaN
134 NaN
135 NaN
136 NaN
137 NaN
138 NaN
139 NaN
[140 rows x 14 columns]
#print(motion_df)
saved_copy_motion_df = motion_df.copy(deep=True) #make a copy of the dataframe with raw data
print(saved_copy_motion_df)
UTC Time IMU A1 IMU A2 \
ride_id
14888 0 2018-07-30T17:17:24.3320+00:00 2067196596 -34.0 -520.0
1 2018-07-30T17:17:24.3650+00:00 2067196629 -30.0 -517.0
2 2018-07-30T17:17:24.3990+00:00 2067196662 -28.0 -517.0
3 2018-07-30T17:17:24.4320+00:00 2067196695 -28.0 -518.0
4 2018-07-30T17:17:24.4650+00:00 2067196728 -30.0 -517.0
5 2018-07-30T17:17:24.4980+00:00 2067196761 -31.0 -518.0
6 2018-07-30T17:17:24.5310+00:00 2067196794 -33.0 -520.0
7 2018-07-30T17:17:24.5650+00:00 2067196828 -30.0 -519.0
8 2018-07-30T17:17:24.5970+00:00 2067196860 -30.0 -517.0
9 2018-07-30T17:17:24.6310+00:00 2067196894 -29.0 -517.0
10 2018-07-30T17:17:24.6630+00:00 2067196926 -30.0 -518.0
11 2018-07-30T17:17:24.6960+00:00 2067196959 -32.0 -520.0
12 2018-07-30T17:17:24.7300+00:00 2067196992 -32.0 -518.0
13 2018-07-30T17:17:24.7630+00:00 2067197025 -30.0 -517.0
14 2018-07-30T17:17:24.7960+00:00 2067197058 -28.0 -516.0
15 2018-07-30T17:17:24.8290+00:00 2067197091 -27.0 -516.0
16 2018-07-30T17:17:24.8620+00:00 2067197124 -31.0 -518.0
17 2018-07-30T17:17:24.8950+00:00 2067197157 -34.0 -518.0
18 2018-07-30T17:17:24.9290+00:00 2067197191 -33.0 -519.0
19 2018-07-30T17:17:24.9610+00:00 2067197223 -30.0 -517.0
20 2018-07-30T17:17:24.9950+00:00 2067197257 -27.0 -516.0
21 2018-07-30T17:17:25.0280+00:00 2067197290 -28.0 -516.0
22 2018-07-30T17:17:25.0620+00:00 2067197323 7.0 -516.0
23 2018-07-30T17:17:25.0950+00:00 2067197356 -50.0 -518.0
24 2018-07-30T17:17:25.1280+00:00 2067197389 -38.0 -517.0
25 2018-07-30T17:17:25.1610+00:00 2067197422 -39.0 -516.0
26 2018-07-30T17:17:25.1940+00:00 2067197455 -29.0 -517.0
27 2018-07-30T17:17:25.2280+00:00 2067197489 -29.0 -517.0
28 2018-07-30T17:17:25.2600+00:00 2067197521 -29.0 -517.0
29 2018-07-30T17:17:25.2930+00:00 2067197554 -30.0 -517.0
... ... ... ... ...
7559 2018-07-30T17:30:50.4950+00:00 2068000375 -58.0 -553.0
7560 2018-07-30T17:30:50.6940+00:00 2068000574 -65.0 -549.0
7561 2018-07-30T17:30:50.8930+00:00 2068000772 -73.0 -539.0
7562 2018-07-30T17:30:51.0920+00:00 2068000971 -73.0 -530.0
7563 2018-07-30T17:30:51.2910+00:00 2068001169 -76.0 -522.0
7564 2018-07-30T17:30:51.4910+00:00 2068001368 -78.0 -510.0
7565 2018-07-30T17:30:51.6900+00:00 2068001567 -73.0 -497.0
7566 2018-07-30T17:30:51.8890+00:00 2068001765 -73.0 -494.0
7567 2018-07-30T17:30:52.0980+00:00 2068001974 -64.0 -480.0
7568 2018-07-30T17:30:52.2970+00:00 2068002172 -57.0 -480.0
7569 2018-07-30T17:30:52.4960+00:00 2068002371 -50.0 -477.0
7570 2018-07-30T17:30:52.6960+00:00 2068002570 -40.0 -472.0
7571 2018-07-30T17:30:52.8950+00:00 2068002768 -32.0 -469.0
7572 2018-07-30T17:30:53.0930+00:00 2068002966 -20.0 -469.0
7573 2018-07-30T17:30:53.3030+00:00 2068003175 -14.0 -472.0
7574 2018-07-30T17:30:53.5020+00:00 2068003374 -4.0 -475.0
7575 2018-07-30T17:30:53.7020+00:00 2068003573 3.0 -480.0
7576 2018-07-30T17:30:53.9010+00:00 2068003771 8.0 -491.0
7577 2018-07-30T17:30:54.1000+00:00 2068003970 12.0 -498.0
7578 2018-07-30T17:30:54.3000+00:00 2068004169 14.0 -509.0
7579 2018-07-30T17:30:54.4980+00:00 2068004367 17.0 -514.0
7580 2018-07-30T17:30:54.6980+00:00 2068004566 16.0 -523.0
7581 2018-07-30T17:30:54.9080+00:00 2068004775 14.0 -530.0
7582 2018-07-30T17:30:54.9970+00:00 2068004864 NaN NaN
7583 2018-07-30T17:31:00.4840+00:00 2068010335 NaN NaN
7584 2018-07-30T17:31:05.5020+00:00 2068015338 NaN NaN
7585 2018-07-30T17:31:10.9830+00:00 2068020803 NaN NaN
7586 2018-07-30T17:31:16.0010+00:00 2068025806 NaN NaN
7587 2018-07-30T17:31:21.4850+00:00 2068031274 NaN NaN
7588 2018-07-30T17:31:26.5000+00:00 2068036274 NaN NaN
IMU A3 IMU G1 IMU G2 IMU G3 IMU M1 IMU M2 IMU M3 \
ride_id
14888 0 -48.0 82.0 -19.0 12.0 208.0 394.0 438.0
1 -57.0 32.0 -14.0 9.0 220.0 400.0 438.0
2 -59.0 -7.0 -11.0 6.0 218.0 398.0 430.0
3 -62.0 -27.0 -9.0 5.0 210.0 400.0 428.0
4 -62.0 64.0 -13.0 9.0 212.0 394.0 426.0
5 -54.0 157.0 -24.0 17.0 215.0 399.0 433.0
6 -41.0 29.0 -14.0 9.0 220.0 400.0 432.0
7 -46.0 -101.0 -3.0 2.0 216.0 406.0 432.0
8 -55.0 -121.0 -1.0 1.0 213.0 401.0 429.0
9 -63.0 -26.0 -8.0 6.0 218.0 396.0 428.0
10 -57.0 -7.0 -11.0 5.0 209.0 407.0 427.0
11 -54.0 -3.0 -11.0 6.0 212.0 398.0 440.0
12 -57.0 -22.0 -8.0 7.0 220.0 400.0 432.0
13 -60.0 -27.0 -9.0 6.0 208.0 400.0 434.0
14 -58.0 11.0 -12.0 9.0 216.0 396.0 430.0
15 -58.0 -4.0 -10.0 6.0 213.0 403.0 437.0
16 -55.0 -32.0 -8.0 4.0 211.0 405.0 441.0
17 -62.0 -71.0 -7.0 3.0 209.0 403.0 437.0
18 -62.0 -32.0 -9.0 5.0 203.0 395.0 433.0
19 -66.0 -68.0 14.0 5.0 213.0 395.0 441.0
20 -66.0 -97.0 25.0 3.0 218.0 392.0 436.0
21 -68.0 -60.0 10.0 6.0 216.0 392.0 440.0
22 -71.0 -24.0 4.0 5.0 217.0 397.0 441.0
23 -73.0 -47.0 13.0 5.0 217.0 399.0 445.0
24 -72.0 -43.0 6.0 8.0 210.0 396.0 442.0
25 -74.0 -29.0 -1.0 7.0 219.0 389.0 441.0
26 -73.0 -7.0 -11.0 6.0 214.0 396.0 448.0
27 -75.0 -53.0 9.0 6.0 210.0 402.0 440.0
28 -77.0 -40.0 6.0 7.0 208.0 392.0 442.0
29 -76.0 -11.0 -9.0 5.0 224.0 386.0 440.0
... ... ... ... ... ... ... ...
7559 -65.0 -9.0 -10.0 5.0 199.0 405.0 439.0
7560 -66.0 -7.0 -10.0 5.0 199.0 409.0 459.0
7561 -65.0 -8.0 -10.0 4.0 201.0 395.0 469.0
7562 -63.0 -9.0 -9.0 3.0 205.0 387.0 467.0
7563 -61.0 -8.0 -9.0 4.0 197.0 381.0 465.0
7564 -63.0 -8.0 -9.0 4.0 209.0 377.0 457.0
7565 -65.0 -9.0 -10.0 5.0 201.0 383.0 445.0
7566 -62.0 -8.0 -9.0 5.0 211.0 377.0 441.0
7567 -60.0 -7.0 -9.0 5.0 208.0 384.0 438.0
7568 -57.0 -6.0 -9.0 6.0 204.0 374.0 434.0
7569 -62.0 -7.0 -10.0 5.0 207.0 385.0 435.0
7570 -56.0 -6.0 -10.0 6.0 210.0 396.0 432.0
7571 -56.0 -6.0 -11.0 4.0 203.0 397.0 429.0
7572 -56.0 -7.0 -11.0 5.0 196.0 396.0 438.0
7573 -56.0 -6.0 -11.0 8.0 205.0 389.0 433.0
7574 -58.0 -7.0 -12.0 5.0 211.0 397.0 429.0
7575 -57.0 -6.0 -12.0 4.0 201.0 395.0 429.0
7576 -58.0 -6.0 -12.0 4.0 210.0 392.0 432.0
7577 -57.0 -6.0 -12.0 5.0 216.0 402.0 426.0
7578 -55.0 -6.0 -13.0 7.0 208.0 394.0 424.0
7579 -59.0 -7.0 -12.0 7.0 207.0 389.0 433.0
7580 -56.0 -8.0 -11.0 6.0 213.0 395.0 429.0
7581 -60.0 -8.0 -13.0 5.0 212.0 400.0 424.0
7582 NaN NaN NaN NaN NaN NaN NaN
7583 NaN NaN NaN NaN NaN NaN NaN
7584 NaN NaN NaN NaN NaN NaN NaN
7585 NaN NaN NaN NaN NaN NaN NaN
7586 NaN NaN NaN NaN NaN NaN NaN
7587 NaN NaN NaN NaN NaN NaN NaN
7588 NaN NaN NaN NaN NaN NaN NaN
Latitude Longitude
ride_id
14888 0 NaN NaN
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 NaN NaN
5 NaN NaN
6 NaN NaN
7 NaN NaN
8 NaN NaN
9 NaN NaN
10 NaN NaN
11 NaN NaN
12 NaN NaN
13 NaN NaN
14 NaN NaN
15 NaN NaN
16 NaN NaN
17 NaN NaN
18 NaN NaN
19 NaN NaN
20 NaN NaN
21 NaN NaN
22 NaN NaN
23 NaN NaN
24 NaN NaN
25 NaN NaN
26 NaN NaN
27 NaN NaN
28 NaN NaN
29 NaN NaN
... ... ...
7559 NaN NaN
7560 NaN NaN
7561 NaN NaN
7562 NaN NaN
7563 NaN NaN
7564 NaN NaN
7565 NaN NaN
7566 NaN NaN
7567 NaN NaN
7568 NaN NaN
7569 NaN NaN
7570 NaN NaN
7571 NaN NaN
7572 NaN NaN
7573 NaN NaN
7574 NaN NaN
7575 NaN NaN
7576 NaN NaN
7577 NaN NaN
7578 NaN NaN
7579 NaN NaN
7580 NaN NaN
7581 NaN NaN
7582 3286943.0 -11725208.0
7583 3286942.0 -11725208.0
7584 3286941.0 -11725207.0
7585 3286941.0 -11725206.0
7586 3286941.0 -11725206.0
7587 3286942.0 -11725206.0
7588 3286943.0 -11725207.0
[7589 rows x 13 columns]
#Drop the "nan" values from the columns that we care about.
dropped_motion_df = motion_df.dropna(subset=['Time', 'IMU A1', 'IMU A2', 'IMU A3', 'IMU G1', 'IMU G2', 'IMU G3', 'IMU M1',
'IMU M2', 'IMU M3'])
print(dropped_motion_df)
UTC Time IMU A1 IMU A2 \
ride_id
14888 0 2018-07-30T17:17:24.3320+00:00 2067196596 -34.0 -520.0
1 2018-07-30T17:17:24.3650+00:00 2067196629 -30.0 -517.0
2 2018-07-30T17:17:24.3990+00:00 2067196662 -28.0 -517.0
3 2018-07-30T17:17:24.4320+00:00 2067196695 -28.0 -518.0
4 2018-07-30T17:17:24.4650+00:00 2067196728 -30.0 -517.0
5 2018-07-30T17:17:24.4980+00:00 2067196761 -31.0 -518.0
6 2018-07-30T17:17:24.5310+00:00 2067196794 -33.0 -520.0
7 2018-07-30T17:17:24.5650+00:00 2067196828 -30.0 -519.0
8 2018-07-30T17:17:24.5970+00:00 2067196860 -30.0 -517.0
9 2018-07-30T17:17:24.6310+00:00 2067196894 -29.0 -517.0
10 2018-07-30T17:17:24.6630+00:00 2067196926 -30.0 -518.0
11 2018-07-30T17:17:24.6960+00:00 2067196959 -32.0 -520.0
12 2018-07-30T17:17:24.7300+00:00 2067196992 -32.0 -518.0
13 2018-07-30T17:17:24.7630+00:00 2067197025 -30.0 -517.0
14 2018-07-30T17:17:24.7960+00:00 2067197058 -28.0 -516.0
15 2018-07-30T17:17:24.8290+00:00 2067197091 -27.0 -516.0
16 2018-07-30T17:17:24.8620+00:00 2067197124 -31.0 -518.0
17 2018-07-30T17:17:24.8950+00:00 2067197157 -34.0 -518.0
18 2018-07-30T17:17:24.9290+00:00 2067197191 -33.0 -519.0
19 2018-07-30T17:17:24.9610+00:00 2067197223 -30.0 -517.0
20 2018-07-30T17:17:24.9950+00:00 2067197257 -27.0 -516.0
21 2018-07-30T17:17:25.0280+00:00 2067197290 -28.0 -516.0
22 2018-07-30T17:17:25.0620+00:00 2067197323 7.0 -516.0
23 2018-07-30T17:17:25.0950+00:00 2067197356 -50.0 -518.0
24 2018-07-30T17:17:25.1280+00:00 2067197389 -38.0 -517.0
25 2018-07-30T17:17:25.1610+00:00 2067197422 -39.0 -516.0
26 2018-07-30T17:17:25.1940+00:00 2067197455 -29.0 -517.0
27 2018-07-30T17:17:25.2280+00:00 2067197489 -29.0 -517.0
28 2018-07-30T17:17:25.2600+00:00 2067197521 -29.0 -517.0
29 2018-07-30T17:17:25.2930+00:00 2067197554 -30.0 -517.0
... ... ... ... ...
7551 2018-07-30T17:30:49.0880+00:00 2067998973 3.0 -548.0
7552 2018-07-30T17:30:49.2880+00:00 2067999172 -2.0 -560.0
7553 2018-07-30T17:30:49.4880+00:00 2067999371 -9.0 -567.0
7554 2018-07-30T17:30:49.6860+00:00 2067999569 -24.0 -564.0
7555 2018-07-30T17:30:49.8860+00:00 2067999768 -31.0 -561.0
7557 2018-07-30T17:30:50.0850+00:00 2067999967 -37.0 -563.0
7558 2018-07-30T17:30:50.2840+00:00 2068000165 -50.0 -561.0
7559 2018-07-30T17:30:50.4950+00:00 2068000375 -58.0 -553.0
7560 2018-07-30T17:30:50.6940+00:00 2068000574 -65.0 -549.0
7561 2018-07-30T17:30:50.8930+00:00 2068000772 -73.0 -539.0
7562 2018-07-30T17:30:51.0920+00:00 2068000971 -73.0 -530.0
7563 2018-07-30T17:30:51.2910+00:00 2068001169 -76.0 -522.0
7564 2018-07-30T17:30:51.4910+00:00 2068001368 -78.0 -510.0
7565 2018-07-30T17:30:51.6900+00:00 2068001567 -73.0 -497.0
7566 2018-07-30T17:30:51.8890+00:00 2068001765 -73.0 -494.0
7567 2018-07-30T17:30:52.0980+00:00 2068001974 -64.0 -480.0
7568 2018-07-30T17:30:52.2970+00:00 2068002172 -57.0 -480.0
7569 2018-07-30T17:30:52.4960+00:00 2068002371 -50.0 -477.0
7570 2018-07-30T17:30:52.6960+00:00 2068002570 -40.0 -472.0
7571 2018-07-30T17:30:52.8950+00:00 2068002768 -32.0 -469.0
7572 2018-07-30T17:30:53.0930+00:00 2068002966 -20.0 -469.0
7573 2018-07-30T17:30:53.3030+00:00 2068003175 -14.0 -472.0
7574 2018-07-30T17:30:53.5020+00:00 2068003374 -4.0 -475.0
7575 2018-07-30T17:30:53.7020+00:00 2068003573 3.0 -480.0
7576 2018-07-30T17:30:53.9010+00:00 2068003771 8.0 -491.0
7577 2018-07-30T17:30:54.1000+00:00 2068003970 12.0 -498.0
7578 2018-07-30T17:30:54.3000+00:00 2068004169 14.0 -509.0
7579 2018-07-30T17:30:54.4980+00:00 2068004367 17.0 -514.0
7580 2018-07-30T17:30:54.6980+00:00 2068004566 16.0 -523.0
7581 2018-07-30T17:30:54.9080+00:00 2068004775 14.0 -530.0
IMU A3 IMU G1 IMU G2 IMU G3 IMU M1 IMU M2 IMU M3 \
ride_id
14888 0 -48.0 82.0 -19.0 12.0 208.0 394.0 438.0
1 -57.0 32.0 -14.0 9.0 220.0 400.0 438.0
2 -59.0 -7.0 -11.0 6.0 218.0 398.0 430.0
3 -62.0 -27.0 -9.0 5.0 210.0 400.0 428.0
4 -62.0 64.0 -13.0 9.0 212.0 394.0 426.0
5 -54.0 157.0 -24.0 17.0 215.0 399.0 433.0
6 -41.0 29.0 -14.0 9.0 220.0 400.0 432.0
7 -46.0 -101.0 -3.0 2.0 216.0 406.0 432.0
8 -55.0 -121.0 -1.0 1.0 213.0 401.0 429.0
9 -63.0 -26.0 -8.0 6.0 218.0 396.0 428.0
10 -57.0 -7.0 -11.0 5.0 209.0 407.0 427.0
11 -54.0 -3.0 -11.0 6.0 212.0 398.0 440.0
12 -57.0 -22.0 -8.0 7.0 220.0 400.0 432.0
13 -60.0 -27.0 -9.0 6.0 208.0 400.0 434.0
14 -58.0 11.0 -12.0 9.0 216.0 396.0 430.0
15 -58.0 -4.0 -10.0 6.0 213.0 403.0 437.0
16 -55.0 -32.0 -8.0 4.0 211.0 405.0 441.0
17 -62.0 -71.0 -7.0 3.0 209.0 403.0 437.0
18 -62.0 -32.0 -9.0 5.0 203.0 395.0 433.0
19 -66.0 -68.0 14.0 5.0 213.0 395.0 441.0
20 -66.0 -97.0 25.0 3.0 218.0 392.0 436.0
21 -68.0 -60.0 10.0 6.0 216.0 392.0 440.0
22 -71.0 -24.0 4.0 5.0 217.0 397.0 441.0
23 -73.0 -47.0 13.0 5.0 217.0 399.0 445.0
24 -72.0 -43.0 6.0 8.0 210.0 396.0 442.0
25 -74.0 -29.0 -1.0 7.0 219.0 389.0 441.0
26 -73.0 -7.0 -11.0 6.0 214.0 396.0 448.0
27 -75.0 -53.0 9.0 6.0 210.0 402.0 440.0
28 -77.0 -40.0 6.0 7.0 208.0 392.0 442.0
29 -76.0 -11.0 -9.0 5.0 224.0 386.0 440.0
... ... ... ... ... ... ... ...
7551 -60.0 -8.0 -11.0 7.0 208.0 396.0 428.0
7552 -65.0 -11.0 -11.0 6.0 204.0 396.0 434.0
7553 -61.0 -9.0 -11.0 4.0 207.0 401.0 423.0
7554 -63.0 -8.0 -10.0 4.0 215.0 395.0 429.0
7555 -66.0 -9.0 -10.0 4.0 205.0 403.0 425.0
7557 -66.0 -9.0 -10.0 6.0 200.0 402.0 440.0
7558 -66.0 -9.0 -10.0 6.0 202.0 398.0 446.0
7559 -65.0 -9.0 -10.0 5.0 199.0 405.0 439.0
7560 -66.0 -7.0 -10.0 5.0 199.0 409.0 459.0
7561 -65.0 -8.0 -10.0 4.0 201.0 395.0 469.0
7562 -63.0 -9.0 -9.0 3.0 205.0 387.0 467.0
7563 -61.0 -8.0 -9.0 4.0 197.0 381.0 465.0
7564 -63.0 -8.0 -9.0 4.0 209.0 377.0 457.0
7565 -65.0 -9.0 -10.0 5.0 201.0 383.0 445.0
7566 -62.0 -8.0 -9.0 5.0 211.0 377.0 441.0
7567 -60.0 -7.0 -9.0 5.0 208.0 384.0 438.0
7568 -57.0 -6.0 -9.0 6.0 204.0 374.0 434.0
7569 -62.0 -7.0 -10.0 5.0 207.0 385.0 435.0
7570 -56.0 -6.0 -10.0 6.0 210.0 396.0 432.0
7571 -56.0 -6.0 -11.0 4.0 203.0 397.0 429.0
7572 -56.0 -7.0 -11.0 5.0 196.0 396.0 438.0
7573 -56.0 -6.0 -11.0 8.0 205.0 389.0 433.0
7574 -58.0 -7.0 -12.0 5.0 211.0 397.0 429.0
7575 -57.0 -6.0 -12.0 4.0 201.0 395.0 429.0
7576 -58.0 -6.0 -12.0 4.0 210.0 392.0 432.0
7577 -57.0 -6.0 -12.0 5.0 216.0 402.0 426.0
7578 -55.0 -6.0 -13.0 7.0 208.0 394.0 424.0
7579 -59.0 -7.0 -12.0 7.0 207.0 389.0 433.0
7580 -56.0 -8.0 -11.0 6.0 213.0 395.0 429.0
7581 -60.0 -8.0 -13.0 5.0 212.0 400.0 424.0
Latitude Longitude
ride_id
14888 0 NaN NaN
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 NaN NaN
5 NaN NaN
6 NaN NaN
7 NaN NaN
8 NaN NaN
9 NaN NaN
10 NaN NaN
11 NaN NaN
12 NaN NaN
13 NaN NaN
14 NaN NaN
15 NaN NaN
16 NaN NaN
17 NaN NaN
18 NaN NaN
19 NaN NaN
20 NaN NaN
21 NaN NaN
22 NaN NaN
23 NaN NaN
24 NaN NaN
25 NaN NaN
26 NaN NaN
27 NaN NaN
28 NaN NaN
29 NaN NaN
... ... ...
7551 NaN NaN
7552 NaN NaN
7553 NaN NaN
7554 NaN NaN
7555 NaN NaN
7557 NaN NaN
7558 NaN NaN
7559 NaN NaN
7560 NaN NaN
7561 NaN NaN
7562 NaN NaN
7563 NaN NaN
7564 NaN NaN
7565 NaN NaN
7566 NaN NaN
7567 NaN NaN
7568 NaN NaN
7569 NaN NaN
7570 NaN NaN
7571 NaN NaN
7572 NaN NaN
7573 NaN NaN
7574 NaN NaN
7575 NaN NaN
7576 NaN NaN
7577 NaN NaN
7578 NaN NaN
7579 NaN NaN
7580 NaN NaN
7581 NaN NaN
[7463 rows x 13 columns]
# To store time elapsed between each measurement, and time offset from 0s
time_e_list = []
time_o_list = []
#Remove all nan instances in time:
time_array_nans = np.array(dropped_motion_df.loc[:,"Time"], dtype=float)
time_array = []
imuA1_array_nans = np.array(dropped_motion_df.loc[:,"IMU A1"], dtype=float)
imu_array_A1 = []
imuA2_array_nans = np.array(dropped_motion_df.loc[:,"IMU A2"], dtype=float)
imu_array_A2 = []
imuA3_array_nans = np.array(dropped_motion_df.loc[:,"IMU A3"], dtype=float)
imu_array_A3 = []
imuG1_array_nans = np.array(dropped_motion_df.loc[:,"IMU G1"], dtype=float)
imu_array_G1 = []
imuG2_array_nans = np.array(dropped_motion_df.loc[:,"IMU G2"], dtype=float)
imu_array_G2 = []
imuG3_array_nans = np.array(dropped_motion_df.loc[:,"IMU G3"], dtype=float)
imu_array_G3 = []
imuM1_array_nans = np.array(dropped_motion_df.loc[:,"IMU M1"], dtype=float)
imu_array_M1 = []
imuM2_array_nans = np.array(dropped_motion_df.loc[:,"IMU M2"], dtype=float)
imu_array_M2 = []
imuM3_array_nans = np.array(dropped_motion_df.loc[:,"IMU M3"], dtype=float)
imu_array_M3 = []
#Get all the times and imus where time, imu a1, imu a2, and imu a3 are NOT nan values:
for t,x,y,z,a,b,c,d,e,f in zip(time_array_nans, imuA1_array_nans, imuA2_array_nans, imuA3_array_nans, imuG1_array_nans,
imuG2_array_nans, imuG3_array_nans, imuM1_array_nans, imuM2_array_nans, imuM3_array_nans):
if (np.isnan(t)==0 and np.isnan(x)==0 and np.isnan(y)==0 and np.isnan(z)==0):
time_array.append(t)
imu_array_A1.append(x)
imu_array_A2.append(y)
imu_array_A3.append(z)
imu_array_G1.append(a)
imu_array_G2.append(b)
imu_array_G3.append(c)
imu_array_M1.append(d)
imu_array_M2.append(e)
imu_array_M3.append(f)
#for x in time_array:
# print(x)
start_time = time_array[0]
time_len = len(time_array)
i = 0
while (i < time_len - 1):
prev = time_array[i]
after = time_array[i+1]
offset = after - prev
#if (np.isnan(offset)==0):
time_o_list.append(offset)
elapsed = time_array[i] - start_time
#if (np.isnan(elapsed)==0):
time_e_list.append(elapsed)
i = i + 1
##Check to make sure there are no "nan" values:
i = 0
while (i < len(time_o_list)):
if (np.isnan(time_o_list[i])):
print("Error! Value at index: ", i, " is nan")
i = i + 1
#Drop the last value from each of the imu lists to make it match the time list.
del(imu_array_A1[-1])
del(imu_array_A2[-1])
del(imu_array_A3[-1])
del(imu_array_G1[-1])
del(imu_array_G2[-1])
del(imu_array_G3[-1])
del(imu_array_M1[-1])
del(imu_array_M2[-1])
del(imu_array_M3[-1])
print(len(time_e_list))
print(len(time_o_list))
print(len(imu_array_A1))
print(len(imu_array_A2))
print(len(imu_array_A3))
print(len(imu_array_G1))
print(len(imu_array_G2))
print(len(imu_array_G3))
print(len(imu_array_M1))
print(len(imu_array_M2))
print(len(imu_array_M3))
CheckLength = len(time_e_list) + len(time_o_list) + len(imu_array_A1) + len(imu_array_A2) + len(imu_array_A3) + len(imu_array_G1) + len(imu_array_G2) + len(imu_array_G3) + len(imu_array_M1)+ len(imu_array_M2) + len(imu_array_M3)
if CheckLength//11 == len(time_e_list):
print("All columns are matching!")
7462
7462
7462
7462
7462
7462
7462
7462
7462
7462
7462
All columns are matching!
#Raw acceleration constant 512 = 1g (accelerometer's measured force due to gravity)
g_const = 512
#Approximate measurement for gravity:
gravity = 9.80665
# Correct the IMU Acceleration columns into units of meters
def convert_acc_units(acc_array):
ret_array = []
for a in acc_array:
#Acceleration is now in m/s^2, need to subtract gravity from vertical axis. (??)
new_a = a / g_const * gravity + gravity
ret_array.append(new_a)
return ret_array
imu1_array = convert_acc_units(imu_array_A1) #new units in m/s^2
imu2_array = convert_acc_units(imu_array_A2) #new units in m/s^2
imu3_array = convert_acc_units(imu_array_A3) #new units in m/s^2
# To check:
#for x,y in zip(imu2_array, imu_array_A2):
# print(x,y)
def convert_time_units(time_array):
ret_array = []
for t in time_array:
new_t = t * (10**(-3)) #converting units in milliseconds to seconds
ret_array.append(new_t)
return ret_array
time_o_array = convert_time_units(time_o_list) #new units in seconds
time_e_array = convert_time_units(time_e_list) #new units in seconds
# To check:
# for t in time_e_array:
# print(t)
print("Done!")
Done!
# Square x and z acceleration values
accel_xz_array = [];
for i in range(0, len(imu1_array)):
currMagnitude = math.sqrt((math.pow(imu1_array[i], 2) + math.pow(imu3_array[i], 2)))
accel_xz_array.append(currMagnitude)
print("Graph of XZ Acceleration vs. Time")
plt.plot(time_e_array, accel_xz_array)
plt.xlabel("Time (s)")
plt.ylabel("Acceleration-XZ (m/s^2)")
plt.show()
Graph of XZ Acceleration vs. Time
# Offset variables help in recentering the magnetic data in order to define direction and use trig functions
M1_offset_var = 219.786
M2_offset_var = 180
M3_offset_var = 280
def calibrate_magn_data(magn_array, offset_value):
ret_array = []
for m in magn_array:
new_m = m - offset_value
ret_array.append(new_m)
return ret_array
imuM1_array = calibrate_magn_data(imu_array_M1, M1_offset_var)
imuM2_array = calibrate_magn_data(imu_array_M2, M2_offset_var)
imuM3_array = calibrate_magn_data(imu_array_M3, M3_offset_var)
# Check
# print(imuM1_array)
print("Done.")
Done.
# Create N x 3 arrays for functions that need them later on, such as Scikit Kinematics
magn_height = len(imuM1_array)
acc_height = len(imu1_array)
acc_array = np.zeros(shape=(acc_height,3))
magn_array = np.zeros(shape=(magn_height,3))
print("For Accelerometer: ")
for x in range(len(acc_array)):
acc_array[x,0] = imu1_array[x]
acc_array[x,1] = imu2_array[x]
acc_array[x,2] = imu3_array[x]
print(acc_array)
print("\nFor Magnetometer: ")
for x in range(len(magn_array)):
magn_array[x,0] = imuM1_array[x]
magn_array[x,1] = imuM2_array[x]
magn_array[x,2] = imuM3_array[x]
print(magn_array)
print("Done.")
For Accelerometer:
[[ 9.15542715 -0.15322891 8.88727656]
[ 9.2320416 -0.09576807 8.71489404]
[ 9.27034883 -0.09576807 8.67658682]
...
[10.07480059 0.05746084 8.75320127]
[10.13226143 -0.03830723 8.67658682]
[10.11310781 -0.21068975 8.73404766]]
For Magnetometer:
[[-1.1786e+01 2.1400e+02 1.5800e+02]
[ 2.1400e-01 2.2000e+02 1.5800e+02]
[-1.7860e+00 2.1800e+02 1.5000e+02]
...
[-1.1786e+01 2.1400e+02 1.4400e+02]
[-1.2786e+01 2.0900e+02 1.5300e+02]
[-6.7860e+00 2.1500e+02 1.4900e+02]]
Done.
Orientation from here onwards will be from the board/surfers reference frame (yaw left = turning left)
x = -IMU1, y = -IMU3, z = -IMU2
# The new array for board reference frame will have the IMUs in columns according to X,Y,Z directions
board_acc = acc_array.copy() # Reassign to the correct axes as stated above
temp_x_acc = board_acc[:,0] * (-1)
temp_y_acc = board_acc[:,1] * (-1)
temp_z_acc = board_acc[:,2] * (-1)
board_acc[:,0] = temp_x_acc # X acceleration
board_acc[:,1] = temp_y_acc # Y acceleration
board_acc[:,2] = temp_z_acc # Z acceleration
print(board_acc)
print("\n")
board_magn = magn_array.copy()
temp_x_magn = board_magn[:,0] * (-1)
temp_y_magn = board_magn[:,1] * (-1)
temp_z_magn = board_magn[:,2] * (-1)
board_magn[:,0] = temp_x_magn
board_magn[:,1] = temp_y_magn
board_magn[:,2] = temp_z_magn
print(board_magn)
print("Done.")
[[ -9.15542715 0.15322891 -8.88727656]
[ -9.2320416 0.09576807 -8.71489404]
[ -9.27034883 0.09576807 -8.67658682]
...
[-10.07480059 -0.05746084 -8.75320127]
[-10.13226143 0.03830723 -8.67658682]
[-10.11310781 0.21068975 -8.73404766]]
[[ 1.1786e+01 -2.1400e+02 -1.5800e+02]
[-2.1400e-01 -2.2000e+02 -1.5800e+02]
[ 1.7860e+00 -2.1800e+02 -1.5000e+02]
...
[ 1.1786e+01 -2.1400e+02 -1.4400e+02]
[ 1.2786e+01 -2.0900e+02 -1.5300e+02]
[ 6.7860e+00 -2.1500e+02 -1.4900e+02]]
Done.
# Square x, y and z acceleration values
accel_xyz_array = [];
for i in range(0, len(board_acc)):
currMagnitude = math.sqrt(math.pow(board_acc[i][0], 2) + math.pow(board_acc[i][1], 2) + math.pow(board_acc[i][2], 2))
accel_xyz_array.append(currMagnitude)
# Check length
print(len(accel_xyz_array))
print("Graph of XYZ Acceleration vs. Time")
plt.plot(time_e_array, accel_xyz_array)
plt.xlabel("Time (s)")
plt.ylabel("Acceleration-XYZ (m/s^2)")
plt.show()
7462
Graph of XYZ Acceleration vs. Time
# Azimuth and Altitude LEGEND:
# Altitude is the angle between the ground and the vector
# Azimuth is the angle going clockwise from 0 deg North:
# N - 0/360deg, E - 90deg, S - 180deg, W - 270deg
# This will get complicated (ie make cases or lots of if statements) when rotations about the heading become more prevalent
def azimuth(x,y,z):
real_y = y * (-1) # This is to account for y
return (180/math.pi * math.atan2(real_y,x)) % 360
def altitude(x,y,z):
h = math.hypot(y, x)
return 180/math.pi * math.atan2(z,h)
def printAltAzi(alt, azi):
print ("Alt:", alt, "\n", "Azi:",azi,"\n")
# These values are uncorrected values: still need to add or subtract 'declination'
# (for AziMuth) and 'inclination' (for Altitude) correction values for geographical location
heading_altitude = board_magn[:,0].copy()
heading_azimuth = board_magn[:,0].copy()
i = 0 #iterator
#for i in range(len(M1_no_out)):
while i < len(heading_altitude):
heading_altitude[i] = altitude(board_magn[i,0], board_magn[i,1], board_magn[i,2])
heading_azimuth[i] = azimuth(board_magn[i,0], board_magn[i,1], board_magn[i,2])
#printAltAzi(heading_altitude[i],heading_azimuth[i])
i += 1
heading_azi_plot = plt.figure(figsize=(10,5))
azi_plot = heading_azi_plot.add_subplot(111)
azi_plot.plot(time_e_array, heading_azimuth)
azi_plot.set_title("Azimuth vs. Time")
azi_plot.set_xlabel("Time Elapsed[sec]")
azi_plot.set_ylabel("Azimuth [deg]")
azi_plot.set_ylim([-50,400])
heading_alt_plot = plt.figure(figsize=(10,5))
alt_plot = heading_alt_plot.add_subplot(111)
alt_plot.plot(time_e_array, heading_altitude)
alt_plot.set_title("Altitude vs. Time")
alt_plot.set_xlabel("Time Elapsed [sec]")
alt_plot.set_ylabel("Altitude [deg]")
plt.show()
#for t in range(len(time_e_array)):
#printAltAzi(heading_altitude[t], heading_azimuth[t])
# Fixing random state for reproducibility
np.random.seed(19680801)
# Compute areas and colors
r = [i for i in range(0, len(board_magn))]
theta = heading_azimuth/360 * 2 * np.pi
area = 1
colors = theta
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=1)
# Compute areas and colors
alt_r = [i for i in range(0, len(board_magn))]
alt_theta = heading_altitude/360 * 2 * np.pi
alt_area = 1
alt_colors = theta
fig2 = plt.figure(figsize=(10,10))
ax2 = fig2.add_subplot(111, projection='polar')
c2 = ax2.scatter(alt_theta, alt_r, c=alt_colors, s=alt_area, cmap='hsv', alpha=1)
# Plot first 10 directional changes
magnfig = plt.figure(figsize=(20,20))
magnaxi = magnfig.add_subplot(111, projection='3d')
magnaxi.scatter(board_magn[0,0], board_magn[0,2], board_magn[0,1], c='black', s=300, marker = "<")
magnaxi.scatter(board_magn[1:,0], board_magn[1:,2], board_magn[1:,1], c='black', s=10, marker = "o")
magnaxi.plot(board_magn[:,0], board_magn[:,2], board_magn[:,1], color='red')
magnaxi.set_xlabel("X Axis ->", fontsize=30)
magnaxi.set_ylabel("Y Axis ->", fontsize=30)
magnaxi.set_zlabel("Z Axis ->", fontsize=30)
plt.show()
As displayed in the diagram, the method for determining peak wave direction is to pool all the data from each of these Smartfins so that we can conduct a cumulative spectral analysis. This means instead of generating a frequency graph for a single ride, we will generate multiple graphs that represents the data for all the Smartfins, and then analyze the frequency transitions between close-by Smartfins.
As the graph suggests, the only difference between this frequency graph and the one used to determine wave height is the parameter wave density, which is essentially the average acceleration per unit of frequency. It represents the energy density per wave unit. Overall, we can compare each frequency graph side-by-side to see how the wave behaves when it starts from one Smartfin and reaches the next. Using this data, we can generalize the directional propagation and behaviour of the waves in the region covered by all the Smartfins. The projected result of my method can be visualized below:
-
Currently, the most popular methods to determine wave direction involve using Buoys, which don't give sufficient data in terms of determining wave direction in a small region. Since buoys are spaced out hundred of meters apart and way offshore, it is almost impossible to determine proximal wave direction without the help of Smartfins.
-
One way to generate a directional spectrum is to measure the same parameter - such as pressure - at a series of nearby locations using pressor sensors. I considered this, but realized that we didn't have the resources to conduct such an experiment.
-
The other way to produce a directional spectrum is by measuring different parameters at the same point. This is the approach used in directional buoys, which measure pitch and roll in addition to vertical heave. However, even this could easily be achieved using an array of Smartfins. It would essentially accomplish the same task as the directional buoys, and it would be much easier to gather wave data for smaller regions.
-
Using spectral analysis and frequency graphs, this method reuses the one for determining wave height, and is much simpler to execute.
-
The only disadvantage I can forsee is the level of noise and inaccuracy presented by Smartfins and the potential for human error, for example when a surfer decides to paddle upstream, or push their surfboard deeper underwater into a wave.
Created by: Howard Wang, 05/08/19