Experimenting with GTS data from ERDDAP

Exploring use of Python to formulate ERDDAP image and data REST requests and process the responses.


In [2]:
from IPython.display import IFrame
IFrame('http://osmc.noaa.gov:8180/erddap/tabledap/OSMC_PROFILERS.html', width='100%', height=450)


Out[2]:

In [ ]:
##Initialize

In [12]:
import urllib2
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

In [2]:
# dictionary for valid parameter_name 
d={'sea_water_temperature':'ZTMP', 'sea_water_salinity':'ZSAL'}

In [3]:
# Specify variable to retrieve: 
param=d['sea_water_temperature']

# Get data shallower than this water depth:
depth_max = 10   

# Use ERDDAP's built-in relative time functionality to get last 48 hours:
start='now-24hours'
stop='now'
# or specify a specific period:
#start = '2013-05-06T00:00:00Z'
#stop =  '2013-05-07T00:00:00Z'

Retrieve an image from ERDDAP


In [8]:
# Construct URL for large PNG:
url='http://osmc.noaa.gov:8180/erddap/tabledap/OSMC_PROFILERS\
.largePng?longitude,latitude,observation_value\
&time>=%s&time<=%s&parameter_name="%s"&observation_depth<=%d&.trim=5&\
.draw=markers&.marker=5|6&.color=0x000000&.colorBar=|||||' % (start,stop,param,depth_max)

In [13]:
# Read the image
im = plt.imread(urllib2.urlopen(url),format='png')

In [14]:
# Display the image
plt.figure(figsize=(12,8))
plt.imshow(im)   
plt.axis('off');


Obtain data from ERDDAP


In [15]:
# Construct URL for CSV data:
url='http://osmc.noaa.gov:8180/erddap/tabledap/OSMC_PROFILERS\
.csv?time,longitude,latitude,observation_depth,observation_value\
&time>=%s&time<=%s&parameter_name="%s"&observation_depth<=%d' % (start,stop,param,depth_max)

In [16]:
# Load the CSV data directly into Pandas
df = pd.read_csv(url,index_col='time',parse_dates=True,skiprows=[1])  # skip the units row

In [17]:
# List last ten records
df.tail(10)


Out[17]:
longitude latitude observation_depth observation_value
time
2014-11-06 02:24:00 179.178 -62.022 5 1.31
2014-11-06 01:53:00 92.855 -1.442 8 29.11
2014-11-06 08:10:00 86.959 -16.316 8 26.40
2014-11-06 08:01:00 152.053 -54.500 10 2.55
2014-11-06 05:43:00 -64.692 19.006 6 28.99
2014-11-06 01:39:00 48.551 -22.353 8 25.59
2014-11-06 05:43:00 -64.692 19.006 10 28.99
2014-11-06 01:39:00 48.551 -22.353 4 25.59
2014-11-06 06:32:00 176.683 -48.347 6 8.97
2014-11-06 08:10:00 86.959 -16.316 4 26.49

In [18]:
df['longitude']


Out[18]:
time
2014-11-05 15:36:00    -33.033
2014-11-05 17:32:00    -16.342
2014-11-05 21:51:00    178.956
2014-11-05 17:32:00    -16.342
2014-11-05 15:36:00    -33.033
2014-11-05 21:51:00    178.956
2014-11-05 15:42:00    118.135
2014-11-05 15:36:00    -33.033
2014-11-05 15:36:00    -33.033
2014-11-05 15:36:00    -33.033
2014-11-05 21:51:00    178.956
2014-11-05 21:51:00    178.956
2014-11-05 14:13:00   -116.646
2014-11-05 14:13:00   -116.646
2014-11-05 14:13:00   -116.646
...
2014-11-06 02:24:00    179.178
2014-11-06 02:43:00    145.089
2014-11-06 01:43:00     52.932
2014-11-06 04:42:00    149.641
2014-11-06 00:45:00    -30.350
2014-11-06 02:24:00    179.178
2014-11-06 01:53:00     92.855
2014-11-06 08:10:00     86.959
2014-11-06 08:01:00    152.053
2014-11-06 05:43:00    -64.692
2014-11-06 01:39:00     48.551
2014-11-06 05:43:00    -64.692
2014-11-06 01:39:00     48.551
2014-11-06 06:32:00    176.683
2014-11-06 08:10:00     86.959
Name: longitude, Length: 496

In [19]:
df.plot()


Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f830d3d9490>

In [ ]: