[GRASS-SVN] r68165 - grass-addons/grass7/raster/r.randomforest

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 27 20:51:05 PDT 2016


Author: spawley
Date: 2016-03-27 20:51:05 -0700 (Sun, 27 Mar 2016)
New Revision: 68165

Modified:
   grass-addons/grass7/raster/r.randomforest/r.randomforest.py
Log:
Fixed randomforest for linux and os x

Modified: grass-addons/grass7/raster/r.randomforest/r.randomforest.py
===================================================================
--- grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-03-27 15:17:42 UTC (rev 68164)
+++ grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-03-28 03:51:05 UTC (rev 68165)
@@ -232,8 +232,16 @@
     
     # determine cell storage type of training roi raster    
     roi_type = grass.read_command("r.info", map = roi, flags = 'g')
-    roi_type = str(roi_type)    
-    roi_list = roi_type.split('\r\n')
+    
+    if os.name == "nt":
+        roi_type = roi_type[0:len(roi_type)-2] # to remove the last line ending and return characters
+        roi_type = str(roi_type)
+        roi_list = roi_type.split('\r\n')
+    else:
+        roi_type = roi_type[0:len(roi_type)-1] # to remove the last line ending and return characters
+        roi_type = str(roi_type)
+        roi_list = roi_type.split('\n')    
+    
     dtype = roi_list[9].split('=')[1]
     
     # check if training rois are valid for classification and regression
@@ -243,7 +251,13 @@
     
     # Count number of labelled pixels
     roi_stats = str(grass.read_command("r.univar", flags=("g"), map = roi))
-    roi_stats = roi_stats.split('\r\n')[0]
+    if os.name == "nt":
+        roi_stats = roi_stats[0:len(roi_stats)-2] # to remove the last line ending and return characters
+        roi_stats = roi_stats.split('\r\n')[0]
+    else:
+        roi_stats = roi_stats[0:len(roi_stats)-1] # to remove the last line ending and return characters
+        roi_stats = roi_stats.split('\n')[0]
+
     ncells = str(roi_stats).split('=')[1]
     nlabel_pixels = int(ncells)
     



More information about the grass-commit mailing list