Skip to content

Commit

Permalink
i.landsat8.swlst: py3 fixes for print() statements
Browse files Browse the repository at this point in the history
  • Loading branch information
neteler committed Sep 26, 2019
1 parent ab4242d commit 9168acb
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 190 deletions.
55 changes: 28 additions & 27 deletions grass7/imagery/i.landsat8.swlst/csv_to_dictionary.py
Expand Up @@ -40,6 +40,7 @@
import csv
from collections import namedtuple
import random
from functools import reduce


# helper functions
Expand Down Expand Up @@ -263,7 +264,7 @@ def main():

if set_csvfile():
CSVFILE = set_csvfile()
print " * Reading comma separated values from:", CSVFILE
print(" * Reading comma separated values from:", CSVFILE)

else:
raise IOError('Please define a file to read comma-separated-values from!')
Expand All @@ -278,7 +279,7 @@ def main():
if set_csvfile():
msg = ' > Dictionary with coefficients '
msg += str('(note, it contains named tuples):\n\n')
print msg, coefficients_dictionary
print(msg, coefficients_dictionary)

# return the dictionary with coefficients
return coefficients_dictionary
Expand All @@ -291,37 +292,37 @@ def test_csvfile(infile):
'''
global CSVFILE
CSVFILE = infile
print "CSVFILE (global variable) = ", CSVFILE
print("CSVFILE (global variable) = ", CSVFILE)

print 'Test helper and main functions using as input a csv file.'
print
print('Test helper and main functions using as input a csv file.')
print()

number = random.randint(1., 10.)
print " * Testing helper function 'is_number':", is_number(number)
print(" * Testing helper function 'is_number':", is_number(number))

if not infile:
csvfile = "average_emissivity.csv"
else:
csvfile = infile

print " * Testing 'csv_reader' on", csvfile, ":\n\n", csv_reader(csvfile)
print
print(" * Testing 'csv_reader' on", csvfile, ":\n\n", csv_reader(csvfile))
print()

csvstring = csv_reader(csvfile)
print " * Testing 'csv_to_dictionary':\n\n", csv_to_dictionary(csvstring)
print
print(" * Testing 'csv_to_dictionary':\n\n", csv_to_dictionary(csvstring))
print()

d = csv_to_dictionary(csvstring)
somekey = random.choice(d.keys())
print "* Some random key:", somekey
somekey = random.choice(list(d.keys()))
print("* Some random key:", somekey)

fields = d[somekey]._fields
print "* Fields of namedtuple:", fields
print("* Fields of namedtuple:", fields)

random_field = random.choice(fields)
print "* Some random field:", random_field
print("* Some random field:", random_field)
# print "* Return values (namedtuple):", d[somekey].TIRS10, d[somekey].TIRS11
print "* Return values (namedtuple):", ('subrange', d[somekey].subrange,
print("* Return values (namedtuple):", ('subrange', d[somekey].subrange,
'b0', d[somekey].b0,
'b1', d[somekey].b1,
'b2', d[somekey].b2,
Expand All @@ -330,7 +331,7 @@ def test_csvfile(infile):
'b5', d[somekey].b5,
'b6', d[somekey].b6,
'b7', d[somekey].b7,
'rmse', d[somekey].rmse)
'rmse', d[somekey].rmse))

#test_using_file(CSVFILE) # Ucomment to run test function!
#CSVFILE = "cwv_coefficients.csv"
Expand All @@ -343,27 +344,27 @@ def test(testdata):
Test helper and main functions using as input a multi-line string.
'''
number = random.randint(1., 10.)
print " * Testing 'is_number':", is_number(number)
print
print(" * Testing 'is_number':", is_number(number))
print()

'''
Testing the process...
'''
d = csv_to_dictionary(testdata)
print "Dictionary is:\n", d
print
print("Dictionary is:\n", d)
print()

somekey = random.choice(d.keys())
print "Some random key:", somekey
print
somekey = random.choice(list(d.keys()))
print("Some random key:", somekey)
print()

fields = d[somekey]._fields
print "Fields of namedtuple:", fields
print
print("Fields of namedtuple:", fields)
print()

random_field = random.choice(fields)
print "Some random field:", random_field
print "Return values (namedtuple):", d[somekey].TIRS10, d[somekey].TIRS11
print("Some random field:", random_field)
print("Return values (namedtuple):", d[somekey].TIRS10, d[somekey].TIRS11)

testdata = '''LandCoverClass|TIRS10|TIRS11
Cropland|0.971|0.968
Expand Down
7 changes: 4 additions & 3 deletions grass7/imagery/i.landsat8.swlst/i.landsat8.swlst.py
Expand Up @@ -312,6 +312,7 @@
# required librairies
import os
import sys
from functools import reduce
sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]),
'etc', 'i.landsat8.swlst'))

Expand Down Expand Up @@ -862,7 +863,7 @@ def estimate_cwv_big_expression(outname, t10, t11, cwv_expression):
in_ti=t10, out_ti='T10',
in_tj=t11, out_tj='T11')
msg += '\n'
print msg
print(msg)

cwv_equation = equation.format(result=outname, expression=cwv_expression)
grass.mapcalc(cwv_equation, overwrite=True)
Expand Down Expand Up @@ -914,7 +915,7 @@ def estimate_lst(outname, t10, t11, avg_lse_map, delta_lse_map, cwv_map, lst_exp
if info:
msg = lst_expression
msg += '\n'
print msg
print(msg)

# replace the "dummy" string...
if landcover_map:
Expand Down Expand Up @@ -1246,7 +1247,7 @@ def main():

# print citation
if info:
print '\nSource: ' + citation_lst
print('\nSource: ' + citation_lst)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion grass7/imagery/i.landsat8.swlst/split_window_lst.py
Expand Up @@ -374,7 +374,7 @@ def get_cwv_coefficients(self):
if self.cwv_coefficients:
return self.cwv_coefficients
else:
print "* CWV coefficients have not been set!"
print("* CWV coefficients have not been set!")

def _retrieve_rmse(self, subrange):
"""
Expand Down
98 changes: 49 additions & 49 deletions grass7/imagery/i.landsat8.swlst/test_column_water_vapor.py
Expand Up @@ -25,99 +25,99 @@ def random_adjacent_pixel_values(pixel_modifiers):

def test_column_water_vapor():

print 'Equations for Column Water Vapor retrieval based on...'
print
print('Equations for Column Water Vapor retrieval based on...')
print()

print (' * Considering N adjacent pixels, the CWV in the MSWCVR method '
'is estimated as:')
print
print()
print (' cwv = c0 + c1 * (tj / ti) + c2 * (tj / ti)^2')
print
print()
print (' where:\n\n - tj/ti ~ Rji = '
'SUM [ ( Tik - Ti_mean ) * ( Tjk - Tj_mean ) ] / '
'SUM [ ( Tik - Tj_mean )^2 ]')

print
print "Testing the Column_Water_Vapor class"
print
print()
print("Testing the Column_Water_Vapor class")
print()

window_size = random_window_size()
# window_size = 7
obj = Column_Water_Vapor(window_size, 'A', 'B')
print " | Testing the '__str__' method:\n\n ", obj
print
print(" | Testing the '__str__' method:\n\n ", obj)
print()

print " | Adjacent pixels:", obj.adjacent_pixels
print
print(" | Adjacent pixels:", obj.adjacent_pixels)
print()

print " | Map Ti:", obj.ti
print(" | Map Ti:", obj.ti)

print " | Map Tj:", obj.tj
print
print(" | Map Tj:", obj.tj)
print()

print " | N pixels window modifiers for Ti:", obj.modifiers_ti
print(" | N pixels window modifiers for Ti:", obj.modifiers_ti)

print " | N pixels window Modifiers for Tj:", obj.modifiers_tj
print(" | N pixels window Modifiers for Tj:", obj.modifiers_tj)

print " | Zipped modifiers_tij (used in a function for the Ratio ji):",
print obj.modifiers
print
print(" | Zipped modifiers_tij (used in a function for the Ratio ji):", end=' ')
print(obj.modifiers)
print()

print " ~ Random N pixel values for Ti:",
print(" ~ Random N pixel values for Ti:", end=' ')
random_ti_values = random_adjacent_pixel_values(obj.modifiers_ti)
print random_ti_values
print(random_ti_values)

print " ~ Random N pixel values for Tj:",
print(" ~ Random N pixel values for Tj:", end=' ')
random_tj_values = random_adjacent_pixel_values(obj.modifiers_ti)
print random_tj_values
print(random_tj_values)

print (' ~ Testing "compute_column_water_vapor" '
'based on the above random values):'),
print obj.compute_column_water_vapor(random_ti_values, random_tj_values)
print
print((' ~ Testing "compute_column_water_vapor" '
'based on the above random values):'), end=' ')
print(obj.compute_column_water_vapor(random_ti_values, random_tj_values))
print()

print " | Expression for Ti mean:", obj.mean_ti_expression
print(" | Expression for Ti mean:", obj.mean_ti_expression)

print " | Expression for Tj mean:", obj.mean_tj_expression
print
print(" | Expression for Tj mean:", obj.mean_tj_expression)
print()

print " ~ Mean of random N pixel values for Ti:",
print sum(random_ti_values) / len(random_ti_values)
print(" ~ Mean of random N pixel values for Ti:", end=' ')
print(sum(random_ti_values) / len(random_ti_values))

print " ~ Mean of random N pixel values for Tj:",
print sum(random_tj_values) / len(random_tj_values)
print
print(" ~ Mean of random N pixel values for Tj:", end=' ')
print(sum(random_tj_values) / len(random_tj_values))
print()

print " | Note, the following mapcalc expressions use dummy strings, meant to be replaced in the main program by the names of the maps in question"
print
print(" | Note, the following mapcalc expressions use dummy strings, meant to be replaced in the main program by the names of the maps in question")
print()

print " | Expression for Numerator for Ratio (method):", obj._numerator_for_ratio('Ti_Mean', 'Tj_Mean')
print
print(" | Expression for Numerator for Ratio (method):", obj._numerator_for_ratio('Ti_Mean', 'Tj_Mean'))
print()

print (' ~ Add example for Numerator based on '
'Mean of random N pixel values for Ti, Tj:')
print
print()


print " | Expression for Denominator for Ratio (method):", obj._denominator_for_ratio('Ti_Mean')
print
print(" | Expression for Denominator for Ratio (method):", obj._denominator_for_ratio('Ti_Mean'))
print()

print (' ~ Add example for Denominator based on '
'Mean of random N pixel values for Tj:')
print
print()

print " | Ratio ji expression for mapcalc:", obj.ratio_ji_expression
print
print(" | Ratio ji expression for mapcalc:", obj.ratio_ji_expression)
print()

print (' ~ Add example for Ratio ji expression based on '
'numerator and denominator as defined above:')
print
print()

print " | One big mapcalc expression:\n\n", obj._big_cwv_expression()
print
print(" | One big mapcalc expression:\n\n", obj._big_cwv_expression())
print()

# reusable & stand-alone
if __name__ == "__main__":
print ('Testing the SplitWindowLST class')
print
print()
test_column_water_vapor()
36 changes: 18 additions & 18 deletions grass7/imagery/i.landsat8.swlst/test_landsat8_mtl.py
Expand Up @@ -16,25 +16,25 @@ def test(mtlfile):
Test the class.
"""

print "! No file defined, testing with default MTl file!"
print("! No file defined, testing with default MTl file!")
mtl = Landsat8_MTL(MTLFILE)
print

print "| Test the object's __str__ method:", mtl
print "| Test method _get_mtl_lines:\n ", mtl._get_mtl_lines()
print

print "| Basic metadata:"
print " > id (original field name is 'LANDSAT_SCENE_ID'):", mtl.scene_id
print " > WRS path:", mtl.wrs_path
print " > WRS row:", mtl.wrs_row
print " > Acquisition date:", mtl.date_acquired
print " > Scene's center time:", mtl.scene_center_time
print " > Upper left corner:", mtl.corner_ul
print " > Lower right corner:", mtl.corner_lr
print " > Upper left (projected):", mtl.corner_ul_projection
print " > Lower right (projected):", mtl.corner_lr_projection
print " > Cloud cover:", mtl.cloud_cover
print()

print("| Test the object's __str__ method:", mtl)
print("| Test method _get_mtl_lines:\n ", mtl._get_mtl_lines())
print()

print("| Basic metadata:")
print(" > id (original field name is 'LANDSAT_SCENE_ID'):", mtl.scene_id)
print(" > WRS path:", mtl.wrs_path)
print(" > WRS row:", mtl.wrs_row)
print(" > Acquisition date:", mtl.date_acquired)
print(" > Scene's center time:", mtl.scene_center_time)
print(" > Upper left corner:", mtl.corner_ul)
print(" > Lower right corner:", mtl.corner_lr)
print(" > Upper left (projected):", mtl.corner_ul_projection)
print(" > Lower right (projected):", mtl.corner_lr_projection)
print(" > Cloud cover:", mtl.cloud_cover)


def main():
Expand Down

0 comments on commit 9168acb

Please sign in to comment.