Skip to content

Instantly share code, notes, and snippets.

@edzer
Created December 5, 2017 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edzer/4c45ae3d4438801ab95ae00bc3e42431 to your computer and use it in GitHub Desktop.
Save edzer/4c45ae3d4438801ab95ae00bc3e42431 to your computer and use it in GitHub Desktop.
openeo client draft
library(openeo) # make the openEO api functions available to the user
eo = openeo_connect("http://.../api/v0", user = "edzer", passwd = "****") # auth
# R6 object with reference semantics / encapsulated OOP
eo$datasets() # list/describe data sets available:
# Sentinel2A-L1C
# Proba-V
# ...
eo$processes() # list available processes
eo$data("Sentinel2A-L1C")
summary(eo$data)
# band 1: 443.9 nm, res: 60 m
# band 2: 496.6 nm, res: 10 m
# band 3: 560 nm, res: 10 m
# ...
# OK, so we have nir in 8 and red in 4
eo$filter_bbox()
# filter_bbox:
# - imagery: input imagery
# - left: left boundary
# - right: right boundary
# - top: top boundary
# - bottom: bottom boundary
# - srs: spatial ref sys
eo$filter_daterange()
# filter_daterange:
# - imagery: ...
# - from: ...
# - to: ...
eo$NDVI()
# NDVI:
# - imagery: ...
# - red: red band reference (number)
# - nir: nir band reference (number)
eo$min_time()
# min_time:
# - time_series: input time series
## OK, so we have all this! Let's do the job:
image = eo$open("Sentinel2A-L1C") # proxy object
summary(image)
# ... bounding box, time range, bands, ...
# nested function call:
#c4 = eo$min_time(
# eo$NDVI(
# eo$filter_daterange(
# eo$filter_bbox(image,
# left = 16.1, right = 16.6, top = 48.6, bottom = 47.9, srs = "EPSG:4326"),
# from = "2017-01-01", to = "2017-01-31"),
# red = 4, nir = 8)
#)
# or sequential:
c0 = eo$open("/Sentinel2A-L1C")
c1 = c0$filter_bbox(left = 16.1, right = 16.6, top = 48.6, bottom = 47.9, srs = "EPSG:4326")
c2 = c1$filter_daterange(from = "2017-01-01", to = "2017-01-31")
c3 = c2$NDVI(red = 4, nir = 8),
c4 = c3$min_time()
# or in a single call:
c4 = eo$open("/Sentinel2A-L1C")$filter_bbox(
left = 16.1, right = 16.6, top = 48.6, bottom = 47.9, srs = "EPSG:4326"
)$filter_daterange(from = "2017-01-01", to = "2017-01-31")$NDVI(
red = 4, nir = 8)$min_time()
# or more generically:
c4 = eo
$filter("/Sentinel2A-L1C")
$filter(st_bbox(minx = 16.1, maxx = 16.6, miny = 48.6, maxy = 47.9, srs = st_crs(4326)))
$filter(c(as.Date("2017-01-01"), as.Date("2017-01-31"))
$filter(bands = c("red", "nir"))
$map("bands", "/")
$map("time", "min")
# nothing is computed so far...
plot(c4$fetch_sample(1e6)) # will have like 1e6 pixels to show, not the whole scene;
# evaluates locally
# push job, compute remotely, download full result
plot(c4$fetch()) # full image (if held in memory)
fetch(c4$openeo, dst = "local_file.png") # if too large to handle in memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment