-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Open-EO/danlooo/develop
Add process graph
- Loading branch information
Showing
12 changed files
with
267 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,16 @@ authors = ["Daniel Loos <[email protected]> and contributors"] | |
version = "1.0.0-DEV" | ||
|
||
[deps] | ||
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" | ||
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" | ||
Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b" | ||
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" | ||
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" | ||
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" | ||
|
||
[compat] | ||
DataFrames = "1" | ||
HTTP = "1" | ||
JSON3 = "1" | ||
StructTypes = "1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import StructTypes | ||
|
||
struct Collection | ||
stac_version::String | ||
stac_extensions::Vector{Any} | ||
type::String | ||
id::String | ||
title::String | ||
description::String | ||
license::String | ||
providers::Vector{Any} | ||
extent::Any | ||
links::Vector{Any} | ||
end | ||
StructTypes.StructType(::Type{Collection}) = StructTypes.Struct() | ||
|
||
function Base.show(io::IO, ::MIME"text/plain", c::Collection) | ||
println(io, "openEO Collection \"$(c.id)\"") | ||
print(io, c.description) | ||
end | ||
|
||
function Base.show(io::IO, ::MIME"text/plain", v::Vector{Collection}; n=10) | ||
println(io, "$(length(v))-element $(typeof(v)):") | ||
for c in first(v, n) | ||
println(io, " $(c.id): $(c.title)") | ||
end | ||
n < length(v) && print("⋮") | ||
end | ||
|
||
# @see https://earthengine.openeo.org/v1.0/collections | ||
struct CollectionsRoot | ||
collections::Vector{Collection} | ||
links::Vector{Any} | ||
end | ||
StructTypes.StructType(::Type{CollectionsRoot}) = StructTypes.Struct() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using OrderedCollections | ||
|
||
using Infiltrator | ||
|
||
function flatten!(g::AbstractProcessNode, root_id, nodes=Vector{ProcessNode}()) | ||
processes = filter(((k, v),) -> v isa ProcessNode, g.arguments) | ||
|
||
# post order tree traversal | ||
for (key, child) in processes | ||
flatten!(child, root_id, nodes) | ||
g.arguments[key] = ProcessNodeReference(child.id) | ||
end | ||
|
||
append!(nodes, [v for (k, v) in processes]) | ||
|
||
if g.id == root_id | ||
return vcat(nodes, [g]) | ||
end | ||
end | ||
|
||
function get_process_graph(process_call::ProcessNode) | ||
g = deepcopy(process_call) | ||
root_id = process_call.id | ||
processes = flatten!(g, root_id) | ||
|
||
res = OrderedDict() | ||
for p in processes | ||
id = p.id | ||
delete!(res, id) | ||
res[p.id] = p | ||
end | ||
|
||
l = last(res).second | ||
l = ProcessNode(l.id, l.process_id, l.arguments, true) | ||
res[l.id] = l | ||
|
||
return res | ||
end | ||
|
||
|
||
""" | ||
Process and download data synchronously | ||
""" | ||
function compute_result(connection::AbstractConnection, process_call::ProcessNode, filepath::String="", kw...) | ||
query = Dict( | ||
:process => Dict( | ||
:process_graph => get_process_graph(process_call), | ||
:parameters => [] | ||
) | ||
) | ||
|
||
headers = [ | ||
"Accept" => "*", | ||
"Content-Type" => "application/json" | ||
] | ||
|
||
response = fetchApi(connection, "result"; method="POST", headers=headers, body=JSON3.write(query)) | ||
|
||
if isempty(filepath) | ||
file_extension = split(Dict(response.headers)["Content-Type"], "/")[2] | ||
filepath = "out." * file_extension | ||
end | ||
|
||
write(open(filepath, "w"), response.body) | ||
return filepath | ||
end | ||
|
||
|
Oops, something went wrong.