[GRASS-SVN] r73104 - grass-addons/grass7/imagery/i.sentinel/i.sentinel.download

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 15 02:41:22 PDT 2018


Author: martinl
Date: 2018-08-15 02:41:22 -0700 (Wed, 15 Aug 2018)
New Revision: 73104

Modified:
   grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.html
   grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.py
Log:
i.sentinel.download: implement uuid option

Modified: grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.html
===================================================================
--- grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.html	2018-08-15 08:52:11 UTC (rev 73103)
+++ grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.html	2018-08-15 09:41:22 UTC (rev 73104)
@@ -114,6 +114,19 @@
 using <em><a href="i.sentinel.import.html">i.sentinel.import</a></em>
 module.
 
+<h3>Download Sentinel products by UUID</h3>
+
+<em>i.sentinel.download</em> also allows downloading Sentinel products
+by giving a list of UUID. This operation is performed by <b>uuid</b>
+option. Note this option is mutually exclusive with all of other
+filtering options.
+
+Example of downloading one Sentinel product:
+
+<div class="code"><pre>
+i.sentinel.download settings=sentinel.txt uuid=98f00e12-3b62-4c54-8554-c4439bb1ebef output=data
+<pre></div>
+
 <h2>REQUIREMENTS</h2>
 
 <ul>

Modified: grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.py
===================================================================
--- grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.py	2018-08-15 08:52:11 UTC (rev 73103)
+++ grass-addons/grass7/imagery/i.sentinel/i.sentinel.download/i.sentinel.download.py	2018-08-15 09:41:22 UTC (rev 73104)
@@ -88,6 +88,13 @@
 #% guisection: Filter
 #%end
 #%option
+#% key: uuid
+#% type: string
+#% multiple: yes
+#% description: List of UUID to download
+#% guisection: Filter
+#%end
+#%option
 #% key: sort
 #% description: Sort by values in given order
 #% multiple: yes
@@ -109,6 +116,7 @@
 #%end
 #%rules
 #% required: output,-l
+#% excludes: uuid,map,area_relation,clouds,producttype,start,end,limit,sort,order
 #%end
 
 import os
@@ -210,7 +218,7 @@
         if self._products_df_sorted is None:
             return
 
-        for idx in range(len(self._products_df_sorted)):
+        for idx in range(len(self._products_df_sorted['uuid'])):
             print ('{0} {1} {2:2.0f}% {3}'.format(
                 self._products_df_sorted['uuid'][idx],
                 self._products_df_sorted['beginposition'][idx].strftime("%Y-%m-%dT%H:%M:%SZ"),
@@ -217,7 +225,7 @@
                 self._products_df_sorted['cloudcoverpercentage'][idx],
                 self._products_df_sorted['producttype'][idx],
             ))
-
+        
     def download(self, output):
         if self._products_df_sorted is None:
             return
@@ -225,7 +233,7 @@
         if not os.path.exists(output):
             os.makedirs(output)
         gs.message(_('Downloading data into <{}>...').format(output))
-        for idx in range(len(self._products_df_sorted)):
+        for idx in range(len(self._products_df_sorted['uuid'])):
             gs.message('{} -> {}.SAFE'.format(
                 self._products_df_sorted['uuid'][idx],
                 os.path.join(output, self._products_df_sorted['identifier'][idx])
@@ -271,7 +279,7 @@
             layer.CreateField(field)
 
         # features
-        for idx in range(len(self._products_df_sorted)):
+        for idx in range(len(self._products_df_sorted['uuid'])):
             wkt = self._products_df_sorted['footprint'][idx]
             feature = ogr.Feature(layer.GetLayerDefn())
             feature.SetGeometry(ogr.CreateGeometryFromWkt(wkt))
@@ -290,6 +298,37 @@
                        layer=map_name, quiet=True
         )
 
+    def set_uuid(self, uuid_list):
+        """Set products by uuid.
+
+        TODO: Find better implementation
+
+        :param uuid: uuid to download
+        """
+        self._products_df_sorted = {}
+
+        for uuid in uuid_list:
+            for k, v in self._api.get_product_odata(uuid, full=True).items():
+                if k == 'id':
+                    k = 'uuid'
+                elif k == 'Sensing start':
+                    k = 'beginposition'
+                elif k == 'Product type':
+                    k = 'producttype'
+                elif k == 'Cloud cover percentage':
+                    k = 'cloudcoverpercentage'
+                elif k == 'Identifier':
+                    k = 'identifier'
+                elif k == 'Ingestion Date':
+                    k = 'ingestiondate'
+                elif k == 'footprint':
+                    pass
+                else:
+                    continue
+                if k not in self._products_df_sorted:
+                    self._products_df_sorted[k] = []
+                self._products_df_sorted[k].append(v)
+        
 def main():
     user = password = None
     api_url='https://scihub.copernicus.eu/dhus'
@@ -323,16 +362,19 @@
     try:
         downloader = SentinelDownloader(user, password, api_url)
 
-        downloader.filter(area=map_box,
-                          area_relation=options['area_relation'],
-                          clouds=options['clouds'],
-                          producttype=options['producttype'],
-                          limit=options['limit'],
-                          start=options['start'],
-                          end=options['end'],
-                          sortby=options['sort'].split(','),
-                          asc=options['order'] == 'asc'
-        )
+        if options['uuid']:
+            downloader.set_uuid(options['uuid'].split(','))
+        else:
+            downloader.filter(area=map_box,
+                              area_relation=options['area_relation'],
+                              clouds=options['clouds'],
+                              producttype=options['producttype'],
+                              limit=options['limit'],
+                              start=options['start'],
+                              end=options['end'],
+                              sortby=options['sort'].split(','),
+                              asc=options['order'] == 'asc'
+            )
     except StandardError as e:
         gs.fatal(_('Unable to connect Copernicus Open Access Hub: {}').format(e))
 



More information about the grass-commit mailing list