Skip to content

Commit

Permalink
Merge pull request #16 from Open-EO/tow_v1.0
Browse files Browse the repository at this point in the history
Tow v1.0
  • Loading branch information
claxn authored Jul 7, 2020
2 parents f948865 + 0a72683 commit 2d7cb7b
Show file tree
Hide file tree
Showing 160 changed files with 29,643 additions and 3,771 deletions.
Binary file added examples/s2_max_ndvi_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14,532 changes: 14,532 additions & 0 deletions examples/translate_graph.html

Large diffs are not rendered by default.

1,313 changes: 1,313 additions & 0 deletions examples/translate_graph.ipynb

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files

[metadata]
name = openeo-pg-parser-python
name = openeo-pg-parser
description = Add a short description here!
author = Luca Foresta
author-email = luca.foresta@eodc.eu
author = Luca Foresta, Claudio Navacchi
author-email = luca.foresta@eodc.eu, claudio.navacchi@geo.tuwien.ac.at
license = mit
url = https://pyscaffold.org/
long-description = file: README.rst
long-description = file: README.md
# Change if running only on Windows, Mac or Linux (comma-separated)
platforms = any
# Add here all kinds of additional classifiers as defined under
Expand All @@ -23,12 +23,14 @@ zip_safe = False
packages = find:
include_package_data = True
package_dir =
=src
= src
# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD!
setup_requires = pyscaffold>=3.1a0,<3.2a0
# Add here dependencies of your project (semicolon/line-separated), e.g.
# install_requires = numpy; scipy
install_requires = requests
install_requires =
numpy
requests
python-igraph
# The usage of test_requires is discouraged, see `Dependency Management` docs
# tests_require = pytest; pytest-cov
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
Expand All @@ -39,6 +41,9 @@ where = src
exclude =
tests

[options.package_data]
openeo_pg_parser = processes/*.json

[options.extras_require]
# Add here additional requirements for extra features, to install with:
# `pip install openeo_pg_parser_python[PDF]` like:
Expand Down Expand Up @@ -70,7 +75,7 @@ extras = True
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
# in order to write a coverage file that can be read by Jenkins.
addopts =
--cov openeo_pg_parser_python --cov-report term-missing
--cov openeo_pg_parser --cov-report term-missing
--verbose
norecursedirs =
dist
Expand Down Expand Up @@ -109,4 +114,4 @@ exclude =
# PyScaffold's parameters when the project was created.
# This will be used when updating. Do not change!
version = 3.1
package = openeo_pg_parser_python
package = openeo_pg_parser
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Setup file for openeo_pg_parser_python.
Setup file for openeo_pg_parser.
Use setup.cfg to configure your project.
This file was generated with PyScaffold 3.1.
Expand Down
File renamed without changes.
201 changes: 201 additions & 0 deletions src/openeo_pg_parser/definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import os
from json import load
from openeo_pg_parser.utils import load_processes
from openeo_pg_parser.utils import get_obj_elem_from_keys
from openeo_pg_parser.utils import walk_process_dictionary


class OpenEOProcess:
""" Class representing an OpenEO process definition. """
def __init__(self, process_def):
"""
Constructor of `OpenEOProcess` class.
Parameters
----------
process_def : dict
A dictionary defining an openEO process definition/schema.
"""
self.definition = process_def

@classmethod
def from_file(cls, filepath):
"""
Creates an `OpenEOProcess` instance from a process definition (JSON) file.
Parameters
----------
filepath : str
Full filepath to the process definition (JSON) file.
Returns
-------
OpenEOProcess
"""
if os.path.splitext(filepath)[1] != 'json':
err_msg = "The given file must be a json file."
raise IOError(err_msg)

process_def = load(filepath)
return cls(process_def)

@classmethod
def from_name(cls, name, src=None):
"""
Creates an `OpenEOProcess` instance from an process name/ID.
Parameters
----------
name : str
The name of the process, i.e. its ID.
src : dict or str or list, optional
It can be:
- dictionary of loaded process definitions (keys are the process ID's)
- directory path to processes (.json)
- URL of the remote process endpoint (e.g., "https://earthengine.openeo.org/v1.0/processes")
- list of loaded process definitions
Returns
-------
OpenEOProcess
"""

# use standard directory
if src is None:
src = os.path.join(os.path.dirname(__file__), "..", "..", "processes")

processes = load_processes(src)

if name not in processes.keys():
err_msg = "Process '{}' could not be found in the list of processes.".format(name)
raise ValueError(err_msg)
else:
return cls(processes[name])

@property
def id(self):
""" str : ID/name of the process. """
return self.definition['id']

@property
def description(self):
""" str : Description of the process. """
return self.definition.get('description')

@property
def parameters(self):
"""
dict : Dictionary containing the process argument names as keys and parameter definitions
(`OpenEOParameter` instances) as values.
"""
parameters = {}
for param_def in self.definition['parameters']:
parameter = OpenEOParameter(param_def)
parameters[parameter.name] = parameter

return parameters

@property
def sub_parameters(self):
"""
dict : Dictionary containing the process argument names as keys and parameter definitions
(`OpenEOParameter` instances) as values for sub-processes.
"""
sub_parameters = {}
for param_def in self.definition['parameters']:
parameter = OpenEOParameter(param_def)
keys_lineage, _, _, _ = walk_process_dictionary(parameter.schema)
keys_done = []
for key_lineage in keys_lineage:
if 'parameters' not in key_lineage: # continue if 'parameter' is not in the list of keys
continue
keys = key_lineage[:key_lineage.index('parameters')+1]
if keys in keys_done: # continue if the keys were already used
continue
keys_done.append(keys)
sub_param_defs = get_obj_elem_from_keys(parameter.schema, keys)
for sub_param_def in sub_param_defs:
sub_parameter = OpenEOParameter(sub_param_def)
sub_parameters.update({sub_parameter.name: sub_parameter})

return sub_parameters

@property
def is_reducer(self):
""" bool : Checks if the current process is a reducer or not. """
return self.definition.get("categories") is not None and "reducer" in self.definition["categories"]

@property
def returns(self):
""" dict : Returns 'return' schema of the process. """
return self.definition.get('returns')

@property
def exceptions(self):
""" dict : Returns 'exceptions' schema of the process. """
return self.definition.get('exceptions')

@property
def process_graph(self):
""" dict : Returns 'process_graph' schema of the process. """
return self.definition.get('process_graph')


class OpenEOParameter:
""" Class representing an OpenEO parameter definition. """

def __init__(self, param_def):
"""
Constructor of `OpenEOParameter` class.
Parameters
----------
param_def : dict
A dictionary defining an openEO parameter schema.
"""
self.definition = param_def

@property
def name(self):
""" str : Name of the parameter. """
return self.definition['name']

@property
def schema(self):
""" dict : Parameter schema. """
return self.definition['schema']

@property
def is_optional(self):
""" bool : Returns True if the parameter is optional. """
is_optional = self.definition.get('optional')
return is_optional if is_optional is not None else False

@property
def is_required(self):
""" bool : Returns True if the parameter is required. """
is_required = self.definition.get('required')
return is_required if is_required is not None else not self.is_optional

@property
def default_value(self):
""" object : Default value/s of the parameter. """
return self.definition.get('default')

def __str__(self):
"""
String representation of this class, i.e.,
the dictionary representation.
Returns
-------
str
"""
return str(self.definition)
Loading

0 comments on commit 2d7cb7b

Please sign in to comment.