In [1]:
# imports libraries
import os
import sys
import glob
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
import math
import sklearn.decomposition as dcmp
import pyaudio
import csv
import IPython
import pywt
%matplotlib inline
# Grabs the preprocessing and automatic_sync files
sys.path.append(os.path.join(os.pardir,'pythonCode'))
import preprocessing as pp
import automatic_sync as autoS
import detection as det
In [2]:
# Determines which cameras will be selected (['Bents'],['Camera Location'],['Motion #'])
filt = (None,None,['18']) # Selects the bent 1 camera used during motion 18
# now reads in the datafile from the raw data folder
rawDataPath = os.path.join(os.pardir,'rawData')
files = glob.glob(os.path.join(rawDataPath, '*.wav'))
names = []
for name in files:
fileName = os.path.basename(name).split(".")[0]
names.append(fileName)
# Applies filter to camera names and returns only selected subset names
audioFiles = pp.getKeys(names,filt);
# Reads the .wav files from the list generted by getKeys
(names,rawDataset) = pp.readWAV(rawDataPath,audioFiles);
In [37]:
final_offsets, syncData = autoS.sync_dataset(rawDataset,'GP_B1_NL_18',names,mask=[0,1])
print(final_offsets)
In [38]:
index = 1
totalfrac = {}
fig1 = plt.figure(figsize = (12,30))
for name in names:
plt.subplot(len(names),1,index)
fractures = det.spectrogram_ridges(syncData[name][:,0],min_length = 130)
plt.xlim(30,40)
totalfrac[name] = fractures
index += 1
In [6]:
index = 1
totalfrac2 = {}
fig1 = plt.figure(figsize = (12,30))
for name in names:
plt.subplot(len(names),1,index)
fractures = det.med_filt(syncData[name][:,0],kernel = 7,thresh = 16)
plt.xlim(30,40)
totalfrac2[name] = fractures
index += 1
In [7]:
index = 1
totalfrac3 = {}
fig1 = plt.figure(figsize = (12,30))
for name in names:
plt.subplot(len(names),1,index)
fractures = det.cwt_ridges(syncData[name][:,0])
plt.xlim(30,40)
totalfrac3[name] = fractures
index += 1
In [8]:
csvPath = os.path.join(os.pardir,'rawData')
fileName = glob.glob(os.path.join(csvPath,'GP_B1_NL_18.csv'));
fractInd = list(csv.reader(open(fileName[0], 'rt'), delimiter=','))
fractInd = np.array([float(i[0]) for i in fractInd]) # in counts
fractIM = 1/48000*(-final_offsets['GP_B1_NL_18'] + fractInd)
print(fractIM)
In [39]:
# for spectrogram ridgeline detection method
index = 1
for name in names:
plt.plot(totalfrac[name], index*np.ones_like(totalfrac[name]),'ko')
index += 1
plt.plot([fractIM,fractIM],[0,len(names)+1],'r')
plt.yticks(np.arange(1,len(names)+1), names)
plt.xlim(30,40)
plt.show()
In [40]:
# for spectrogram ridgeline detection method
index = 1
this_array = []
for name in names:
this_array = np.hstack((this_array,totalfrac[name]))
bins = np.linspace(0, 60, 2400)
n = plt.hist(this_array, bins)
plt.xlim(33,40)
plt.ylim(1,5)
Out[40]:
In [34]:
Out[34]:
In [10]:
# for the median filter thresholding method
index = 1
for name in names:
plt.plot(totalfrac2[name], index*np.ones_like(totalfrac2[name]),'ko')
index += 1
plt.plot([fractIM,fractIM],[0,len(names)+1],'r')
plt.yticks(np.arange(1,len(names)+1), names)
plt.xlim(30,40)
plt.show()
In [11]:
# for the cwt ridgeline detection method
index = 1
for name in names:
plt.plot(totalfrac3[name], index*np.ones_like(totalfrac3[name]),'ko')
index += 1
plt.plot([fractIM,fractIM],[0,len(names)+1],'r')
plt.yticks(np.arange(1,len(names)+1), names)
plt.xlim(30,40)
plt.show()