Last active
August 29, 2015 14:06
-
-
Save seumasmorrison/02e9c18d2e1f289d3b1a to your computer and use it in GitHub Desktop.
Plotting Battery Status from Datawell waverider spt files using pandas
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
import os | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
fig = plt.figure(figsize=(20,10), dpi=100) | |
from datetime import datetime | |
os.chdir('/path/to/buoy_name/year/') | |
date_index = [] | |
battery_status = [] | |
months = os.listdir('.') | |
for month in months: | |
try: | |
os.chdir(month) | |
dir_listing = os.listdir('.') | |
for file_name in dir_listing: | |
if '$' not in file_name: | |
if file_name.endswith('.spt'): | |
date_index.append(datetime.strptime(file_name.split('}')[1][:-4], '%Y-%m-%dT%Hh%MZ')) | |
battery_status.append(int(open(file_name).readlines()[6:7][0].strip())) | |
os.chdir('..') | |
except: | |
print "problem" | |
battery_status_df = pd.DataFrame(battery_status, columns = ['battery_staus'], index=date_index) | |
battery_status_df.plot() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment