<jupyter_start><jupyter_text>Tide Prediction TaskStart with some imports.<jupyter_code>from gbdxtools import Interface
from shapely.wkt import loads
import dateutil.parser
from datetime import datetime<jupyter_output><empty_output><jupyter_text>Create a GBDX interface.<jupyter_code>gbdx = Interface()<jupyter_output><empty_output><jupyter_text>Start with a catalog ID (this is some image of the Palm Islands in Dubai).<jupyter_code>cat_id = '103001000349F800'<jupyter_output><empty_output><jupyter_text>Get metadata record for parsing of footprint WKT and timestamp.<jupyter_code>record = gbdx.catalog.get(cat_id)<jupyter_output><empty_output><jupyter_text>Get the centroid of the footprint.<jupyter_code>centroid = loads(record.get('properties').get('footprintWkt')).centroid<jupyter_output><empty_output><jupyter_text>The latitude corresponds to `y` and longitude corresponds to `x`.<jupyter_code>lat = centroid.y
lon = centroid.x
print('lat=%f, lon=%f' % (lat, lon))<jupyter_output>lat=25.113527, lon=55.133696<jupyter_text>Next, we get the timestamp of the image.<jupyter_code>timestamp = dateutil.parser.parse(record.get('properties').get('timestamp'))<jupyter_output><empty_output><jupyter_text>The timestamp is converted to the date time group format that the tide prediction algorithm expects (Y-m-d-H-M).<jupyter_code>dtg = datetime.strftime(timestamp, '%Y-%m-%d-%H-%M')
print('dtg="%s"' % dtg)<jupyter_output>dtg="2010-01-12-07-12"<jupyter_text>At this point, we'd like to call the task with<jupyter_code>print('lat="%s", lon="%s", dtg="%s"' % (str(lat), str(lon), dtg))<jupyter_output>lat="25.1135269383", lon="55.1336961813", dtg="2010-01-12-07-12"<jupyter_text>and receive an output like```json{  "minimumTide24Hours":null,  "maximumTide24Hours":null,  "currentTide":null}``` We have currently implemented tide prediction using a modified version of bf-tideprediction (just without the flask wrapper for endpoints). The image `chambbj/hello-gbdx` v0.0.9 is available as GBDX task `hello-gbdx-chambbj`. It takes the aforementioned lat, lon, dtg all as strings.<jupyter_code>aoptask = gbdx.Task('AOP_Strip_Processor',
                 data=gbdx.catalog.get_data_location(cat_id),
                 bands='MS',
                 enable_dra=False,
                 enable_pansharpen=False,
                 enable_acomp=True,
                 ortho_epsg='UTM')

tide_task = gbdx.Task('ShorelineDetection',
                      lat = str(lat),
                      lon = str(lon),
                      dtg = dtg,
                      image = aoptask.outputs.data.value)<jupyter_output><empty_output><jupyter_text>The tide prediction json file will be saved to `/mnt/work/output/json` and is persisted to `some_new_folder` within my user bucket/prefix on S3.<jupyter_code>import uuid
from os.path import join
workflow = gbdx.Workflow([aoptask, tide_task])
random_str = str(uuid.uuid4())
workflow.savedata(tide_task.outputs.results, location=join('some_random_folder', random_str))
workflow.execute()
workflow.status<jupyter_output><empty_output><jupyter_text>Check periodically for status `complete`.<jupyter_code>import time
import sys
from __future__ import print_function
while not workflow.status.get('state') == u'complete':
    print(datetime.now(), workflow.status, end='\r')
    sys.stdout.flush()
    time.sleep(5.0)
workflow.status<jupyter_output>2017-06-20 14:16:01.481899 {u'state': u'running', u'event': u'started'}'}<jupyter_text>And download the result. Yes, we could display it here, but this is good enough.<jupyter_code>gbdx.s3.download(join('some_random_folder', random_str))<jupyter_output><empty_output><jupyter_text>The tides.json file is now in the local directory.<jupyter_code>print(join('some_random_folder', random_str))
workflow.events
workflow.stdout<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup