Skip to content

Instantly share code, notes, and snippets.

@adambard
Created October 10, 2013 17:05
Show Gist options
  • Save adambard/6921918 to your computer and use it in GitHub Desktop.
Save adambard/6921918 to your computer and use it in GitHub Desktop.
import csv
import numpy
with open("c46145.csv", "rb") as f:
r = csv.reader(f)
headers = r.next()
print headers
vwh_idx = headers.index('VWH$')
wspd_idx = headers.index('WSPD')
gspd_idx = headers.index('GSPD')
sstp_idx = headers.index('SSTP')
data = [(float(row[vwh_idx]),
float(row[wspd_idx]),
float(row[gspd_idx]),
float(row[sstp_idx]))
for row in r if row[vwh_idx] is not None and row[vwh_idx] != '']
data_headers = ['Significant Wave Height',
'Wind speed',
'Gust speed',
'Sea Surface Temperature']
data_with_headers = zip(data_headers, zip(*data))
# zip(*data) means unzip(data)
for name, dim in data_with_headers:
print name
print "Median: {}".format(numpy.median(dim))
print "Mean: {}".format(numpy.mean(dim))
print "Std: {}".format(numpy.std(dim))
print "---"
# Model response conditions
total = 0
no_response_possible = 0
for vwh, wspd, _, sstp in data:
if sstp < -3.:
continue # Assume nobody's operating in these conditions
total += 1
if vwh > 3.:
no_response_possible += 1
elif vwh > 1. and wspd > 10.:
no_response_possible += 1
elif wspd > 15.:
no_response_possible += 1
print "Total data points with sst > -3 C:", total
print "No response possible in", no_response_possible, "of them"
print "({0:.1f}%)".format(float(no_response_possible) / float(total) * 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment