From 1f8b2b04c47ca7b85d0330554a2a016980c8e2d1 Mon Sep 17 00:00:00 2001
From: Impact <pascal.mouquet@ird.fr>
Date: Tue, 30 Apr 2019 15:00:49 +0400
Subject: [PATCH] example scripts update 3

---
 script_examples/download_tiles.csv |  4 +++
 script_examples/download_tiles.py  | 51 ++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 script_examples/download_tiles.csv
 create mode 100644 script_examples/download_tiles.py

diff --git a/script_examples/download_tiles.csv b/script_examples/download_tiles.csv
new file mode 100644
index 0000000..5e580ac
--- /dev/null
+++ b/script_examples/download_tiles.csv
@@ -0,0 +1,4 @@
+tile;start_time;end_time;max_clouds;site;nom
+
+40KCB;2019-01-01;;;France;Reunion
+#37KFR;;;;TAAF_Eparses;Europa
diff --git a/script_examples/download_tiles.py b/script_examples/download_tiles.py
new file mode 100644
index 0000000..6475786
--- /dev/null
+++ b/script_examples/download_tiles.py
@@ -0,0 +1,51 @@
+# -*- coding:utf-8 -*-
+
+"""
+    Download L1C products from a tile and dates list provided by a csv file
+    
+    peps and scihub hub limits can be adjusted (line 53)
+    - usually PEPS is faster for recent data (limit max 8)
+    - scihub is better for a few months old products (limit max 2)
+    
+"""
+
+import logging
+import pandas as pd
+from sen2chain import DataRequest, DownloadAndProcess, Tile
+import datetime
+import os
+import time
+import math
+
+logger = logging.getLogger("Downloading L1C")
+logging.basicConfig(level=logging.INFO)
+
+fwd = os.path.dirname(os.path.realpath(__file__))
+
+# Path to csv process list
+tiles_file = fwd + "/download_tiles.csv"
+
+# default number of days to check before today 
+# if this field is empty in the csv file
+delta_t = 15
+
+tiles_list = pd.read_csv(tiles_file, sep = ';', na_values="", comment='#')
+
+for index, row in tiles_list.iterrows():
+    try:
+        if math.isnan(row.start_time):
+            row.start_time = (datetime.datetime.now()-datetime.timedelta(days=delta_t)).strftime('%Y-%m-%d')
+    except:
+        pass
+    try:
+        if math.isnan(row.end_time):
+            row.end_time = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime('%Y-%m-%d')
+    except:
+        pass
+
+    tuile = Tile(row.tile)
+    req = DataRequest(start_date=row.start_time, end_date=row.end_time).from_tiles([row.tile])
+    DownloadAndProcess(req, hubs_limit={"peps":8, "scihub":0}, process_products=False, indices_list=[], nodata_clouds=False, quicklook=False, max_processes=8)
+    time.sleep(1)
+    tuile = Tile(row.tile)
+
-- 
GitLab