Skip to content

Commit

Permalink
Fix for mixed timezones. #815
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileSonneveld committed Jun 25, 2024
1 parent 26fb8bd commit 96546fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions openeogeotrellis/layercatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import py4j.protocol
import pyproj
import pyspark.sql.utils
import pytz

from openeo.metadata import Band
from openeo.util import TimingLogger, deep_get, str_truncate
from openeo_driver import filter_properties
Expand Down Expand Up @@ -891,12 +893,13 @@ def estimate_number_of_temporal_observations(self,
logger.warning(
f"Got half open: {temporal_extent=}. Assuming it goes till today."
)
from_date_parsed = dateutil.parser.parse(from_date).replace(tzinfo=None)
to_date_now = datetime.now().replace(tzinfo=None)
from_date_parsed = dateutil.parser.parse(from_date).replace(tzinfo=pytz.UTC)
to_date_now = datetime.now().replace(tzinfo=pytz.UTC)
number_of_temporal_observations = (to_date_now - from_date_parsed).total_seconds() / temporal_step
else:
number_of_temporal_observations = (dateutil.parser.parse(to_date) - dateutil.parser.parse(
from_date)).total_seconds() / temporal_step
to_date_parsed = dateutil.parser.parse(to_date).replace(tzinfo=pytz.UTC)
from_date_parsed = dateutil.parser.parse(from_date).replace(tzinfo=pytz.UTC)
number_of_temporal_observations = (to_date_parsed - from_date_parsed).total_seconds() / temporal_step
number_of_temporal_observations = max(math.floor(number_of_temporal_observations), 1)
return number_of_temporal_observations

Expand Down
21 changes: 21 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ def test_extra_validation_layer_too_large_area(backend_implementation):
assert "spatial extent" in errors[0]['message']


def test_extra_validation_layer_timezone(backend_implementation):
processing = GpsProcessing()
source_id1 = "load_collection", ("SENTINEL1_GRD", None)
env_source_constraints = [
(source_id1, {
"temporal_extent": ["2022-01-01T00:00:00Z", "2022-01-09"],
"spatial_extent": {"south": -952987.7582, "west": 1495130.8875, "north": 910166.7419, "east": 9088482.3929,
"crs": "EPSG:32632"},
"bands": ["VV"],
})
]
env = EvalEnv(
values={ENV_SOURCE_CONSTRAINTS: env_source_constraints, "backend_implementation": backend_implementation,
"sync_job": True,
"version": "1.0.0"})
errors = list(processing.extra_validation({}, env, None, env_source_constraints))
assert len(errors) == 1
assert errors[0]['code'] == "ExtentTooLarge"
assert "spatial extent" in errors[0]['message']


def test_extra_validation_layer_too_large_delayedvector(backend_implementation):
processing = GpsProcessing()
source_id1 = "load_collection", ("SENTINEL1_GRD", None)
Expand Down

0 comments on commit 96546fd

Please sign in to comment.