You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 29
Next »
Ocean Networks Canada now supports a growing number of datasets with OPeNDAP web services, via an ERDDAP web server.
Categories of datasets supported currently on the ERDDAP server can be viewed here.
See here, for more background information on ERDDAP, or watch a short video introduction (11 min)
Web Services
TableDap Data Service
All datasets that have a tabular format can be accessed using the tabledap protocol described here.
GridDap Data Service
All datasets that have a gridded format can be accessed using the griddap protocol described here.
RESTful Web Service
Data can be access using APIs described here.
getDapInstruments API service
This API service can be used to list the set of instruments and datasets supported by ONC OpeNDAP implementation.
Sample Scripts
Python
# This example script uses the "erddapy" python package to download data from ONC ERDDAP server.
# More information on how to use the erddapy package to download data using python: https://github.com/ioos/erddapy
# Installing erddapy in conda
# conda install --channel conda-forge erddapy
# Installing erddapy using pip
# pip install erddapy
from erddapy import ERDDAP
import pandas as pd
erddap_server = ERDDAP(
server='http://dap.onc.uvic.ca/erddap', # ONC ERDDAP server
)
# Fetch total number of datasets on the server
df = pd.read_csv(erddap_server.get_search_url(response='csv', search_for='all'))
print(
f'ONC currently hosts {len(set(df["tabledap"].dropna()))} '
f'tabledap, {len(set(df["griddap"].dropna()))} '
f'griddap, and {len(set(df["wms"].dropna()))} wms endpoints.'
)
# Searching for datasets
# The following parameter list will search for all datasets available between 2015 and 2017 with temperature as a variable.
params = {
'standard_name': 'temperature',
'min_time': '2015-01-01T00:00:00Z',
'max_time': '2017-12-31T00:00:00Z'
}
search_url = erddap_server.get_search_url(response='csv', **params)
print(pd.read_csv(search_url)['Dataset ID'].values)
# Fetch metadata of a particular dataset
metadata_url = erddap_server.get_info_url(dataset_id="scalar_1206500", response='csv')
metadata = pd.read_csv(metadata_url)
metadata.head()
# Fetch all data categories from the server
category_url = erddap_server.get_categorize_url(categorize_by='standard_name', response='csv')
pd.read_csv(category_url)['Category']
# Downloading a dataset
server_url = ERDDAP(
server='http://dap.onc.uvic.ca/erddap',
protocol='tabledap',
response='csv',
)
server_url.dataset_id = "scalar_118170"
server_url.constraints = {
'time>=': '2012-05-24T00:00:00Z',
'time<=': '2012-05-29T00:00:00Z'
}
server_url.variables = [
'latitude',
'longitude',
'temperature',
'time'
]
data_url = server_url.get_download_url()
df = server_url.to_pandas(
index_col='time (UTC)',
parse_dates=True,
).dropna()
df.head()
# To fetch all variables in a dataset, do not define the variable parameters for the url object
# Clear workspace before executing next code block
server_url = ERDDAP(
server='http://dap.onc.uvic.ca/erddap',
protocol='tabledap',
response='csv',
)
server_url.dataset_id = "scalar_118170"
server_url.constraints = {
'time>=': '2012-05-24T00:00:00Z',
'time<=': '2012-05-29T00:00:00Z'
}
data_url = server_url.get_download_url()
df = server_url.to_pandas(
index_col='time (UTC)',
parse_dates=True,
)
df.head()
# Plot data
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
fig, ax = plt.subplots(figsize=(17, 2))
cs = ax.scatter(df.index, df['temperature (K)'], s=1)
ax.invert_yaxis()
ax.set_xlim(df.index[0], df.index[-1])
xfmt = mdates.DateFormatter('%H:%Mh\n%d-%b')
ax.xaxis.set_major_formatter(xfmt)
ax.set_ylabel('Temperature ($^\circ$K)');
Matlab
% Load portion of dataset from ONC ERDDAP server load(urlwrite('http://dap.onc.uvic.ca/erddap/tabledap/SaanichInlet_BPS_WLFLNTU2474.mat?timeseries_id,profile_id,time,latitude,longitude,chlorophyll,turbidity,depth&time>=2015-01-02T00:00:00Z&time<=2015-01-03T00:00:00Z', 'test.mat'));
% Load metadata for dataset from ONC ERDDAP server and review portions of the response
load(urlwrite('http://dap.onc.uvic.ca/erddap/info/SaanichInlet_BPS_WLFLNTU2474/index.mat', 'meta.mat'));
response.Attribute_Name
for i=1:length(response.Attribute_Name)
if strcmp(strtrim(response.Attribute_Name(i,: - ) ),'deviceName')
response.Value(i,: - )
end
end
j=1;
for i=1:length(response.Attribute_Name)
if strcmp(strtrim(response.Attribute_Name(i,: -) ),'units')
units(j,: - ) =response.Value(i,: -) ;
j=j+1;
end
end
units
% Investigate some of the dataset contents
length(SaanichInlet_BPS_WLFLNTU2474.chlorophyll)
SaanichInlet_BPS_WLFLNTU2474.chlorophyll(1:10)
max(SaanichInlet_BPS_WLFLNTU2474.turbidity)
min(SaanichInlet_BPS_WLFLNTU2474.turbidity)
% Chlorophyll plots - vs time, depth and turbidity
plot(SaanichInlet_BPS_WLFLNTU2474.time, SaanichInlet_BPS_WLFLNTU2474.chlorophyll)
datetick
xlabel('Time')
ylabel('Chlorophyll')
plot(SaanichInlet_BPS_WLFLNTU2474.chlorophyll,SaanichInlet_BPS_WLFLNTU2474.depth,'.')
ylabel('Depth')
xlabel('Chlorophyll')
axis ij
scatter(SaanichInlet_BPS_WLFLNTU2474.chlorophyll, SaanichInlet_BPS_WLFLNTU2474.turbidity)
xlabel('Chlorphyll')
ylabel('Turbidity')
R
# This example script uses the "rerddap" R package to download data from ONC ERDDAP server.
# More information on how to use the erddapy package to download data using python: https://cran.r-project.org/web/packages/rerddap/rerddap.pdf
# Install packages
# install.packages("rerddap")
# install.packages("tidyverse")
library(rerddap)
library(tidyverse)
erddap_server <- "http://dap.onc.uvic.ca/erddap/"
all_datasets <- ed_datasets(which = "tabledap", url = erddap_server)
head(all_datasets)
# Get metadata of a particular dataset
info("scalar_118170", url = erddap_server)
# Download a subset of a dataset using different parameters
# Subset over time
data_susbet1 <- tabledap("scalar_118170", 'time>=2012-05-23', 'time<=2012-05-29', url = erddap_server)
# Subset by variable name
data_susbet2 <- tabledap("scalar_118170", fields = c("time", "temperature"),
'time>=2012-05-23', 'time<=2012-05-29', url = erddap_server)
# Download complete dataset with no filters
data <- tabledap("scalar_118170", url = erddap_server)
# Plot the data
# Convert to date time before plotting
data_subset2$date <- paste(substr(data_subset2$time,1,10),substr(data_subset2$time,12,19),sep=" ")
data_subset2$date <- as.POSIXct(data_subset2$date,format="%Y-%m-%d %H:%M:%S",tz="UTC")
with(data_subset2, plot(date, temperature, type = "l",
col = "blue", xlab = "Date", ylab = "Temperature (K)", xaxt = "n"))
axis(1, data_subset2$date, format(data_subset2$date, "%b %d"), cex.axis = .7)
Third-Party Resources
Excellent resource for explaining the NetCDF-CF-OPeNDAP framework and listing available tools: https://publicwiki.deltares.nl/display/OET/netCDF-CF-OPeNDAP