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])
def validate_processes(process_graph, processes_src): """ Validate the input process graph according to the given list of processes. Parameters ---------- process_graph : graph.Graph Traversable Python process graph. processes_src : dict or str or list 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 ------- valid : bool If True, the given process graph is valid with respect to the given process definitions. err_msgs : list List of strings containing error or user information messages if `valid` is False. """ process_defs = load_processes(processes_src) err_msgs = [] for node in process_graph.nodes: if node.process_id not in process_defs.keys(): err_msg = "'{}' is not in the current set of process definitions.".format( node.process_id) err_msgs.append(err_msg) else: # First, check if required parameter is set in the process graph for parameter in node.process.parameters.values(): if not parameter.is_required: if parameter.name not in node.arguments.keys(): err_msg = "Parameter '{}' is required for process '{}'".format( parameter.name, node.process_id) err_msgs.append(err_msg) valid = len(err_msgs) == 0 return valid, err_msgs
def walk_process_graph(process_graph, nodes, process_defs, node_ids=None, level=0, keys=None): """ Recursively walks through an openEO process graph dictionary and transforms the dictionary into a list of graph nodes. Parameters ---------- process_graph : dict Dictionary to walk through. nodes : collections.OrderedDict Ordered dictionary containing the node IDs as keys and the `graph.Node` instances as values. process_defs : dict or str or list 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 node_ids : list, optional List of Node ID's for one dictionary branch (only internally used in the recursive process, can be ignored) level : int, optional Current level/deepness in the dictionary (default is 0, only internally used in the recursive process, can be ignored). keys : list of str List of process graph dictionary keys pointing to the current node. Returns ------- nodes : collections.OrderedDict node_ids : list level : int keys : list of str """ process_defs = load_processes(process_defs) if keys is None: keys = [] for key, value in process_graph.items(): if isinstance(value, dict): keys = copy.deepcopy(keys) keys.append(key) if "process_id" in value.keys(): # process node found node_counter = len(nodes) node_id = "_".join([key, str(node_counter)]) node = OpenEONode(id=node_id, name=key, content=value, edges=[], depth=level, processes_src=process_defs) node.keys = keys if node_ids: filtered_node_ids = [prev_node_id for prev_node_id in node_ids if prev_node_id] parent_node_id = filtered_node_ids[-1] parent_node = nodes[parent_node_id] create_edge(node, parent_node, name="callback") # overwrite depth using parent information node.depth = parent_node.depth + 1 nodes[node_id] = node else: node_id = None if node_ids is None: node_ids = [] node_ids.append(node_id) level += 1 nodes, node_ids, level, keys = walk_process_graph(value, nodes, process_defs, node_ids=node_ids, level=level, keys=keys) level += -1 if node_ids: node_ids = node_ids[:-1] if keys: keys = keys[:-1] return nodes, node_ids, level, keys