Created
January 1, 2011 01:14
-
-
Save bmander/761474 to your computer and use it in GitHub Desktop.
calculate total energy accumulation from insolation measurements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wow. energy. | |
# | |
# grab source data from http://www-k12.atmos.washington.edu/k12/grayskies/nw_weather.html | |
import csv | |
from datetime import datetime, timedelta | |
MINS_IN_DAY=1440 | |
fp = open( "LFEM_data-.csv" ) | |
rd = csv.reader( fp ) | |
# skip the header | |
rd.next() | |
day_totals = {} | |
for i, (julain,reading_datetime_str,solar_str) in enumerate(rd): | |
if i%MINS_IN_DAY==0: | |
print i//MINS_IN_DAY | |
try: | |
solar = float(solar_str) | |
reading_dt = datetime.strptime(reading_datetime_str, "%Y-%m-%d %H:%M")-timedelta(hours=8) | |
except ValueError, e: | |
continue | |
day = (reading_dt.year,reading_dt.month,reading_dt.day) | |
day_totals[day] = day_totals.get(day,0) + solar*60 | |
day_totals = sorted( day_totals.items(), key=lambda x:x[0] ) | |
fp = open( "totals.csv", "w" ) | |
for day,total in day_totals: | |
day_of_year = datetime(*day).strftime("%j") | |
fp.write( "%s,%s,%s\n"%(day_of_year,"%s-%s-%s"%day, total) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment