Skip to content
Snippets Groups Projects
Commit 37bb2a57 authored by pascal.mouquet_ird.fr's avatar pascal.mouquet_ird.fr
Browse files

Merge branch 'master' of framagit.org:espace-dev/sen2chain

parents 9aadee48 96e18d79
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
"""
Module for automatized downloading, processing and time series computing of new Sentinel-2 images.
"""
import time
import logging
import pandas as pd
import numpy as np
......@@ -148,24 +148,25 @@ class Automatization:
return None
@staticmethod
def _five_days_since_date(date: datetime) -> bool:
"""Checks if at least five days have passed since the date.
def _ndays_since_date(date: datetime, ndays: int) -> bool:
"""Checks if at least ndays have passed since the date.
:param date: date to check.
:param ndays: number of days.
"""
time_period = datetime.today() - date
if time_period.days < 4:
if time_period.days < ndays:
return False
return True
def _get_products_list(self) -> None:
def _get_products_list(self, revisit_period) -> None:
"""Merge each request dict into a single one."""
for tile, request_date in self._tiles_to_update.items():
# Don't overload the server with useless requests :
# Sentinel-2 revisit time is 5 days
if request_date:
if not Automatization._five_days_since_date(request_date):
if not Automatization._ndays_since_date(request_date, revisit_period):
logger.info("Too early to check {}".format(tile))
continue
......@@ -188,7 +189,8 @@ class Automatization:
indices_list: List[str] = None,
nodata_clouds: bool = True,
quicklook: bool = True,
hubs_limit: Dict[str, int] = None
hubs_limit: Dict[str, int] = None,
revisit_period: int = 2,
) -> None:
"""
Runs automatization.
......@@ -198,6 +200,7 @@ class Automatization:
:param indices_list: list of valid indices names that will be processed.
:param nodata_clouds: mask indices output rasters with a cloud-mask.
:param quicklook: creates a quicklook for each indice processed.
:param revisit_period: number of days, since last date, to check again for new images.
"""
logger.info("Running automatization")
logger.info("Ignored tiles: {}".format(self._get_ignored_tiles(self)))
......@@ -210,7 +213,7 @@ class Automatization:
hubs_limit = {"peps": 3, "scihub": 2}
self._get_tiles_to_update(tiles_list=tiles)
self._get_products_list()
self._get_products_list(revisit_period)
if any(self._products_list.values()):
prods = DownloadAndProcess(identifiers=self._products_list,
hubs_limit=hubs_limit,
......@@ -223,6 +226,9 @@ class Automatization:
failed = prods.failed_products
if failed:
print(failed)
# When working on a local network storage, pause the process in
# order to let the file to be checked by the filesystem (lags).
time.sleep(2)
self._update_df()
self._save_csv()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment