-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransmitter_analysis.py
129 lines (99 loc) · 3.06 KB
/
transmitter_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 11 17:08:15 2017
@author: Jordan
Looking at data results carefully in code and plots
Examining moving data and generating contour plots
Note data smoothing required
Analysis on July 11 data
Making Contour plots
Analysis on July 19 data, creating contour plots to verify transmitter location
"""
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from scipy.interpolate import griddata
from TDMS_handler import runTDMS
import os.path
from dataprep import make_contour, calcSma
import glob
#%% Functions
#def normpower(xx):
# for i in range(3,7):
# col = xx[:,i]
# newcol = (col - np.min(col)) / (np.max(col) - np.min(col))
# xx[:,i] = newcol
# return xx
#%% Main
dir_in = '../Data/july19/static/' # Main folder of our current study
file = "static_9.tdms"
dir_analysis = '../Data/july19/static/analysis/' # Location of analysis files
#%% If running single files, use logic below
path_in = dir_in + 'analysis/' + file[:-5] + '.csv'
if os.path.isfile(path_in):
print 'file exists. Will not run TDMS Importer'
else:
runTDMS(dir_in,file) # Run TDMS Import script
#%% Main
interp_method = 'nearest' # Interpolation method used for griddata function
boolplot = 0 # Flag for plotting contour points or not
# Load data
x_all=[]
filelist = glob.glob(dir_analysis + '*.csv') # Generate file list
for file in filelist:
x_all.append(np.genfromtxt(file,delimiter=','))
# Combine with others
xx = np.vstack(x_all)
m = len(xx)
#Segment and shuffle as required
#segment = 0.2
#np.random.shuffle(xx)
#xx = xx[0:int(segment*m),:]
#xx = xx[::250]
# Normalize our power data
#maxpower = np.max(xx[:,3:])
#minpower = np.min(xx[:,3:])
#xx = normpower(xx)
#xx[:,3:7] = np.round(xx[:,3:7],decimals=4)
# Extract values
time = xx[:,0] # Extract time value
x = xx[:,1]
y = xx[:,2]
c1 = xx[:,3]
c2 = xx[:,4]
c3 = xx[:,5]
c4 = xx[:,6]
channel = c1 # Choose the channel we analyze
#channel = np.resize(channel,(len(channel),1))
#%% Data treatment and smoothing
#!! Change logic order since we should data smoothing on individual files !!#
#N1 = 300
#smooth_channel = calcSma(channel,N1)
#smooth_x = x[N1-1:]
#smooth_y = y[N1-1:]
# Data handling
#x = np.round(x,decimals=1)
#y = np.round(y,decimals=1)
#%% Plotting
# Coordinate plot
plt.figure(1)
plt.plot(time,y,"o")
plt.plot(time,x,"x")
plt.title('x and y coordinate changes with time')
# Look at some data
slice1=0
slice2=int(m*0.3)
plt.figure(2)
plt.plot(time[slice1:slice2],channel[slice1:slice2],"o")
plt.title("Signal power with time")
plt.figure(3)
plt.plot(y[slice1:slice2],channel[slice1:slice2],"o")
plt.title("Signal power with distance")
#%% Contour Plot and Surface plot
# Surface plot is probably more applicable
#f2, (ax21, ax22) = plt.subplots(1,2)
make_contour(x,y,channel,interp_method=interp_method,levels=15,boolplot=boolplot,file=file)
# Look at the smooth data
#make_contour(smooth_x,smooth_y,smooth_channel,interp_method=interp_method,levels=15,boolplot=boolplot,file=file)