%matplotlib inline
import urllib, json
import pandas as pd

"""
Explanation: Some simple ERDDAP timing tests
Time how long it takes to get data via ERDDAP.  
Here we are using the IOOS NERACOOS ERDDAP service at http://www.neracoos.org/erddap.  
Lots of factors affect timing, as described at the end.  
But for these tests it's pretty darn speedy!
End of explanation
"""


url = 'http://www.neracoos.org/erddap/tabledap/B01_accelerometer_all.csv?time,significant_wave_height&time>"now-7days"'
print(url)

%%timeit
df_sb = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row 

df_sb = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row 
df_sb.plot(figsize=(12,4),grid='on');

"""
Explanation: Try CSV response for 1 week of accelerometer (wave) data from NERACOOS Buoy B off Portland, ME
End of explanation
"""


url = 'http://www.neracoos.org/erddap/tabledap/B01_accelerometer_all.csv?time,significant_wave_height&time>"now-365days"'
print(url)

%%timeit
df_sb = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row 

df_sb = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row 
df_sb.plot(figsize=(12,4),grid='on');

"""
Explanation: How about 1 year of data?
End of explanation
"""


url = 'http://www.neracoos.org/erddap/tabledap/B01_accelerometer_all.json?time,significant_wave_height&time>"now-7days"'
print(url)

%%timeit
response = urllib.urlopen(url)
data = json.loads(response.read())

response = urllib.urlopen(url)
data = json.loads(response.read())

data

"""
Explanation: Try JSON response -- might want to use this in a web app
End of explanation
"""


