[GRASS-SVN] r73975 - in grass-addons/grass7/imagery: i.modis/i.modis.import i.segment.stats i.variance
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jan 17 22:18:31 PST 2019
Author: neteler
Date: 2019-01-17 22:18:31 -0800 (Thu, 17 Jan 2019)
New Revision: 73975
Modified:
grass-addons/grass7/imagery/i.modis/i.modis.import/i.modis.import.py
grass-addons/grass7/imagery/i.segment.stats/i.segment.stats.py
grass-addons/grass7/imagery/i.variance/i.variance.py
Log:
imagery addons: fix tab/space indentation; tabs are to be avoided, see https://trac.osgeo.org/grass/wiki/Submitting/Python?version=19#Editorsettingsfor4-spaceindentation
Modified: grass-addons/grass7/imagery/i.modis/i.modis.import/i.modis.import.py
===================================================================
--- grass-addons/grass7/imagery/i.modis/i.modis.import/i.modis.import.py 2019-01-18 05:34:41 UTC (rev 73974)
+++ grass-addons/grass7/imagery/i.modis/i.modis.import/i.modis.import.py 2019-01-18 06:18:31 UTC (rev 73975)
@@ -230,7 +230,7 @@
conf = pm.confResample(spectr, res, pref, dat, resampl,
proj, zone, projpar)
return conf
- except IOError, e:
+ except IOError as e:
grass.fatal(e)
Modified: grass-addons/grass7/imagery/i.segment.stats/i.segment.stats.py
===================================================================
--- grass-addons/grass7/imagery/i.segment.stats/i.segment.stats.py 2019-01-18 05:34:41 UTC (rev 73974)
+++ grass-addons/grass7/imagery/i.segment.stats/i.segment.stats.py 2019-01-18 06:18:31 UTC (rev 73975)
@@ -178,18 +178,18 @@
rasters = options['rasters'].split(',') if options['rasters'] else []
area_measures = options['area_measures'].split(',') if (options['area_measures'] and not flags['s']) else []
if area_measures:
- if not gscript.find_program('r.object.geometry', '--help'):
- message = _("You need to install the addon r.object.geometry to be able")
- message += _(" to calculate area measures.\n")
- message += _(" You can install the addon with 'g.extension r.object.geometry'")
- gscript.fatal(message)
+ if not gscript.find_program('r.object.geometry', '--help'):
+ message = _("You need to install the addon r.object.geometry to be able")
+ message += _(" to calculate area measures.\n")
+ message += _(" You can install the addon with 'g.extension r.object.geometry'")
+ gscript.fatal(message)
neighborhood = True if flags['n'] else False
if neighborhood:
- if not gscript.find_program('r.neighborhoodmatrix', '--help'):
- message = _("You need to install the addon r.neighborhoodmatrix to be able")
- message += _(" to calculate area measures.\n")
- message += _(" You can install the addon with 'g.extension r.neighborhoodmatrix'")
- gscript.fatal(message)
+ if not gscript.find_program('r.neighborhoodmatrix', '--help'):
+ message = _("You need to install the addon r.neighborhoodmatrix to be able")
+ message += _(" to calculate area measures.\n")
+ message += _(" You can install the addon with 'g.extension r.neighborhoodmatrix'")
+ gscript.fatal(message)
raster_statistics = options['raster_statistics'].split(',') if options['raster_statistics'] else []
separator = gscript.separator(options['separator'])
@@ -205,7 +205,7 @@
'mean': 7}
geometry_stat_dict = {'cat': 0, 'area': 1, 'perimeter': 2,
- 'compact_square': 3, 'compact_circle': 4, 'fd' : 5,
+ 'compact_square': 3, 'compact_circle': 4, 'fd' : 5,
'xcoords': 6, 'ycoords': 7}
if flags['r']:
@@ -214,23 +214,23 @@
stats_temp_file = gscript.tempfile()
if area_measures:
- gscript.message(_("Calculating geometry statistics..."))
- output_header += area_measures
- stat_indices = [geometry_stat_dict[x] for x in area_measures]
+ gscript.message(_("Calculating geometry statistics..."))
+ output_header += area_measures
+ stat_indices = [geometry_stat_dict[x] for x in area_measures]
gscript.run_command('r.object.geometry',
- input_=segment_map,
- output=stats_temp_file,
- overwrite=True,
- quiet=True)
+ input_=segment_map,
+ output=stats_temp_file,
+ overwrite=True,
+ quiet=True)
- firstline = True
- with open(stats_temp_file, 'r') as fin:
- for line in fin:
- if firstline:
- firstline = False
- continue
- values = line.rstrip().split('|')
- output_dict[values[0]] = [values[x] for x in stat_indices]
+ firstline = True
+ with open(stats_temp_file, 'r') as fin:
+ for line in fin:
+ if firstline:
+ firstline = False
+ continue
+ values = line.rstrip().split('|')
+ output_dict[values[0]] = [values[x] for x in stat_indices]
if rasters:
if not flags['c']:
@@ -286,7 +286,7 @@
# Calculating neighborhood statistics if requested
if neighborhood:
- gscript.message(_("Calculating neighborhood statistics..."))
+ gscript.message(_("Calculating neighborhood statistics..."))
# Add neighbordhood statistics to headers
original_nb_values = len(output_header) - 1
@@ -334,14 +334,14 @@
with open(csvfile, 'wb') as f:
f.write(separator.join(output_header)+"\n")
for key in output_dict:
- if len(output_dict[key]) + 1 == len(output_header):
+ if len(output_dict[key]) + 1 == len(output_header):
f.write(key+separator+separator.join(output_dict[key])+"\n")
- else:
- error_objects.append(key)
+ else:
+ error_objects.append(key)
f.close()
if vectormap:
- gscript.message(_("Creating output vector map..."))
+ gscript.message(_("Creating output vector map..."))
temporary_vect = 'segmstat_tmp_vect_%d' % os.getpid()
gscript.run_command('r.to.vect',
input_=segment_map,
@@ -365,15 +365,15 @@
addcol_statement = 'ALTER TABLE %s ADD COLUMN %s double precision;\n' % (temporary_vect, header)
fsql.write(addcol_statement)
for key in output_dict:
- if len(output_dict[key]) + 1 == len(output_header):
+ if len(output_dict[key]) + 1 == len(output_header):
sql = "INSERT INTO %s VALUES (%s, %s);\n" % (temporary_vect, key, ",".join(output_dict[key]))
sql = sql.replace('inf', 'NULL')
sql = sql.replace('nan', 'NULL')
fsql.write(sql)
- else:
- if not csvfile:
- error_objects.append(key)
-
+ else:
+ if not csvfile:
+ error_objects.append(key)
+
fsql.write('END TRANSACTION;')
fsql.close()
@@ -385,8 +385,8 @@
object_string = ', '.join(error_objects[:100])
message += _("\n\nObjects with errors (only first 100 are shown):\n%s" % object_string)
gscript.message(message)
-
+
if __name__ == "__main__":
options, flags = gscript.parser()
atexit.register(cleanup)
Modified: grass-addons/grass7/imagery/i.variance/i.variance.py
===================================================================
--- grass-addons/grass7/imagery/i.variance/i.variance.py 2019-01-18 05:34:41 UTC (rev 73974)
+++ grass-addons/grass7/imagery/i.variance/i.variance.py 2019-01-18 06:18:31 UTC (rev 73975)
@@ -2,15 +2,15 @@
############################################################################
#
-# MODULE: i.variance
-# AUTHOR(S): Moritz Lennert
+# MODULE: i.variance
+# AUTHOR(S): Moritz Lennert
#
-# PURPOSE: Calculate variation of variance by variation of resolution
-# COPYRIGHT: (C) 1997-2016 by the GRASS Development Team
+# PURPOSE: Calculate variation of variance by variation of resolution
+# COPYRIGHT: (C) 1997-2016 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.
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
#
#############################################################################
# Curtis E. Woodcock, Alan H. Strahler, The factor of scale in remote sensing,
@@ -92,18 +92,18 @@
length = len(numbers)
if length >= 2:
if numbers[0] > numbers[1]:
- maxima.append(0)
- differences.append(numbers[0] - numbers[1])
+ maxima.append(0)
+ differences.append(numbers[0] - numbers[1])
if length > 3:
for i in range(1, length-1):
if numbers[i] > numbers[i-1] and numbers[i] > numbers[i+1]:
- maxima.append(i)
- differences.append(min(numbers[i] - numbers[i-1], numbers[i] - numbers[i+1]))
+ maxima.append(i)
+ differences.append(min(numbers[i] - numbers[i-1], numbers[i] - numbers[i+1]))
- if numbers[length-1] > numbers[length-2]:
- maxima.append(length-1)
- differences.append(numbers[length-1] - numbers[length-2])
+ if numbers[length-1] > numbers[length-2]:
+ maxima.append(length-1)
+ differences.append(numbers[length-1] - numbers[length-2])
return maxima, differences
@@ -120,7 +120,7 @@
min_cells = int(options['min_cells'])
target_res = None
if options['max_size']:
- target_res = float(options['max_size'])
+ target_res = float(options['max_size'])
step = float(options['step'])
global temp_resamp_map, temp_variance_map
@@ -138,9 +138,9 @@
east = float(region['e'])
if res % 1 == 0 and step % 1 == 0:
- template_string = "%d,%f\n"
+ template_string = "%d,%f\n"
else:
- template_string = "%f,%f\n"
+ template_string = "%f,%f\n"
if min_cells:
target_res_cells = int(sqrt(((east - west) * (north - south)) / min_cells))
@@ -159,40 +159,40 @@
gscript.message(_("Calculating variance at different resolutions"))
while res <= target_res:
- gscript.percent(res, target_res, step)
- gscript.run_command('r.resamp.stats',
- input=input,
- output=temp_resamp_map,
- method='average',
- quiet=True,
- overwrite=True)
- gscript.run_command('r.neighbors',
- input=temp_resamp_map,
- method='variance',
- output=temp_variance_map,
- quiet=True,
- overwrite=True)
- varianceinfo = gscript.parse_command('r.univar',
- map_=temp_variance_map,
- flags='g',
- quiet=True)
+ gscript.percent(res, target_res, step)
+ gscript.run_command('r.resamp.stats',
+ input=input,
+ output=temp_resamp_map,
+ method='average',
+ quiet=True,
+ overwrite=True)
+ gscript.run_command('r.neighbors',
+ input=temp_resamp_map,
+ method='variance',
+ output=temp_variance_map,
+ quiet=True,
+ overwrite=True)
+ varianceinfo = gscript.parse_command('r.univar',
+ map_=temp_variance_map,
+ flags='g',
+ quiet=True)
resolutions.append(res)
- variances.append(float(varianceinfo['mean']))
- res += step
+ variances.append(float(varianceinfo['mean']))
+ res += step
region = gscript.parse_command('g.region',
- res=res,
- n=north,
- s=south,
- w=west,
- e=east,
- flags='ag')
- cells = int(region['cells'])
+ res=res,
+ n=north,
+ s=south,
+ w=west,
+ e=east,
+ flags='ag')
+ cells = int(region['cells'])
indices, differences = FindMaxima(variances)
max_resolutions = [resolutions[x] for x in indices]
gscript.message(_("resolution,min_diff"))
for i in range(len(max_resolutions)):
- print "%g,%g" % (max_resolutions[i], differences[i])
+ print("%g,%g" % (max_resolutions[i], differences[i]))
if output:
header = "resolution,variance\n"
@@ -213,7 +213,6 @@
else:
plt.savefig(plot_output)
-
if __name__ == "__main__":
options, flags = gscript.parser()
More information about the grass-commit
mailing list