[GRASS-SVN] r71006 - grass-addons/grass7/raster/r.series.filter

svn_grass at osgeo.org svn_grass at osgeo.org
Tue May 2 19:11:12 PDT 2017


Author: wenzeslaus
Date: 2017-05-02 19:11:12 -0700 (Tue, 02 May 2017)
New Revision: 71006

Modified:
   grass-addons/grass7/raster/r.series.filter/r.series.filter.py
Log:
r.series.filter: lazy import scipy (global import in main block)

Modified: grass-addons/grass7/raster/r.series.filter/r.series.filter.py
===================================================================
--- grass-addons/grass7/raster/r.series.filter/r.series.filter.py	2017-05-03 02:05:45 UTC (rev 71005)
+++ grass-addons/grass7/raster/r.series.filter/r.series.filter.py	2017-05-03 02:11:12 UTC (rev 71006)
@@ -127,14 +127,8 @@
 from grass.pygrass.gis.region import Region
 
 import numpy as np
-try:
-    from scipy.signal import savgol_filter
-except ImportError:
-    grass.error("Cannot import savgol_filter from scipy. Install python-scipy version 0.14 or later package first")
-    sys.exit(1)
-from scipy.signal import medfilt
+# lazy import scipy at the end of the file
 
-
 CNULL = -2147483648  # null value for CELL maps
 FNULL = np.nan       # null value for FCELL and DCELL maps
 
@@ -447,4 +441,14 @@
 
 if __name__ == "__main__":
     options, flags = grass.parser()
+
+    # import only after the parser finished and the code actually runs
+    try:
+        from scipy.signal import savgol_filter
+    except ImportError:
+        grass.fatal("Cannot import savgol_filter from scipy."
+                    " Install python-scipy package version"
+                    " 0.14 or later first")
+    from scipy.signal import medfilt
+
     main(options, flags)



More information about the grass-commit mailing list