Browse Source

t.rast.import: added memory option https://trac.osgeo.org/grass/ticket/2375, added answer /tmp to directory option, added test

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67963 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 9 years ago
parent
commit
67812a406d

+ 7 - 4
lib/python/temporal/stds_import.py

@@ -53,7 +53,7 @@ imported_maps = {}
 
 
 def _import_raster_maps_from_gdal(maplist, overr, exp, location, link, format_,
-                                  set_current_region=False):
+                                  set_current_region=False, memory=300):
     impflags = ""
     if overr:
         impflags += "o"
@@ -76,7 +76,7 @@ def _import_raster_maps_from_gdal(maplist, overr, exp, location, link, format_,
                                     overwrite=gscript.overwrite())
             else:
                 gscript.run_command("r.in.gdal", input=filename,
-                                    output=name,
+                                    output=name, memory=memory,
                                     flags=impflags,
                                     overwrite=gscript.overwrite())
 
@@ -173,7 +173,8 @@ def _import_vector_maps(maplist):
 
 def import_stds(input, output, directory, title=None, descr=None, location=None,
                 link=False, exp=False, overr=False, create=False,
-                stds_type="strds", base=None, set_current_region=False):
+                stds_type="strds", base=None, set_current_region=False,
+                memory=300):
     """Import space time datasets of type raster and vector
 
         :param input: Name of the input archive file
@@ -194,6 +195,7 @@ def import_stds(input, output, directory, title=None, descr=None, location=None,
                          should be imported
         :param base: The base name of the new imported maps, it will be
                      extended using a numerical index.
+        :param memory: Cache size for raster rows, used in r.in.gdal
     """
 
     global raise_on_error
@@ -437,7 +439,8 @@ def import_stds(input, output, directory, title=None, descr=None, location=None,
         if type_ == "strds":
             if format_ == "GTiff" or format_ == "AAIGrid":
                 _import_raster_maps_from_gdal(maplist, overr, exp, location,
-                                              link, format_, set_current_region)
+                                              link, format_, set_current_region,
+                                              memory)
             if format_ == "pack":
                 _import_raster_maps(maplist, set_current_region)
         elif type_ == "stvds":

+ 13 - 1
temporal/t.rast.import/t.rast.import.py

@@ -41,6 +41,7 @@
 #%option G_OPT_M_DIR
 #% key: directory
 #% description: Path to the extraction directory
+#% answer: /tmp
 #%end
 
 #%option
@@ -67,6 +68,16 @@
 #% multiple: no
 #%end
 
+#%option
+#% key: memory
+#% type: integer
+#% description: Cache size for raster rows
+#% label: Maximum memory to be used (in MB)
+#% options: 0-2047
+#% answer: 300
+#% multiple: no
+#%end
+
 #%flag
 #% key: r
 #% description: Set the current region from the last map that was imported
@@ -107,6 +118,7 @@ def main():
     descr = options["description"]
     location = options["location"]
     base = options["basename"]
+    memory = options["memory"]
     set_current_region = flags["r"]
     link = flags["l"]
     exp = flags["e"]
@@ -117,7 +129,7 @@ def main():
 
     tgis.import_stds(input, output, directory, title, descr, location,
                      link, exp, overr, create, "strds", base, 
-                     set_current_region)
+                     set_current_region, memory)
 
 if __name__ == "__main__":
     options, flags = grass.parser()

BIN
temporal/t.rast.import/testsuite/data/precip_2000.tar.bzip2


+ 47 - 0
temporal/t.rast.import/testsuite/test_temporal_rast_import.py

@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Feb 26 14:46:06 2016
+
+@author: lucadelu
+"""
+
+"""
+Test t.rast.import
+
+(C) 2014 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+@author: lucadelu
+"""
+
+from grass.gunittest.case import TestCase
+import os
+
+class TestRasterImport(TestCase):
+    
+    input_ = os.path.join("data", "precip_2000.tar.bzip2")
+    @classmethod
+    def tearDownClass(cls):
+        """Remove the temporary region
+        """
+        cls.del_temp_region()
+        cls.runModule("t.remove", flags="rf", inputs="A")
+        
+    def test_import(self):
+        self.assertModule("t.rast.import", input=self.input_, output="A", 
+                          basename="a", overwrite=True)
+        tinfo = """start_time=2000-01-01 00:00:00
+                   end_time=2001-01-01 00:00:00
+                   granularity=1 month
+                   map_time=interval
+                   north=320000.0
+                   south=10000.0
+                   east=935000.0
+                   west=120000.0
+                """
+                
+        info = SimpleModule("t.info", flags="g", input="A")
+        self.assertModuleKeyValue(module=info, reference=tinfo,
+                                  precision=2, sep="=")