You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

The ONC Python client library contains a number of classes and functions that make access to the ONC data, through the Oceans 2.0 API, quick and easy to use.

Installation

The ONC Python client library can be installed using the pip command found in the Scripts folder of your python install.

$ pip install onc

 

History

versionDateDescriptionPackage
1.06/9/2017Beta versiononc-1.0.tar.gz
1.16/12/2016Rename onc.dap.DAP class to onc.dap.ERDDAPonc-1.1.tar.gz
    

Classes

onc

Description

This Class provides

constructor

ONC(token, production=True, showInfo=False, outPath='c:/temp')

 

from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

 

 

 

from onc.onc import ONC

isProduction = True
showInfo = False
outPath = 'c:/ONC/Data'
onc = ONC('YOUR_TOKEN_HERE',isProduction,showInfo,outPath)

 

 

methods

getLocations(parameters)

  
  
  
  
Example - Print all locations in North East Pacific with Hydrophones deployed
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

locations = onc.getLocations({'locationCode':'NEP', 'deviceCategoryCode':'HYDROPHONE'}) #NEP - North East Pacific
print('Locations')

for location in locations:
    locationCode = location['locationCode']
    locationName = location['locationName']
    hasDeviceData = location['hasDeviceData']
    hasPropertyData = location['hasPropertyData']
    if (len(locationCode.split('.')) == 2):
        parentName = onc.getLocationName(locationCode.split('.')[0])
        if (parentName):
            locationName = '{} / {}'.format(parentName,locationName)
    print('  {0} - {1}'.format(locationCode,locationName))
    print('     Request data product using Device Category (Site Device): {}'.format(hasDeviceData))
    print('     Request data product using Property (Primary Sensor): {}'.format(hasPropertyData))
print('{} locations'.format(len(locations)))

 

getDevices(parameters)

 

Example - Print all devices deployed at Barkley Canyon - Axis, between June 1, 2016 and May 31, 2017
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

devices = onc.getDevices({'locationCode':'BACAX','begin':'2016-06-01T00:00:00.000Z','end':'2017-05-31T23:59:59.999Z'})  #BACAX - Barkley Canyon / Axis

print('Devices:')

for device in devices:
    deviceCode = device['deviceCode']
    deviceName = device['deviceName']
    print('  {} - {}'.format(deviceCode,deviceName))
print('{} devices'.format(len(devices)))

 

getDeviceCategories(parameters)

 

Example - Print all device categories available at Barkley Canyon - Upper Slope
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

deviceCategories = onc.getDeviceCategories({'locationCode':'NCBC'})    #NCBC - Barkely Canyon / Upper Slope

print('Device Categories:')

for deviceCategory in deviceCategories:
    deviceCategoryCode = deviceCategory['deviceCategoryCode']
    deviceCategoryName = deviceCategory['deviceCategoryName']
    print('  {} - {}'.format(deviceCategoryCode,deviceCategoryName))
print('{} device categories'.format(len(deviceCategories)))

 

getProperties(parameters)

 

Example - Print all properties that are available at Barkley Canyon - Axis
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

properties = onc.getProperties({'locationCode':'BACAX'})  #BACAX - Barkley Canyon / Axis

print('Properties:')

for prprty in properties:
    propertyCode = prprty['propertyCode']
    propertyName = prprty['propertyName']
    description = prprty['description']
    print('  {} - {} ({})'.format(propertyCode,propertyName,description))
print('{} properties'.format(len(properties)))

 

getDataProducts(parameters)

 

Example - Print all MatLab data product
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

dataProducts = onc.getDataProducts({'extension':'mat'}) #mat - MatLab


print('Data Products:')


for c in sorted(set([str(dp['dataProductCode']) for dp in dataProducts])):
    name = [dp['dataProductName'] for dp in dataProducts if dp['dataProductCode'] == c][0]
    print ('{} - {}'.format(c,name))
    for e in sorted(set([dp['extension'] for dp in dataProducts if dp['dataProductCode'] == c])):
        print('  {}'.format(e))
print('{} data product extensions'.format(len(dataProducts))) 

 

orderDataProduct

Example - Download Time Series Scalar Data Product in CSV format for ADCP 2 MHZ at Barkley Canyon - Axis
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

onc.orderDataProduct({'locationCode':'BACAX',
                        'deviceCategoryCode':'ADCP2MHZ',
                        'dataProductCode':'TSSD',
                        'extension':'csv',
                        'begin':'2016-07-27T00:00:00.000Z',
                        'end':'2016-08-01T00:00:00.000Z',
                        'dpo_qualityControl':1,
                        'dpo_resample':'none',
                        'dpo_dataGaps':0},100)

 

requestDataProduct

runDataProduct

downloadDataProduct

downloadDataProductIndex

downloadFile

getJsonDataProduct

getJsonFromUrl

getDataProductUrls

 

 

  • No labels