This example creates a request for a Time Series Scalar Data data product for the Barkley Canyon / Axis (POD 1) 150 kHz ADCP and returns information about the request. The returns a Request Id, which can be used to run the data product. Code Block |
---|
language | py |
---|
title | Python 3.x |
---|
linenumbers | true |
---|
| import requests
import json
url = 'https://data.oceannetworks.ca/api/dataProductDelivery'
parameters = {'method':'request',
'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
'locationCode':'BACAX', # Barkley Canyon / Axis (POD 1)
'deviceCategoryCode':'ADCP2MHZ', # 150 kHz Acoustic Doppler Current Profiler
'dataProductCode':'TSSD', # Time Series Scalar Data
'extension':'csv', # Comma Separated spreadsheet file
'begin':'2016-07-27T00:00:00.000Z', # The datetime of the first data point (From Date)
'end':'2016-08-01T00:00:00.000Z', # The datetime of the last data point (To Date)
'dpo_qualityControl':1, # The Quality Control data product option - See https://wiki.oceannetworks.ca/display/DP/1
'dpo_resample':'none', # The Resampling data product option - See https://wiki.oceannetworks.ca/display/DP/1
'dpo_dataGaps':0} # The Data Gaps data product option - See https://wiki.oceannetworks.ca/display/DP/1
response = requests.get(url,params=parameters)
if (response.ok):
requestInfo = json.loads(str(response.content,'utf-8')) # convert the json response to an object
print('Request Id: {}'.format(requestInfo['dpRequestId'])) # Print the Request Id
if ('numFiles' in requestInfo.keys()):
print('File Count: {}'.format(requestInfo['numFiles'])) # Print the Estimated File Size
if ('fileSize' in requestInfo.keys()):
print('File Size: {}'.format(requestInfo['fileSize'])) # Print the Estimated File Size
if 'downloadTimes' in requestInfo.keys():
print('Estimated download time:')
for e in sorted(requestInfo['downloadTimes'].items(),key=lambda t: t[1]):
print(' {} - {} sec'.format(e[0],'{:0.2f}'.format(e[1])))
if 'estimatedFileSize' in requestInfo.keys():
print('Estimated File Size: {}'.format(requestInfo['estimatedFileSize']))
if 'estimatedProcessingTime' in requestInfo.keys():
print('Estimated Processing Time: {}'.format(requestInfo['estimatedProcessingTime']))
else:
if(response.status_code == 400):
error = json.loads(str(response.content,'utf-8'))
print(error) # json response contains a list of errors, with an errorMessage and parameter
else:
print ('Error {} - {}'.format(response.status_code,response.reason)) |
Code Block |
---|
language | py |
---|
title | Python 2.x |
---|
linenumbers | true |
---|
collapse | true |
---|
| import requests
import json
url = 'https://data.oceannetworks.ca/api/dataProductDelivery'
parameters = {'method':'request',
'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
'locationCode':'BACAX', # Barkley Canyon / Axis (POD 1)
'deviceCategoryCode':'ADCP2MHZ', # 150 kHz Acoustic Doppler Current Profiler
'dataProductCode':'TSSD', # Time Series Scalar Data
'extension':'csv', # Comma Separated spreadsheet file
'begin':'2016-07-27T00:00:00.000Z', # The datetime of the first data point (From Date)
'end':'2016-08-01T00:00:00.000Z', # The datetime of the last data point (To Date)
'dpo_qualityControl':1, # The Quality Control data product option - See https://wiki.oceannetworks.ca/display/DP/1
'dpo_resample':'none', # The Resampling data product option - See https://wiki.oceannetworks.ca/display/DP/1
'dpo_dataGaps':0} # The Data Gaps data product option - See https://wiki.oceannetworks.ca/display/DP/1
response = requests.get(url,params=parameters)
if (response.ok):
requestInfo = json.loads(str(response.content)) # convert the json response to an object
print('Request Id: {}'.format(requestInfo['dpRequestId'])) # Print the Request Id
if ('numFiles' in requestInfo.keys()):
print('File Count: {}'.format(requestInfo['numFiles'])) # Print the Estimated File Size
if ('fileSize' in requestInfo.keys()):
print('File Size: {}'.format(requestInfo['fileSize'])) # Print the Estimated File Size
if 'downloadTimes' in requestInfo.keys():
print('Estimated download time:')
for e in sorted(requestInfo['downloadTimes'].items(),key=lambda t: t[1]):
print(' {} - {} sec'.format(e[0],'{:0.2f}'.format(e[1])))
if 'estimatedFileSize' in requestInfo.keys():
print('Estimated File Size: {}'.format(requestInfo['estimatedFileSize']))
if 'estimatedProcessingTime' in requestInfo.keys():
print('Estimated Processing Time: {}'.format(requestInfo['estimatedProcessingTime']))
else:
if(response.status_code == 400):
error = json.loads(str(response.content))
print(error) # json response contains a list of errors, with an errorMessage and parameter
else:
print ('Error {} - {}'.format(response.status_code,response.reason)) |
Code Block |
---|
theme | Confluence |
---|
language | erl |
---|
title | MATLAB |
---|
linenumbers | true |
---|
| url = ['https://data.oceannetworks.ca/api/dataProductDelivery', ...
'?method=request' ...
'&token=YOUR_TOKEN_HERE' ... % replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
'&locationCode=BACAX' ... % Barkley Canyon / Axis (POD 1)
'&deviceCategoryCode=ADCP2MHZ' ... % 150 kHz Acoustic Doppler Current Profiler
'&dataProductCode=TSSD' ... % Time Series Scalar Data
'&extension=csv' ... % Comma Separated spreadsheet file
'&begin=2016-07-27T00:00:00.000Z' ... % The datetime of the first data point (From Date)
'&end=2016-08-01T00:00:00.000Z' ... % The datetime of the last data point (To Date)
'&dpo_qualityControl=1' ... % The Quality Control data product option - See https://wiki.oceannetworks.ca/display/DP/1
'&dpo_resample=none' ... % The Resampling data product option - See https://wiki.oceannetworks.ca/display/DP/1
'&dpo_dataGaps=0']; % The Data Gaps data product option - See https://wiki.oceannetworks.ca/display/DP/1
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);
response = send(request,uri,options);
if (response.StatusCode == 200) % HTTP Status - OK
requestInfo = response.Body.Data;
disp(requestInfo)
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
disp(response.Body.Data.errors);
else % all other HTTP Statuses
disp(char(response.StatusLine));
end |
Code Block |
---|
| library(httr)
r <- GET("https://data.oceannetworks.ca/api/dataProductDelivery",
query = list(method="request",
token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
locationCode="BACAX", #>Barkley Canyon / Axis (POD 1)
deviceCategoryCode="ADCP2MHZ", #>150 kHz Acoustic Doppler Current Profiler
dataProductCode="TSSD", #>Time Series Scalar Data
extension="csv", #>Comma Separated spreadsheet file
begin="2016-07-27T00:00:00.000Z", #>The datetime of the first data point (From Date)
end="2016-08-01T00:00:00.000Z", #>The datetime of the last data point (To Date)
dpo_qualityControl=1, #>The Quality Control data product option - See https://wiki.oceannetworks.ca/display/DP/1
dpo_resample="none", #>The Resampling data product option - See https://wiki.oceannetworks.ca/display/DP/1
dpo_dataGaps=0)) #>The Data Gaps data product option - See https://wiki.oceannetworks.ca/display/DP/1
if (http_error(r)) {
if (r$status_code == 400){
error = content(r)
str(error)
} else {
str(http_status(r)$message)
}
} else {
requestInfo = content(r)
str(requestInfo)
} |
|