amc2021:groupl:extras:python:start
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
amc2021:groupl:extras:python:start [2021/09/05 01:14] – created kshama001 | amc2021:groupl:extras:python:start [2023/01/05 14:38] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Python Code ====== | ====== Python Code ====== | ||
+ | |||
Python was used to parse the data received from the sensors. | Python was used to parse the data received from the sensors. | ||
+ | |||
+ | The below program was used to get a graph based on the values received from the sensor. The data was also saved in a csv format after. Data was then combined from all the locations and the pandas tool was used to find the mean value and the ratio of the mean vs the concentration of CO< | ||
+ | |||
+ | < | ||
<PHP> | <PHP> | ||
+ | # Importing library | ||
+ | import csv | ||
+ | import pandas as pd | ||
import serial | import serial | ||
import time | import time | ||
Line 8: | Line 16: | ||
# make sure the ' | # make sure the ' | ||
- | ser = serial.Serial(' | + | ser = serial.Serial(' |
time.sleep(2) | time.sleep(2) | ||
Line 28: | Line 36: | ||
plt.show() | plt.show() | ||
- | </ | ||
- | |||
- | <PHP> | ||
- | # Importing library | ||
- | import csv | ||
- | import pandas as pd | ||
CO2 = pd.DataFrame(data) #convert data to a pandas dataframe | CO2 = pd.DataFrame(data) #convert data to a pandas dataframe | ||
Line 42: | Line 44: | ||
CO2.to_csv(file, | CO2.to_csv(file, | ||
- | </ | + | #combining data taken from all three locations |
- | <PHP> | ||
- | #combining data taken from all three locations | ||
- | import pandas as pd | ||
L = pd.read_csv(' | L = pd.read_csv(' | ||
K = pd.read_csv(' | K = pd.read_csv(' | ||
B = pd.read_csv(' | B = pd.read_csv(' | ||
- | df = pd.concat([L, | + | df = pd.concat([L, |
- | </ | + | |
- | <PHP> | ||
# calculating the mean for each location | # calculating the mean for each location | ||
mean = df.mean() | mean = df.mean() | ||
Line 67: | Line 64: | ||
df.to_csv(file1, | df.to_csv(file1, | ||
</ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | The below program was used to get a graph based on the sound in decibels vs time. The data was received from the sensor LM393. | ||
+ | < | ||
+ | |||
+ | <PHP> | ||
+ | # Importing library | ||
+ | import csv | ||
+ | import pandas as pd | ||
+ | import serial | ||
+ | import time | ||
+ | import matplotlib.pyplot as plt | ||
+ | |||
+ | # make sure the ' | ||
+ | ser = serial.Serial(' | ||
+ | time.sleep(2) | ||
+ | |||
+ | data = [] | ||
+ | for i in range(100): | ||
+ | line = ser.readline() | ||
+ | if line: | ||
+ | string = line.decode() | ||
+ | num = float(string) # convert the unicode string to an int | ||
+ | num2 = int(num) | ||
+ | data.append(num2) # add int to data list | ||
+ | ser.close() | ||
+ | |||
+ | # build the plot | ||
+ | plt.plot(data) | ||
+ | plt.xlabel(' | ||
+ | plt.ylabel(' | ||
+ | plt.title(' | ||
+ | plt.show() | ||
+ | |||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | </ | ||
+ | [[amc2021: |
amc2021/groupl/extras/python/start.1630797273.txt.gz · Last modified: 2023/01/05 14:38 (external edit)