From e15a51b7a13da5aa29a51c558ceaccc9e618cde4 Mon Sep 17 00:00:00 2001 From: Markus Metz Date: Fri, 3 Jun 2022 16:20:02 +0200 Subject: [PATCH 1/3] openeo GRASS driver: fix temporal filter, fix extents --- .../filter_temporal_process.py | 37 +++++++----- .../load_collection_process.py | 9 ++- .../collection_information.py | 8 ++- src/openeo_grass_gis_driver/jobs_job_id.py | 59 ++++++++++++++++++- .../jobs_job_id_results.py | 7 +++ 5 files changed, 99 insertions(+), 21 deletions(-) diff --git a/src/openeo_grass_gis_driver/actinia_processing/filter_temporal_process.py b/src/openeo_grass_gis_driver/actinia_processing/filter_temporal_process.py index b82de479..da658046 100644 --- a/src/openeo_grass_gis_driver/actinia_processing/filter_temporal_process.py +++ b/src/openeo_grass_gis_driver/actinia_processing/filter_temporal_process.py @@ -128,23 +128,30 @@ def create__process_chain_entry( """ start_time = start_time.replace('T', ' ') - end_time = end_time.replace('T', ' ') - - # Get info about the time series to extract its resolution settings and - # bbox rn = randint(0, 1000000) - # end_time can be null, and we can not find out if end_time is set because - # the input does not exist yet - pc = {"id": "t_rast_extract_%i" % rn, - "module": "t.rast.extract", - "inputs": [{"param": "input", "value": input_object.grass_name()}, - {"param": "where", "value": "start_time >= '%(start)s' " - "AND start_time <= '%(end)s'" % {"start": start_time, "end": end_time}}, - {"param": "output", "value": output_object.grass_name()}, - {"param": "expression", "value": "1.0 * %s" % input_object.name}, - {"param": "basename", "value": output_object.name}, - {"param": "suffix", "value": "num"}]} + # end_time can be null, use only start_time for filtering + if end_time and len(end_time) > 0: + end_time = end_time.replace('T', ' ') + + pc = {"id": "t_rast_extract_%i" % rn, + "module": "t.rast.extract", + "inputs": [{"param": "input", "value": input_object.grass_name()}, + {"param": "where", "value": "start_time >= '%(start)s' " + "AND start_time < '%(end)s'" % {"start": start_time, "end": end_time}}, + {"param": "output", "value": output_object.grass_name()}, + {"param": "expression", "value": "1.0 * %s" % input_object.name}, + {"param": "basename", "value": output_object.name}, + {"param": "suffix", "value": "num"}]} + else: + pc = {"id": "t_rast_extract_%i" % rn, + "module": "t.rast.extract", + "inputs": [{"param": "input", "value": input_object.grass_name()}, + {"param": "where", "value": "start_time >= '%(start)s'" % {"start": start_time}}, + {"param": "output", "value": output_object.grass_name()}, + {"param": "expression", "value": "1.0 * %s" % input_object.name}, + {"param": "basename", "value": output_object.name}, + {"param": "suffix", "value": "num"}]} return pc diff --git a/src/openeo_grass_gis_driver/actinia_processing/load_collection_process.py b/src/openeo_grass_gis_driver/actinia_processing/load_collection_process.py index de8465c7..be9aaa53 100644 --- a/src/openeo_grass_gis_driver/actinia_processing/load_collection_process.py +++ b/src/openeo_grass_gis_driver/actinia_processing/load_collection_process.py @@ -344,10 +344,13 @@ def create_process_chain_entry(input_object: DataObject, wherestring = "" if temporal_extent: start_time = temporal_extent[0].replace('T', ' ') - end_time = temporal_extent[1].replace('T', ' ') + if len(temporal_extent) > 1: + end_time = temporal_extent[1].replace('T', ' ') + wherestring = "start_time >= '%(start)s' AND start_time < '%(end)s'" % { + "start": start_time, "end": end_time} # end_time can be null, use only start_time for filtering - wherestring = "start_time >= '%(start)s' AND start_time <= '%(end)s'" % { - "start": start_time, "end": end_time} + else: + wherestring = "start_time >= '%(start)s'" % {"start": start_time} if bands: wherestring = wherestring + " AND " if bands: diff --git a/src/openeo_grass_gis_driver/collection_information.py b/src/openeo_grass_gis_driver/collection_information.py index 859736c0..02f11eb4 100644 --- a/src/openeo_grass_gis_driver/collection_information.py +++ b/src/openeo_grass_gis_driver/collection_information.py @@ -181,11 +181,15 @@ def get(self, name): bands = [] dimensions = {"x": { "type": "spatial", - "axis": "x" + "axis": "x", + "extent": [layer_data["west"], layer_data["east"]], + "reference_system": mapset_info["projection"] }, "y": { "type": "spatial", - "axis": "y" + "axis": "y", + "extent": [layer_data["south"], layer_data["north"]], + "reference_system": mapset_info["projection"] }, } platform = "unknown" diff --git a/src/openeo_grass_gis_driver/jobs_job_id.py b/src/openeo_grass_gis_driver/jobs_job_id.py index d9c83124..7515ffb5 100644 --- a/src/openeo_grass_gis_driver/jobs_job_id.py +++ b/src/openeo_grass_gis_driver/jobs_job_id.py @@ -38,8 +38,60 @@ def get(self, job_id): if job_id in self.job_db: job: JobInformation = self.job_db[job_id] + + job.stac_version = CAPABILITIES['stac_version'] + job.type = "Feature" + job.geometry = "json:null" + job.properties = dict() + job.properties['datetime'] = None + job.assets = dict() + job.links = [] + + # Check for the actinia id to get the latest actinia job + # information + if job_id in self.actinia_job_db: + actinia_id = self.actinia_job_db[job_id] + code, job_info = self.iface.resource_info( + resource_id=actinia_id) + + if code == 200: + # Add the actinia information to the openeo job + if job.additional_info != job_info: + job.additional_info = job_info + job.updated = job_info["datetime"].replace( + " ", "T").replace( + "'", "").replace( + '"', '') + if job_info["status"] == "finished": + job.status = "finished" + if job_info["status"] == "error": + job.status = "error" + if job_info["status"] == "accepted": + job.status = "queued" + if job_info["status"] == "terminated": + job.status = "canceled" + if job_info["status"] == "running": + job.status = "running" + + # Store the updated job in the database + self.job_db[job_id] = job + else: + if job.additional_info != job_info: + job.additional_info = job_info + self.job_db[job_id] = job + + if (job.additional_info['urls'] and + "resources" in job.additional_info['urls']): + resource_links = job.additional_info['urls']['resources'] + + if job.links is None: + job.links = [] + + for link in resource_links: + eo_link = EoLink(href=link) + job.links.append(eo_link) + return job.as_response(http_status=200) - # return make_response(job.to_json(), 200) else: return ErrorSchema( id="123456678", @@ -88,6 +140,11 @@ def delete(self, job_id): """ if job_id in self.job_db: + if job_id in self.actinia_job_db: + actinia_id = self.actinia_job_db[job_id] + code, job_info = self.iface.delete_resource( + resource_id=actinia_id) + del self.job_db[job_id] return make_response("The job has been successfully deleted", 204) else: diff --git a/src/openeo_grass_gis_driver/jobs_job_id_results.py b/src/openeo_grass_gis_driver/jobs_job_id_results.py index add62f28..472a0d5a 100644 --- a/src/openeo_grass_gis_driver/jobs_job_id_results.py +++ b/src/openeo_grass_gis_driver/jobs_job_id_results.py @@ -197,6 +197,13 @@ def delete(self, job_id): actinia_id = self.actinia_job_db[job_id] code, job_info = self.iface.delete_resource( resource_id=actinia_id) + del self.actinia_job_db[job_id] + + job: JobInformation = self.job_db[job_id] + job.status = "cancelled" + job.updated = str(datetime.now().isoformat()) + + self.job_db[job_id] = job return make_response( "The job has been successfully cancelled", 204) From 6d72d97e22973706314c6ad880c873c91d17eda0 Mon Sep 17 00:00:00 2001 From: Markus Metz Date: Fri, 3 Jun 2022 16:27:58 +0200 Subject: [PATCH 2/3] add imports --- src/openeo_grass_gis_driver/jobs_job_id.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openeo_grass_gis_driver/jobs_job_id.py b/src/openeo_grass_gis_driver/jobs_job_id.py index 7515ffb5..e277a595 100644 --- a/src/openeo_grass_gis_driver/jobs_job_id.py +++ b/src/openeo_grass_gis_driver/jobs_job_id.py @@ -3,6 +3,7 @@ from uuid import uuid4 import sys from flask import make_response, request +from openeo_grass_gis_driver.capabilities import CAPABILITIES from openeo_grass_gis_driver.actinia_processing.actinia_interface import \ ActiniaInterface from openeo_grass_gis_driver.actinia_processing.config import \ @@ -13,6 +14,7 @@ from openeo_grass_gis_driver.models.job_schemas import JobInformation from openeo_grass_gis_driver.jobs import check_job from openeo_grass_gis_driver.authentication import ResourceBase +from openeo_grass_gis_driver.models.schema_base import EoLink __license__ = "Apache License, Version 2.0" __author__ = "Sören Gebbert" From 6153d9bf2b5b059000add4ce8996d0d6d384c4f3 Mon Sep 17 00:00:00 2001 From: Markus Metz Date: Fri, 3 Jun 2022 16:32:18 +0200 Subject: [PATCH 3/3] flake8 --- src/openeo_grass_gis_driver/jobs_job_id_results.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openeo_grass_gis_driver/jobs_job_id_results.py b/src/openeo_grass_gis_driver/jobs_job_id_results.py index 472a0d5a..7e52ae6c 100644 --- a/src/openeo_grass_gis_driver/jobs_job_id_results.py +++ b/src/openeo_grass_gis_driver/jobs_job_id_results.py @@ -198,7 +198,7 @@ def delete(self, job_id): code, job_info = self.iface.delete_resource( resource_id=actinia_id) del self.actinia_job_db[job_id] - + job: JobInformation = self.job_db[job_id] job.status = "cancelled" job.updated = str(datetime.now().isoformat())