/
display.py
executable file
·60 lines (38 loc) · 1.49 KB
/
display.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
# Author = Joseph Cameron
# display.py displays raw data from the IDEAL dataset
# USAGE
# python display.py data.csv
# --------------------------------------------------
# IMPORT STATEMENTS
import pandas as pd
from datetime import datetime
import csv
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pickle
import sys
import glob
# --------------------------------------------------
# Files within this directory
files = sorted(glob.glob('*.csv'))
for f in files:
headers = ['Time', 'Sensor Value']
# Read .csv while getting rid of IDEAL data strings surrounding the data on the first and/or last rows
# Be careful with skiprows and skipfooter, maybe remove them
ideal_data = pd.read_csv(f, parse_dates = {"Datetime" : [0]}, names = headers, skiprows = 1, skipfooter = 1)
# Formatting dates
ideal_data['Time'] = ideal_data['Datetime'].map(lambda x: datetime.strptime(str(x), '%Y-%m-%d %H:%M:%S'))
# Plot
ideal_data.plot(x='Time', y='Sensor Value', style='.')
# Variable used to create pickles
#pickleVar = ideal_data
# Properly format the x-labels
plt.gcf().autofmt_xdate()
# Title
plt.title(f + " Data")
# Toggle comment if figure should be shown first
#plt.show()
# Saving Pickle for future interactivity in the 'Pickles' directory
#pickle.dump(pickleVar, file('Pickles/' + f + '_Figure.pickle','w'))
# Save Figure in the 'Figures' directory
plt.savefig('Figures/' + f + '_Figure.png', dpi=500)