Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SyntaxError issues with Python 3. #549

Merged
merged 1 commit into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/python/m.distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ def main():
segment_distance = G_distance(x[i-1], y[i-1], x[i], y[i])
overall_distance += segment_distance

print "segment %d distance is %.2f meters" % (i, segment_distance)
print("segment %d distance is %.2f meters" % (i, segment_distance))

# add to the area array

print "\ntotal distance is %.2f meters\n" % overall_distance
print("\ntotal distance is %.2f meters\n" % overall_distance)

# calc area
if len(coords) < 3:
Expand All @@ -136,7 +136,7 @@ def main():

# do not need to close polygon (but it doesn't hurt if you do)
area = G_area_of_polygon(x, y, len(coords))
print "area is %.2f square meters\n" % area
print("area is %.2f square meters\n" % area)

# we don't need this, but just to have a look
if proj_type == 1:
Expand Down
8 changes: 4 additions & 4 deletions doc/python/raster_example_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@
ptype = POINTER(c_double)
type_name = 'DCELL'

print "Raster map <%s> contains data type %s." % (input, type_name)
print("Raster map <%s> contains data type %s." % (input, type_name))

in_fd = Rast_open_old(input, mapset)
in_rast = Rast_allocate_buf(data_type)
in_rast = cast(c_void_p(in_rast), ptype)

rows = Rast_window_rows()
cols = Rast_window_cols()
print "Current region is %d rows x %d columns" % (rows, cols)
print("Current region is %d rows x %d columns" % (rows, cols))

# iterate through map rows
print "Map data:"
print("Map data:")
for row_n in range(rows):
# read a row of raster data into memory, then print it
Rast_get_row(in_fd, in_rast, row_n, data_type)
print row_n, in_rast[0:cols]
print(row_n, in_rast[0:cols])
# TODO check for NULL

# closed map and cleanup memory allocation
Expand Down
20 changes: 10 additions & 10 deletions doc/python/vector_example_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
Vect_open_old(map_info, input, mapset)

# query
print 'Vector map :', Vect_get_full_name(map_info)
print 'Vector is 3D :', Vect_is_3d(map_info)
print 'Vector DB links :', Vect_get_num_dblinks(map_info)
print 'Map Scale : 1:%d' % Vect_get_scale(map_info)
print('Vector map :', Vect_get_full_name(map_info))
print('Vector is 3D :', Vect_is_3d(map_info))
print('Vector DB links :', Vect_get_num_dblinks(map_info))
print('Map Scale : 1:%d' % Vect_get_scale(map_info))

# vector box tests
box = bound_box()
Expand All @@ -48,13 +48,13 @@
c_easting2 = 4599505.0

Vect_get_map_box(map_info, byref(box))
print 'Position 1 in box ?', Vect_point_in_box(c_easting1, c_northing, 0, byref(box))
print 'Position 2 in box ?', Vect_point_in_box(c_easting2, c_northing, 0, byref(box))
print('Position 1 in box ?', Vect_point_in_box(c_easting1, c_northing, 0, byref(box)))
print('Position 2 in box ?', Vect_point_in_box(c_easting2, c_northing, 0, byref(box)))

print 'Number of features:', Vect_get_num_lines(map_info)
print 'Number of points :', Vect_get_num_primitives(map_info, GV_POINT)
print 'Number of lines :', Vect_get_num_primitives(map_info, GV_LINE)
print 'Number of areas :', Vect_get_num_areas(map_info)
print('Number of features:', Vect_get_num_lines(map_info))
print('Number of points :', Vect_get_num_primitives(map_info, GV_POINT))
print('Number of lines :', Vect_get_num_primitives(map_info, GV_LINE))
print('Number of areas :', Vect_get_num_areas(map_info))

# close map
Vect_close(map_info)
44 changes: 22 additions & 22 deletions imagery/i.atcorr/create_iwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@

def usage():
"""How to use this..."""
print "create_iwave.py <csv file>"
print("create_iwave.py <csv file>")
print
print "Generates filter function template for iwave.cpp from csv file. Note:"
print "- csv file must have wl response for each band in each column"
print "- first line must be a header with wl followed by band names"
print "- all following lines will be the data."
print "If spectral response is null, leave field empty in csv file. Example:"
print("Generates filter function template for iwave.cpp from csv file. Note:")
print("- csv file must have wl response for each band in each column")
print("- first line must be a header with wl followed by band names")
print("- all following lines will be the data.")
print("If spectral response is null, leave field empty in csv file. Example:")
print
print "WL(nm),band 1,band 2,band 3,band 4"
print "455,0.93,,,"
print "485,0.94,0.00,,"
print "545,0.00,0.87,0.00,"
print("WL(nm),band 1,band 2,band 3,band 4")
print("455,0.93,,,")
print("485,0.94,0.00,,")
print("545,0.00,0.87,0.00,")
print
print "This script will interpolate the filter functions to 2.5 nm steps"
print "and output a cpp template file in the IWave format to be added to iwave.cpp"
print("This script will interpolate the filter functions to 2.5 nm steps")
print("and output a cpp template file in the IWave format to be added to iwave.cpp")

def read_input(csvfile):
"""
Expand All @@ -64,7 +64,7 @@ def read_input(csvfile):
bands = infile.readline().split(',')
bands.remove(bands[0])
bands[-1] = bands[-1].strip()
print " > Number of bands found: %d" % len(bands)
print(" > Number of bands found: %d" % len(bands))
infile.close()

# create converter dictionary for import
Expand Down Expand Up @@ -197,7 +197,7 @@ def write_cpp(bands, values, sensor, folder):
# keep in sync with IWave::parse()
rthresh = 0.01
print
print " > Response peaks from interpolation to 2.5 nm steps:"
print(" > Response peaks from interpolation to 2.5 nm steps:")

# getting necessary data
# single or multiple bands?
Expand All @@ -218,7 +218,7 @@ def write_cpp(bands, values, sensor, folder):
while c < len(fi) - 1 and fi[c + 1] > rthresh:
c = c + 1
max_wavelength = np.floor(li[0] * 1000 + (2.5 * c))
print " %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength)
print(" %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength))

else:
filter_f = []
Expand All @@ -240,7 +240,7 @@ def write_cpp(bands, values, sensor, folder):
while c < len(fi) - 1 and fi[c + 1] > rthresh:
c = c + 1
max_wavelength = np.floor(li[0] * 1000 + (2.5 * c))
print " %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength)
print(" %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength))

# writing...
outfile = open(os.path.join(folder, sensor+"_cpp_template.txt"), 'w')
Expand Down Expand Up @@ -314,7 +314,7 @@ def main():
sensor = os.path.splitext(os.path.basename(inputfile))[0]

print
print " > Getting sensor name from csv file: %s" % (sensor)
print(" > Getting sensor name from csv file: %s" % (sensor))

# getting data from file
bands, values = read_input(inputfile)
Expand All @@ -324,7 +324,7 @@ def main():
# around the peak response, keep in sync with IWave::parse()
rthresh = 0.01
print
print " > Response peaks from input file:"
print(" > Response peaks from input file:")
for b in range(1, len(bands) + 1):
lowl = 0
hiwl = 0
Expand All @@ -346,15 +346,15 @@ def main():
hiwl = values[i,0]
i += 1

print " %s (%inm - %inm)" % (bands[b - 1], lowl, hiwl)
print(" %s (%inm - %inm)" % (bands[b - 1], lowl, hiwl))

# writing file in same folder of input file
write_cpp(bands, values, sensor, os.path.dirname(inputfile))

print
print " > Filter functions exported to %s" % ("sensors_csv/"+sensor+"_cpp_template.txt")
print " > Please check this file for possible errors before inserting the code into file iwave.cpp"
print " > Don't forget to add the necessary data to the files iwave.h, geomcond.h, geomcond.cpp, and to i.atcorr.html"
print(" > Filter functions exported to %s" % ("sensors_csv/"+sensor+"_cpp_template.txt"))
print(" > Please check this file for possible errors before inserting the code into file iwave.cpp")
print(" > Don't forget to add the necessary data to the files iwave.h, geomcond.h, geomcond.cpp, and to i.atcorr.html")
print

return
Expand Down