Skip to content

Instantly share code, notes, and snippets.

@seumasmorrison
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seumasmorrison/02e9c18d2e1f289d3b1a to your computer and use it in GitHub Desktop.
Save seumasmorrison/02e9c18d2e1f289d3b1a to your computer and use it in GitHub Desktop.
Plotting Battery Status from Datawell waverider spt files using pandas
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