Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor
dataproduct1
dataproduct1

Code Block
languagepy
themeDJango
title1. Get all data products available with MATLAB .mat extension
collapsetrue
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

filters = {
    'extension': 'mat'    # mat - MATLAB
}
dataProducts = onc.getDataProducts(filters)
onc.print(dataProducts)


Link to this example

Anchor
dataproduct2
dataproduct2

Code Block
languagepy
themeDJango
title2. Download Time Series Scalar Data Product in CSV format for ADCP 2 MHZ
collapsetrue
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

filters = {
    'locationCode':'BACAX',
    'deviceCategoryCode':'ADCP2MHZ',
    'dataProductCode':'TSSD',
    'extension':'csv',
    'dateFrom':'2016-07-27T00:00:00.000Z',
    'dateTo':'2016-08-01T00:00:00.000Z',
    'dpo_qualityControl':1,
    'dpo_resample':'none',
    'dpo_dataGaps':0
}
results = onc.orderDataProduct(filters)
onc.print(results)


Link to this example

Anchor
dataproduct3
dataproduct3

Code Block
languagepy
themeDJango
title3. Download 6 months of hydrophone files, 1 hour at a time
collapsetrue
# If your data is in the ONC archive, the archive files example 7
# might be noticeably faster for downloading files

from datetime import datetime, timedelta
from dateutil.parser import parse
from time import sleep
from onc.onc import ONC

onc = ONC('YOUR_TOKEN')

# start and end date
dateFrom = parse('2019-01-01T00:00:00.000Z')
dateTo   = parse('2019-06-01T00:00:00.000Z')

# time to add to dateFrom
step = timedelta(hours=1)

# use a loop to download 1 hour at a time
while dateFrom < dateTo:
    txtDate = dateFrom.strftime("%Y-%m-%dT%H:%M:%S.000Z")
    print("\nDownloading data from: {:s}\n".format(txtDate))
    
    # Documentation on "diversion mode":
    # https://wiki.oceannetworks.ca/display/DP/Hydrophone+Data+Acquisition+and+Diversion+Mode
    filters = {
        'dataProductCode'   : 'AD',
        'locationCode'      : 'BACND',
        'deviceCategoryCode': 'HYDROPHONE',
        'dateFrom'          : txtDate,
        'dateTo'            : 'PT1H',
        'extension'         : 'mp3',     # Could be wav
        'dpo_hydrophoneDataDiversionMode': 'OD'
    }
    result = onc.orderDataProduct(filters, includeMetadataFile=False)

        dateFrom += step

   sleep(1)

print("\nFinished!")


Link to this example

Near real-time data examples

...

Anchor
archived1
archived1

Code Block
languagepy
themeDJango
title1. Get a list of ".ruv" archived files from a radar in one day
collapsetrue
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

filters = {
    'locationCode': 'VION',
    'deviceCategoryCode': 'OCEANOGRAPHICRADAR',
    'extension': 'ruv',
    'dateFrom': '2018-11-07T00:00:00.000Z',
    'dateTo': '2018-11-08T00:00:00.000Z'
}
results = onc.getListByLocation(filters)
onc.print(results)


Link to this example

Anchor
archived2
archived2

Code Block
languagepy
themeDJango
title2. Get a list of all archived files available in a device in one day
collapsetrue
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

filters = {
    'deviceCode':'RDIADCP600WH25471',    # AML CTD Metrec X 50348 in Burrard Inlet
    'dateFrom': '2019-06-07T00:00:00.000Z',
    'dateTo': '2019-06-08T00:00:00.000Z'
}
results = onc.getListByDevice(filters)
onc.print(results)


Link to this example

Anchor
archived3
archived3

Code Block
languagepy
themeDJango
title3. Download a file by its filename
collapsetrue
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

result = onc.getFile('BC_POD2_JB_20181107T000000.000Z.txt')
onc.print(result)


Link to this example

Anchor
archived4
archived4

Code Block
languagepy
themeDJango
title4. List .mp3 files from a hydrophone in the last 2 hours
collapsetrue
import datetime

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

# Get the current ISO8601 timestamp, without milliseconds
now = datetime.datetime.utcnow().replace(microsecond=0).isoformat() + '.000Z'

filters = {
    'locationCode': 'SEVIP',            # Strait of Georgia East
    'deviceCategoryCode': 'HYDROPHONE', # Hydrophones
    'dateFrom': '-PT2H',                # Minus 2 hours from dateTo
    'dateTo': now,
    'extension': 'mp3'                  # "mp3" files, could be "wav"
}

# list available files
result = onc.getListByDevice(filters)
onc.print(result)


Link to this example

Anchor
archived5
archived5

Code Block
languagepy
themeDJango
title5. Download all .mp3 files from a hydrophone in the last 2 hours
collapsetrue
import datetime

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

# Get the current ISO8601 timestamp, without milliseconds
now = datetime.datetime.utcnow().replace(microsecond=0).isoformat() + '.000Z'

filters = {
    'locationCode': 'SEVIP',            # Strait of Georgia East
    'deviceCategoryCode': 'HYDROPHONE', # Hydrophones
    'dateFrom': '-PT2H',                # Minus 2 hours from dateTo
    'dateTo': now,
    'extension': 'mp3'                  # "mp3" files, could be "wav"
}

# download available files (will skip existing files)
result = onc.getDirectFiles(filters)
onc.print(result)


Link to this example

Anchor
archived6
archived6

Code Block
languagepy
themeDJango
title6. Repeatedly download the latest .mp3 files from a hydrophone every 2 hours
collapsetrue
import datetime
import time

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

while True:
    # Get the current ISO8601 timestamp, without milliseconds
    now = datetime.datetime.utcnow().replace(microsecond=0).isoformat() + '.000Z'

    filters = {
        'locationCode': 'SEVIP',            # Strait of Georgia East
        'deviceCategoryCode': 'HYDROPHONE', # Hydrophones
        'dateFrom': '-PT2H',                # Minus 2 hours from dateTo
        'dateTo': now,
        'extension': 'mp3'                  # "mp3" files, could be "wav"
    }

    # download files found, skip existing files
    result = onc.getDirectFiles(filters)
    
    # wait 2 hours (7200 seconds)
    time.sleep(60 * 60 * 2)


Link to this example

Anchor
archived7
archived7

Code Block
languagepy
themeDJango
title7. Download 6 months of hydrophone files, 1 hour at a time
collapsetrue
from datetime import datetime, timedelta
from dateutil.parser import parse
from time import sleep
from onc.onc import ONC

onc = ONC('YOUR_TOKEN')

# start and end date
dateFrom = parse('2019-01-01T00:00:00.000Z')
dateTo   = parse('2019-06-01T00:00:00.000Z')

# time to add to dateFrom
step = timedelta(hours=1)

# use a loop to download 1 hour at a time
while dateFrom < dateTo:
    txtDate = dateFrom.strftime("%Y-%m-%dT%H:%M:%S.000Z")
    print("\nDownloading data from: {:s}\n".format(txtDate))
    
    filters = {
        'locationCode'      : 'BACND',
        'deviceCategoryCode': 'HYDROPHONE',
        'dateFrom'          : txtDate,
        'dateTo'            : 'PT1H',
        'extension'         : 'mp3',     # Could be wav
    }

    result = onc.getDirectFiles(filters)
    
    dateFrom += step

   sleep(1)

print("\nFinished!")


Link to this example