plot.py 1.53 KB
Newer Older
Nathan Coppin's avatar
Nathan Coppin committed
1
2
3
4
5
6
7
8
import numpy as np
import os
import time
import shutil
import random
import csv 
import matplotlib.pyplot as plt

Nathan Coppin's avatar
Nathan Coppin committed
9
filename = "ellipseForced/Drag.csv"
Nathan Coppin's avatar
Nathan Coppin committed
10
11
12
13
with open(filename) as file1:
      reader = csv.reader(file1,delimiter = ";",quoting=csv.QUOTE_NONNUMERIC)
      data = [r for r in reader]  
data = np.array(data);
Nathan Coppin's avatar
Nathan Coppin committed
14
15
16
react = data[:,1]
react2 = data[:,3]
react3 = data[:,5]
Nathan Coppin's avatar
Nathan Coppin committed
17
prod = np.zeros_like(react)
Nathan Coppin's avatar
Nathan Coppin committed
18
19
20
prod2 = np.zeros_like(react2)
prod3 = np.zeros_like(react3)
ranges = 500
Nathan Coppin's avatar
Nathan Coppin committed
21
print(data)
Nathan Coppin's avatar
Nathan Coppin committed
22
for i in range(len(react)):
Nathan Coppin's avatar
Nathan Coppin committed
23
24
  if i <ranges:
    prod[i] = np.sum(react[0:i+ranges])/(i+ranges)
Nathan Coppin's avatar
Nathan Coppin committed
25
26
    prod2[i] = np.sum(react2[0:i+ranges])/(i+ranges)
    prod3[i] = np.sum(react3[0:i+ranges])/(i+ranges)
Nathan Coppin's avatar
Nathan Coppin committed
27
28
  elif len(react)-i<ranges:
    prod[i] = np.sum(react[i-ranges:])/((len(react)-i)+ranges)
Nathan Coppin's avatar
Nathan Coppin committed
29
30
    prod2[i] = np.sum(react2[i-ranges:])/((len(react)-i)+ranges)
    prod3[i] = np.sum(react3[i-ranges:])/((len(react)-i)+ranges)
Nathan Coppin's avatar
Nathan Coppin committed
31
  else:
Nathan Coppin's avatar
Nathan Coppin committed
32
    prod[i] = np.sum(react[i-ranges:i+ranges])/(2*ranges)
Nathan Coppin's avatar
Nathan Coppin committed
33
34
    prod2[i] = np.sum(react2[i-ranges:i+ranges])/(2*ranges)
    prod3[i] = np.sum(react3[i-ranges:i+ranges])/(2*ranges)
Nathan Coppin's avatar
Nathan Coppin committed
35

Nathan Coppin's avatar
Nathan Coppin committed
36
37
38
39

print(np.mean(prod[5000:]))
mean = np.ones_like(prod[5000:])*np.mean(prod[5000:])
TimeVel = (data[5000:, 7] + data[5000:, 8])/2
Nathan Coppin's avatar
switch    
Nathan Coppin committed
40
plt.plot(data[:,6],-prod,color='black')
Nathan Coppin's avatar
Nathan Coppin committed
41
42
43
plt.plot(data[:,6],-prod2, color = 'purple')
plt.plot(data[:,6],-prod3, color = 'green')
plt.plot(data[5000:,6],-mean,color = 'red')
Nathan Coppin's avatar
Nathan Coppin committed
44
45
plt.xlabel("Time [s]",size=15)
plt.ylabel("Drag force [N]",size=15)
Nathan Coppin's avatar
Nathan Coppin committed
46
47
48
plt.title("v = %.1f mm/s"%(np.mean(TimeVel)*1000))
plt.ylim([-1,150])
plt.xlim([.0,20])
Nathan Coppin's avatar
Nathan Coppin committed
49
plt.show()