-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_stats.py
More file actions
75 lines (58 loc) · 2.33 KB
/
Copy pathdump_stats.py
File metadata and controls
75 lines (58 loc) · 2.33 KB
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
import os
import csv
from dateutil import parser
from skyrec.processing import Image
observed_okta = {}
with open('contrib/data.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
wd = parser.parse(row['timestamp']).strftime('%Y%m%d_%H')
observed_okta[wd] = row['observed']
basedir = '/lustre/storeB/users/thomasn/webcams/cropped'
txt_file = open('extracted_features.txt', 'w')
txt_file.write("filename,msat,vsat,mbr,vbr,bf,gf,observed\n")
html_file = open('raw_values.html', 'w')
html_file.write("<html><body><table border = \"1\">")
html_file.write("""
<tr>
<th>Image</th>
<th>Saturation (mean)</th>
<th>Saturation (var)</th>
<th>Brightness (mean)</th>
<th>Brightness (var)</th>
<th>Blue Fraction</th>
<th>Grey Fraction</th>
<th>Observed okta</th>
</tr>""")
def write_txt_row(iname, oo, sm, sv, bm, bv, bf, gf):
txt_file.write("%s, %.5f, %.1f, %.5f, %.1f, %.5f, %.5f, %s\n" % (iname, sm, sv, bm, bv, bf, gf, oo))
def write_html_row(ip, oo, sm, sv, bm, bv, bf, gf):
color = "#FFFFFF"
if (im.brightness['mean'] < 0.4):
color = "#FF0000"
html_file.write("<tr bgcolor=\"%s\">\n" % color)
html_file.write("<td><img src=\"%s\" style=\"width:400px\"</td>\n" % ip)
html_file.write("<td>%.5f</td>\n" % sm)
html_file.write("<td>%.1f</td>\n" % sv)
html_file.write("<td>%.5f</td>\n" % bm)
html_file.write("<td>%.1f</td>\n" % bv)
html_file.write("<td>%.5f</td>\n" % bf)
html_file.write("<td>%.5f</td>\n" % gf)
html_file.write("<td>%s</td>\n" % oo)
html_file.write("</tr>\n")
for image_name in os.listdir(basedir):
if image_name.endswith(".jpg"):
try:
oo = observed_okta[image_name[:11]]
except:
oo = ''
image_path = os.path.join(basedir, image_name)
with open(image_path, 'rb') as image_buffer:
im = Image(image_buffer)
im.process()
write_html_row(image_path, oo, im.saturation['mean'], im.saturation['var'], im.brightness['mean'], im.brightness['var'], im.blue_fraction, im.grey_fraction)
write_txt_row(image_name, oo, im.saturation['mean'], im.saturation['var'], im.brightness['mean'], im.brightness['var'], im.blue_fraction, im.grey_fraction)
html_file.write("</table></body></html>\n")
html_file.close()
txt_file.write("\n")
txt_file.close()