In [1]:
# Make it so notebook knows how to access ooitk from the notebook dir
import sys
import os
sys.path.append(os.path.dirname(os.getcwd()))
In [2]:
# Make a new session to localhost and point it to the service gateway
from ooitk.session import Session
session = Session('localhost', 5000)
In [9]:
# Make a new catalog instance
from ooitk.data_catalog import DataProductCatalog
catalog = DataProductCatalog(session)
In [10]:
# Find all the data products that have 'ctd' in the name
relevant_data_products = catalog.find_data_product('ctd')
In [11]:
# Fetch a DAP dataset for the first one
dap_dataset = catalog.download(relevant_data_products[0]['_id'])
In [12]:
# Get time, time is a dimension variable so it's really simple to get
time = dap_dataset['time'][:]
# Get temp, temp is a gridded variable so it needs to baccessed like this
temp = dap_dataset['temp']['temp'][:][0]
In [13]:
# Plot it in pyplot
plt.plot(time,temp)
Out[13]:
In [18]:
erddap_url = 'http://erddap-test.oceanobservatories.org:8080/erddap/tabledap/e1fd3967aa55475e8338fc36a6493f5c'
nc_url = erddap_url + '.nc?&orderBy%28%22time%22%29'
from tempfile import gettempdir
import os
import requests
def scrape(url):
tmpfile = os.path.join(gettempdir(), 'cache.nc')
r = requests.get(url)
chunk_size = 4096
with open(tmpfile, 'wb') as fd:
for chunk in r.iter_content(chunk_size):
fd.write(chunk)
return tmpfile
In [19]:
fname = scrape(nc_url)
In [21]:
from netCDF4 import Dataset
nc = Dataset(fname)
In [25]:
t = nc.variables['time'][:]
temp = nc.variables['sci_water_temp'][:]
In [24]:
nc.variables
Out[24]:
In [ ]: