In [1]:
import os
import numpy as np
import csv
import datetime
import matplotlib.pyplot as plt
import sys
import argparse

In [2]:
path = 'C:/Users/emily/documents/Color_Detectors'

In [14]:
x = []
y = []
yerr = []
allCO2 = []
for filename in os.listdir(path):
    print(filename)
    with open(path+'/'+filename,'r') as f:
        reader = csv.reader(f)
        CO2 = []
        err = []
        for row in reader:
            try:
                CO2.append(float(row[1]))
                err.append(float(row[2]))
            except Exception as e:
                print(e)
                pass
        CO2_avg = np.mean(np.array(CO2))
        err_avg = np.std(np.array(CO2))
        allCO2.append(CO2)
        print(CO2_avg)
        print(err_avg)
        x.append(filename)
        y.append(CO2_avg)
        yerr.append(err_avg)


blue_2019-04-30_CO2.csv
could not convert string to float: 'CO2 (ppm)'
524.4051809806701
21.38942296237964
clear_b_2019-04-30_CO2.csv
could not convert string to float: 'CO2 (ppm)'
432.4225080345666
6.571855989244388
clear_f_2019-04-30_CO2.csv
could not convert string to float: 'CO2 (ppm)'
608.1091647475337
15.27033688833574
pink_2019-05-03_CO2.csv
could not convert string to float: 'CO2 (ppm)'
could not convert string to float: 'CO2 (ppm)'
436.5626901457969
7.1045613113754875
purple_2019-04-30_CO2.csv
could not convert string to float: 'CO2 (ppm)'
could not convert string to float: 'CO2 (ppm)'
513.1667528101942
5.313186852203875
white_2019-04-25_CO2.csv
could not convert string to float: 'CO2 (ppm)'
432.1234214307325
8.271009901235509
yellow_2019-04-30_CO2.csv
could not convert string to float: 'CO2 (ppm)'
608.9511187691373
6.034658623240503

In [10]:
plt.plot(x, y)
plt.errorbar(x, y, yerr)

plt.xlabel('test')
plt.ylabel('ppm')

plt.title('Co2 Averages')

plt.show()



In [11]:
n, bins, patches = plt.hist(x=y, bins='auto')
plt.grid(axis='y')
plt.xlabel('ppm')
plt.ylabel('Frequency')
plt.title('CO2 Averages')
plt.show()



In [18]:
labels=["blue","clear_f","clear_b","pink","purple","white","yellow","red"]
for i in range(len(allCO2)):
    n, bins, patches = plt.hist(x=allCO2[i], bins='auto', alpha=0.5, label=labels[i])
plt.legend(loc='upper right')


Out[18]:
<matplotlib.legend.Legend at 0x1be03ef4518>

In [12]:
Total_mean = np.mean(np.array(y))
Tmean = print('Total avg = {}'.format(Total_mean))
Total_std = np.std(np.array(y))
print('Total std = {}'.format(Total_std))
Ins_rms = np.square(np.array(yerr))
Total_rms = np.sqrt(np.sum(Ins_rms))
print('rms = {}'.format(Total_rms))


Total avg = 507.96297670266165
Total std = 72.78273996343646
rms = 30.288799083640146

In [ ]:


In [ ]: