def get_process_list(args): """Analyse the process description and return the GRaaS process chain and the name of the processing result :param args: The process description :return: (output_name, pc) """ input_names, process_list = process_definitions.analyse_process_graph(args) output_names = [] for input_name in input_names: # Create the output name based on the input name and method output_name = input_name output_names.append(output_name) left = args["left"] right = args["right"] top = args["top"] bottom = args["bottom"] ewres = args["ewres"] nsres = args["nsres"] if "srs" in args: print("SRS is currently not supported") pc = create_graas_process_chain_entry(left=left, right=right, top=top, bottom=bottom, ewres=ewres, nsres=nsres) process_list.append(pc) return output_names, process_list
def test_ndvi(self): graph = { "process_graph": { "process_id": "NDVI", "args": { "collections": [{ "product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B04" }, { "product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B08" }], "red": "S2A_B04", "nir": "S2A_B08" } } } names, pc = analyse_process_graph(graph=graph) pprint(names) pprint(pc) self.assertEqual(names[0], "S2A_B08_NDVI") self.assertEqual(len(pc), 2)
def get_process_list(args): """Analyse the process description and return the GRaaS process chain and the name of the processing result strds that was filtered by start and end date :param args: The process description :return: (output_name, pc) """ # Get the input description and the process chain to attach this process input_names, process_list = process_definitions.analyse_process_graph(args) output_names = [] for input_name in input_names: location, mapset, datatype, layer_name = GRaaSInterface.layer_def_to_components( input_name) output_name = "%s_%s" % (layer_name, PROCESS_NAME) output_names.append(output_name) start_time = None end_time = None if "from" in args: start_time = args["from"] if "to" in args: end_time = args["to"] pc = create_graas_process_chain_entry(input_name=input_name, start_time=start_time, end_time=end_time, output_name=output_name) process_list.append(pc) return output_names, process_list
def get_process_list(args): """Analyse the process description and return the GRaaS process chain and the name of the processing result layer which is a single raster layer :param args: The process description :return: (output_name, pc) """ # Get the input description and the process chain to attach this process input_names, process_list = process_definitions.analyse_process_graph(args) output_names = [] for input_name in input_names: location, mapset, datatype, layer_name = GRaaSInterface.layer_def_to_components( input_name) output_name = "%s_%s" % (layer_name, PROCESS_NAME) output_names.append(output_name) if "python_file_url" in args: python_file_url = args["python_file_url"] else: raise Exception("Python fle is missing in the process description") pc = create_graas_process_chain_entry(input_name=input_name, python_file_url=python_file_url, output_name=output_name) process_list.append(pc) return output_names, process_list
def get_process_list(args): """Analyse the process description and return the GRaaS process chain and the name of the processing result layer which is a single raster layer :param args: The process description :return: (output_name, pc) """ # Get the input description and the process chain to attach this process input_names, process_list = process_definitions.analyse_process_graph(args) output_names = [] for input_name in input_names: output_name = input_name output_names.append(output_name) if "regions" in args: regions = args["regions"] else: raise Exception( "The vector polygon is missing in the process description") pc = create_graas_process_chain_entry(input_name=input_name, regions=regions) process_list.extend(pc) return output_names, process_list
def test_ndvi_export(self): graph = { "process_graph": { "process_id": "raster_exporter", "args": { "collections": [{ "product_id": "LL.sentinel2A_openeo_subset.raster.S2A_MSIL1C_20170412T110621_N0204_R137_T30SUJ_20170412T111708_B04" }, { "product_id": "LL.sentinel2A_openeo_subset.raster.S2A_MSIL1C_20170412T110621_N0204_R137_T30SUJ_20170412T111708_B08" }] } } } names, pc = analyse_process_graph(graph=graph) pprint(names) pprint(pc) self.assertEqual( names[0], "LL.sentinel2A_openeo_subset.raster.S2A_MSIL1C_20170412T110621_N0204_R137_T30SUJ_20170412T111708_B04" ) self.assertEqual( names[1], "LL.sentinel2A_openeo_subset.raster.S2A_MSIL1C_20170412T110621_N0204_R137_T30SUJ_20170412T111708_B08" ) self.assertEqual(len(pc), 2)
def test_filter_bbox(self): graph = { "process_graph": { "process_id": "filter_bbox", "args": { "collections": [{ "product_id": "ECAD.PERMANENT.strds.temperature_mean_1950_2013_yearly_celsius" }], "left": -40.5, "right": 75.5, "top": 75.5, "bottom": 25.25, "ewres": 0.1, "nsres": 0.1, } } } name, pc = analyse_process_graph(graph=graph) pprint(name) pprint(pc) self.assertEqual(len(pc), 1) for entry in pc: self.assertTrue(entry["module"] == "g.region")
def test_daterange(self): graph = { "process_graph": { "process_id": "filter_daterange", "args": { "collections": [{ "product_id": "ECAD.PERMANENT.strds.temperature_mean_1950_2013_yearly_celsius" }], "from": "2001-01-01", "to": "2005-01-01" } } } name, pc = analyse_process_graph(graph=graph) pprint(name) pprint(pc) self.assertEqual(len(pc), 1) for entry in pc: self.assertTrue(entry["module"] == "t.rast.extract")
def test_ndvi_error(self): graph = { "process_graph": { "process_id": "NDVI_nope", "args": { "collections": [{ "product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B04" }, { "product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B08" }], "red": "S2A_B04", "nir": "S2A_B08" } } } try: names, pc = analyse_process_graph(graph=graph) pprint(names) pprint(pc) self.assertTrue(False) except: pass
def test_zonal_statistics(self): graph = { "process_graph": { "process_id": "zonal_statistics", "args": { "collections": [{ "product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B04" }, { "product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B08" }], "regions": "https://storage.googleapis.com/graas-geodata/roi_openeo_use_case_2.geojson" } } } names, pc = analyse_process_graph(graph=graph) pprint(names) pprint(pc) self.assertEqual(names[0], "LL.sentinel2A_openeo_subset.strds.S2A_B04") self.assertEqual(names[1], "LL.sentinel2A_openeo_subset.strds.S2A_B08") self.assertEqual(len(pc), 14)
def post(self): """Run the job in an ephemeral mapset :return: """ try: # Empty the process location graas_openeo_core_wrapper.PROCESS_LOCATION = {} process_graph = request.get_json() # Transform the process graph into a process chain and store the input location # Check all locations in the process graph result_name, process_list = analyse_process_graph(process_graph) if len(graas_openeo_core_wrapper.PROCESS_LOCATION) == 0 or len( graas_openeo_core_wrapper.PROCESS_LOCATION) > 1: return make_response( jsonify( { "description": "Processes can only be defined for a single location!" }, 400)) location = graas_openeo_core_wrapper.PROCESS_LOCATION.keys() location = list(location)[0] process_chain = dict(list=process_list, version="1") # pprint.pprint(process_chain) status, response = self.iface.async_ephemeral_processing_export( location=location, process_chain=process_chain) # pprint.pprint(response) # Save the process graph into the graph db self.db[response["resource_id"]] = process_graph if status == 200: return make_response( jsonify({ "job_id": response["resource_id"], "job_info": response }), status) else: return make_response(jsonify(response), status) except Exception as e: return make_response(jsonify({"error": str(e)}), 400)
def test_openeo_usecase_1a(self): graph = \ { "process_graph": { "process_id": "min_time", "args": { "collections": [{ "process_id": "NDVI", "args": { "collections": [{ "process_id": "filter_daterange", "args": { "collections": [{ "process_id": "filter_bbox", "args": { "collections": [ {"product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B04"}, {"product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B08"}], "left": -5.0, "right": -4.7, "top": 39.3, "bottom": 39.0, "ewres": 0.1, "nsres": 0.1, "srs": "EPSG:4326" } }], "from": "2017-04-12 11:17:08", "to": "2017-09-04 11:18:26" } }], "red": "S2A_B04", "nir": "S2A_B08" } }] } } } name, pc = analyse_process_graph(graph=graph) pprint(name) pprint(pc) self.assertEqual(len(pc), 7)
def get_process_list(args): """Analyse the process description and return the GRaaS process chain and the name of the processing result layer which is a single raster layer :param args: The process description arguments :return: (output_name, pc) """ input_names, process_list = process_definitions.analyse_process_graph(args) output_names = [] for input_name in input_names: location, mapset, datatype, layer_name = GRaaSInterface.layer_def_to_components( input_name) output_name = "%s_%s" % (layer_name, PROCESS_NAME) output_names.append(output_name) pc = create_graas_process_chain_entry(input_name, output_name) process_list.append(pc) return output_names, process_list
def get_process_list(args): """Analyse the process description and return the GRaaS process chain and the name of the processing result :param args: The process description arguments :return: (output_time_series, pc) """ input_names, process_list = process_definitions.analyse_process_graph(args) output_names = [] # Two input names are required if len(input_names) != 2: raise Exception("At least two input time series are required") for i in range(0, len(input_names), 2): input_tuple = (input_names[i], input_names[i + 1]) nir_time_series = None red_time_series = None for input_name in input_tuple: if "nir" in args and args["nir"] in input_name: nir_time_series = input_name if "red" in args and args["red"] in input_name: red_time_series = input_name if nir_time_series is None or red_time_series is None: raise Exception("Band information is missing from process description") location, mapset, datatype, layer_name = GRaaSInterface.layer_def_to_components(nir_time_series) output_name = "%s_%s" % (layer_name, PROCESS_NAME) output_names.append(output_name) pc = create_graas_process_chain_entry(nir_time_series, red_time_series, output_name) process_list.extend(pc) return output_names, process_list
def test_openeo_usecase_2(self): graph = \ { "process_graph": { "process_id": "udf_reduce_time", "args": { "collections": [{ "process_id": "filter_daterange", "args": { "collections": [{ "process_id": "filter_bbox", "args": { "collections": [{"product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B04"}, {"product_id": "LL.sentinel2A_openeo_subset.strds.S2A_B08"}], "left": -5.0, "right": -4.7, "top": 39.3, "bottom": 39.0, "ewres": 0.1, "nsres": 0.1, "srs": "EPSG:4326" } }], "from": "1980-01-01 00:00:00", "to": "2010-01-01 00:00:00" } }], "python_file_url": "https://storage.googleapis.com/datentransfer/aggr_func.py" } } } name, pc = analyse_process_graph(graph=graph) pprint(name) pprint(pc) self.assertEqual(len(pc), 6)
def get_process_list(args): """Analyse the process description and return the GRaaS process chain and the name of the processing result layer which is a single raster layer :param args: The process description :return: (output_names, pc) """ # Get the input description and the process chain to attach this process input_names, process_list = process_definitions.analyse_process_graph(args) output_names = [] for input_name in input_names: output_name = input_name output_names.append(output_name) pc = create_graas_process_chain_entry(input_name=input_name) process_list.extend(pc) import pprint pprint.pprint(process_list) return output_names, process_list
def test_min_time(self): graph = { "process_graph": { "process_id": "min_time", "args": { "collections": [{ "process_id": "min_time", "args": { "collections": [{ "process_id": "min_time", "args": { "collections": [{ "process_id": "min_time", "args": { "collections": [{ "product_id": "ECAD.PERMANENT.strds.temperature_mean_1950_2013_yearly_celsius" }] } }], } }], } }] } } } name, pc = analyse_process_graph(graph=graph) pprint(name) pprint(pc) self.assertEqual(len(pc), 4) for entry in pc: self.assertTrue(entry["module"] == "t.rast.series")
def put(self): """Modify the existing database by running the job in a persistent mapset :return: """ try: # Empty the process location graas_openeo_core_wrapper.PROCESS_LOCATION = {} process_graph = request.get_json() # Transform the process graph into a process chain and store the input location # Check all locations in the process graph result_name, process_list = analyse_process_graph(process_graph) if len(graas_openeo_core_wrapper.PROCESS_LOCATION) == 0 or len( graas_openeo_core_wrapper.PROCESS_LOCATION) > 1: return make_response( jsonify( { "description": "Processes can only be defined for a single location!" }, 400)) location = graas_openeo_core_wrapper.PROCESS_LOCATION.keys() location = list(location)[0] status_code, mapsets = self.iface.list_mapsets(location=location) if status_code != 200: return make_response( jsonify( { "description": "An internal error occurred " "while catching mapsets!" }, 400)) count = 0 name = "openeo_mapset" new_mapset = "%s_%i" % (name, count) while new_mapset in mapsets: count += 1 new_mapset = "%s_%i" % (name, count) process_chain = dict(list=process_list, version="1") # pprint.pprint(process_chain) status, response = self.iface.async_persistent_processing( location=location, mapset=new_mapset, process_chain=process_chain) # pprint.pprint(response) # Save the process graph into the graph db self.db[response["resource_id"]] = process_graph if status == 200: return make_response( jsonify({ "job_id": response["resource_id"], "job_info": response }), status) else: return make_response(jsonify(response), status) except Exception as e: return make_response(jsonify({"error": str(e)}), 400)