Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openeo GRASS driver: fix temporal filter, fix extents #147

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions src/openeo_grass_gis_driver/collection_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
61 changes: 60 additions & 1 deletion src/openeo_grass_gis_driver/jobs_job_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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"
Expand All @@ -38,8 +40,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",
Expand Down Expand Up @@ -88,6 +142,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:
Expand Down
7 changes: 7 additions & 0 deletions src/openeo_grass_gis_driver/jobs_job_id_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down