Skip to content
GitLab
    • Explore Projects Groups Topics Snippets
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • scenes scenes
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Graph
    • Compare revisions
  • Issues 9
    • Issues 9
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Terraform modules
  • Monitor
    • Monitor
    • Incidents
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

La forge institutionnelle d'INRAE étant en production depuis le 10 juin 2025, nous vous invitons à y créer vos nouveaux projets.

  • umr-tetisumr-tetis
  • scenesscenes
  • Merge requests
  • !26
An error occurred while fetching the assigned milestone of the selected merge_request.

ENH: lazy dates formats

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Cresson Remi requested to merge 11-enh_lazy_dates into develop 3 years ago
  • Overview 0
  • Commits 5
  • Pipelines 5
  • Changes 5

Closes #11 (closed)

Compare
  • version 4
    28fc7046
    3 years ago

  • version 3
    353ee924
    3 years ago

  • version 2
    c7f3b1ce
    3 years ago

  • version 1
    bed917ee
    3 years ago

  • develop (base)

and
  • latest version
    0c5bf8e0
    5 commits, 3 years ago

  • version 4
    28fc7046
    4 commits, 3 years ago

  • version 3
    353ee924
    3 commits, 3 years ago

  • version 2
    c7f3b1ce
    2 commits, 3 years ago

  • version 1
    bed917ee
    1 commit, 3 years ago

5 files
+ 68
− 48

    Preferences

    File browser
    Compare changes
test/download_test.py → apps/s2_download.py
+ 0
− 0
  • View file @ 0c5bf8e0

  • Edit in single-file editor

  • Open in Web IDE

Unable to load file contents. Try again later.
File renamed with no changes. Show file contents
scenes/dates.py
+ 13
− 0
  • View file @ 0c5bf8e0

  • Edit in single-file editor

  • Open in Web IDE


@@ -5,6 +5,19 @@ This module aims to deal with dates
import datetime
def get_timestamp(dt):
"""Converts datetime.datetime into a timestamp (in seconds)
Args:
dt: datetime.datetime instance
Returns:
timestamp (in seconds)
"""
return dt.replace(tzinfo=datetime.timezone.utc).timestamp()
def str2datetime(datestr):
"""
Converts an input date as string into a datetime instance.
scenes/indexation.py
+ 23
− 48
  • View file @ 0c5bf8e0

  • Edit in single-file editor

  • Open in Web IDE


@@ -3,52 +3,23 @@ This module contains stuff for the spatio-temporal indexation of scenes.
"""
import datetime
import rtree
from scenes.dates import get_timestamp, any2datetime
def get_timestamp(dt):
"""Converts datetime.datetime into a timestamp (in seconds)
Args:
dt: datetime.datetime instance
Returns:
timestamp (in seconds)
"""
return dt.replace(tzinfo=datetime.timezone.utc).timestamp()
def new_bbox(bbox_wgs84, dt):
"""Return a bounding box in the domain (lat, lon, time)
Args:
bbox_wgs84: Bounding box (in WGS84)
dt: date datetime.datetime
Returns:
item for rtree
"""
dt_min = dt - datetime.timedelta(days=1)
dt_max = dt + datetime.timedelta(days=1)
return bbox(bbox_wgs84=bbox_wgs84, dt_min=dt_min, dt_max=dt_max)
def bbox(bbox_wgs84, dt_min, dt_max):
def _bbox(bbox_wgs84, date_min, date_max):
"""Return a bounding box in the domain (lat, lon, time)
Args:
bbox_wgs84: The bounding box in WGS84 (BoundingBox instance)
dt_min: date min (datetime.datetime)
dt_max: date max (datetime.datetime)
date_min: date min (datetime.datetime or str)
date_max: date max (datetime.datetime or str)
Returns:
item for rtree
"""
return (bbox_wgs84.xmin, bbox_wgs84.ymin, get_timestamp(dt_min),
bbox_wgs84.xmax, bbox_wgs84.ymax, get_timestamp(dt_max))
return (bbox_wgs84.xmin, bbox_wgs84.ymin, get_timestamp(any2datetime(date_min)),
bbox_wgs84.xmax, bbox_wgs84.ymax, get_timestamp(any2datetime(date_max)))
class Index:
@@ -66,38 +37,42 @@ class Index:
properties.dimension = 3
self.index = rtree.index.Index(properties=properties)
for scene_idx, scene in enumerate(scenes_list):
self.index.insert(scene_idx, new_bbox(bbox_wgs84=scene.bbox_wgs84, dt=scene.acquisition_date))
dt = scene.acquisition_date
dt_min = dt - datetime.timedelta(days=1)
dt_max = dt + datetime.timedelta(days=1)
new_bbox = _bbox(bbox_wgs84=scene.bbox_wgs84, date_min=dt_min, date_max=dt_max)
self.index.insert(scene_idx, new_bbox)
def find_indices(self, bbox_wgs84, dt_min=None, dt_max=None):
def find_indices(self, bbox_wgs84, date_min=None, date_max=None):
"""Search the intersecting elements, and return their indices
Args:
bbox_wgs84: The bounding box in WGS84 (BoundingBox instance)
dt_min: date min (datetime.datetime) (Default value = None)
dt_max: date max (datetime.datetime) (Default value = None)
date_min: date min (datetime.datetime or str) (Default value = None)
date_max: date max (datetime.datetime or str) (Default value = None)
Returns:
list of indices
"""
if not dt_min:
dt_min = datetime.datetime.strptime("2000-01-01", "%Y-%m-%d")
if not dt_max:
dt_max = datetime.datetime.strptime("3000-01-01", "%Y-%m-%d")
bbox_search = bbox(bbox_wgs84=bbox_wgs84, dt_min=dt_min, dt_max=dt_max)
if not date_min:
date_min = datetime.datetime.strptime("2000-01-01", "%Y-%m-%d")
if not date_max:
date_max = datetime.datetime.strptime("3000-01-01", "%Y-%m-%d")
bbox_search = _bbox(bbox_wgs84=bbox_wgs84, date_min=date_min, date_max=date_max)
return self.index.intersection(bbox_search)
def find(self, bbox_wgs84, dt_min=None, dt_max=None):
def find(self, bbox_wgs84, date_min=None, date_max=None):
"""Search the intersecting elements, and return them
Args:
bbox_wgs84: The bounding box in WGS84 (BoundingBox instance)
dt_min: date min (datetime.datetime) (Default value = None)
dt_max: date max (datetime.datetime) (Default value = None)
date_min: date min (datetime.datetime or str) (Default value = None)
date_max: date max (datetime.datetime or str) (Default value = None)
Returns:
list of indices
"""
indices = self.find_indices(bbox_wgs84=bbox_wgs84, dt_min=dt_min, dt_max=dt_max)
indices = self.find_indices(bbox_wgs84=bbox_wgs84, date_min=date_min, date_max=date_max)
return [self.scenes_list[i] for i in indices]
test/dates_test.py 0 → 100644
+ 28
− 0
  • View file @ 0c5bf8e0

  • Edit in single-file editor

  • Open in Web IDE

# -*- coding: utf-8 -*-
from scenes_test_base import ScenesTestBase
import datetime
from scenes import Index, BoundingBox, dates
class DatesTest(ScenesTestBase):
def test_input_dates_formats(self):
datestr1 = "04/10/1986"
datestr2 = "04-10-1986"
datestr3 = "1986-10-04"
dt = datetime.datetime(year=1986, month=10, day=4)
assert dates.any2datetime(datestr1) == dt
assert dates.any2datetime(datestr2) == dt
assert dates.any2datetime(datestr3) == dt
# Index test
idx = Index([])
dummy_bbox = BoundingBox(0, 0, 0, 0)
_ = idx.find(dummy_bbox, date_min=datestr1)
_ = idx.find(dummy_bbox, date_min=datestr2)
_ = idx.find(dummy_bbox, date_min=datestr3)
if __name__ == '__main__':
unittest.main()
.gitlab-ci.yml
+ 4
− 0
  • View file @ 0c5bf8e0

  • Edit in single-file editor

  • Open in Web IDE


@@ -69,3 +69,7 @@ indexation:
script:
- pytest -o log_cli=true --log-cli-level=INFO --junitxml=report_indexation_test.xml test/indexation_test.py
dates:
extends: .test_base
script:
- pytest -o log_cli=true --log-cli-level=INFO --junitxml=report_dates_test.xml test/dates_test.py
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 Participants
Reference:
Source branch: 11-enh_lazy_dates

Menu

Explore Projects Groups Topics Snippets