Skip to content

Commit

Permalink
Merge rework of #128 and related tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Apr 3, 2020
2 parents cb717a0 + b874b30 commit e0aa3b5
Show file tree
Hide file tree
Showing 21 changed files with 2,647 additions and 1,432 deletions.
106 changes: 33 additions & 73 deletions examples/gee_example.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import openeo
from openeo.internal.graph_building import PGNode
import logging
import time
import json
from openeo.auth.auth_bearer import BearerAuth

logging.basicConfig(level=logging.INFO)


GEE_DRIVER_URL = "https://earthengine.openeo.org/v0.4"
GEE_DRIVER_URL = "https://earthengine.openeo.org/v1.0"

OUTPUT_FILE = "/tmp/openeo_gee_output.png"

user = "group1"
password = "test123"

#connect with GEE backend
#session = openeo.session("nobody", GEE_DRIVER_URL)

#TODO update example
con = openeo.connect(GEE_DRIVER_URL, auth_type=BearerAuth, auth_options={"username": user, "password": password})
# Connect to backend via basic authentication
con = openeo.connect(GEE_DRIVER_URL)
con.authenticate_basic(user, password)

#Test Connection
# Get information about the backend
print(con.list_processes())
print(con.list_collections())
print(con.describe_collection("COPERNICUS/S2"))


# Test Capabilities
cap = con.capabilities()

Expand All @@ -34,68 +29,33 @@
print(cap.currency())
print(cap.list_plans())

# Test Processes
datacube = con.load_collection("COPERNICUS/S2",
spatial_extent={"west": 16.138916, "south": 48.138600, "east": 16.524124, "north": 48.320647, "crs": "EPSG:4326"},
temporal_extent=["2017-01-01T00:00:00Z", "2017-01-31T23:59:59Z"],
bands=["B4", "B8"])

# Defining complex reducer
red = PGNode("array_element", arguments={"data": {"from_parameter": "data"}, "label": "B4"})
nir = PGNode("array_element", arguments={"data": {"from_parameter": "data"}, "label": "B8"})
ndvi = PGNode("normalized_difference", arguments={"x": {"from_node": nir}, "y": {"from_node": red}})

datacube = datacube.reduce_dimension(dimension="bands", reducer=ndvi)

datacube = con.imagecollection("COPERNICUS/S2")
datacube = datacube.filter_bbox(west=16.138916, south=48.138600, east=16.524124, north=48.320647, crs="EPSG:4326")
datacube = datacube.filter_daterange(extent=["2017-01-01T00:00:00Z", "2017-01-31T23:59:59Z"])
datacube = datacube.ndvi(nir="B4", red="B8A")
datacube = datacube.min_time()
print(json.dumps(datacube.graph, indent=2))

# Test Job

job = con.create_job(datacube.graph)
print(job.job_id)
print(job.start_job())
print (job.describe_job())
time.sleep(5)
job.download_results("/tmp/testfile")



# PoC JSON:
# {
# "process_graph":{
# "process_id":"stretch_colors",
# "args":{
# "imagery":{
# "process_id":"min_time",
# "args":{
# "imagery":{
# "process_id":"NDVI",
# "args":{
# "imagery":{
# "process_id":"filter_daterange",
# "args":{
# "imagery":{
# "process_id":"filter_bbox",
# "args":{
# "imagery":{
# "product_id":"COPERNICUS/S2"
# },
# "left":9.0,
# "right":9.1,
# "top":12.1,
# "bottom":12.0,
# "srs":"EPSG:4326"
# }
# },
# "from":"2017-01-01",
# "to":"2017-01-31"
# }
# },
# "red":"B4",
# "nir":"B8"
# }
# }
# }
# },
# "min": -1,
# "max": 1
# }
# },
# "output":{
# "format":"png"
# }
# }
datacube = datacube.min_time(dimension="t")

# defining linear scale range for apply process
lin_scale = PGNode("linear_scale_range", arguments={"x": {"from_parameter": "x"}, "inputMin": -1, "inputMax": 1, "outputMax": 255})

datacube = datacube.apply(lin_scale)
datacube = datacube.save_result(format="PNG")
print(json.dumps(datacube.graph, indent=2))

# Send Job to backend
job = datacube.send_job()
print(job.describe_job())

# Wait for job to finish and download
res = job.start_and_wait().download_results("/tmp")
print(res)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e0aa3b5

Please sign in to comment.