You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by hu...@apache.org on 2019/10/03 16:50:16 UTC

[climate] branch master updated: update all print statements to functions

This is an automated email from the ASF dual-hosted git repository.

huikyole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/climate.git


The following commit(s) were added to refs/heads/master by this push:
     new b680bee  update all print statements to functions
     new 2581d13  Merge branch 'print'
b680bee is described below

commit b680bee070dc5e20d74bc10a725dc65431d06afa
Author: burrches <br...@gmail.com>
AuthorDate: Sat Sep 28 19:11:12 2019 -0400

    update all print statements to functions
---
 .../run_statistical_downscaling.py                 |  2 +-
 docs/source/ocw/overview.rst                       |  6 ++--
 obs4MIPs/Toolbox/CMORresources.py                  |  4 ++-
 obs4MIPs/Toolbox/ESGFexcel.py                      | 15 +++++----
 obs4MIPs/Toolbox/ESGFresources.py                  | 19 ++++++-----
 obs4MIPs/factory/formats.py                        |  6 ++--
 obs4MIPs/obs4MIPs_process.py                       | 38 ++++++++++++----------
 7 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/RCMES/statistical_downscaling/run_statistical_downscaling.py b/RCMES/statistical_downscaling/run_statistical_downscaling.py
index 18b39fe..832c283 100644
--- a/RCMES/statistical_downscaling/run_statistical_downscaling.py
+++ b/RCMES/statistical_downscaling/run_statistical_downscaling.py
@@ -91,7 +91,7 @@ if hasattr(ssl, '_create_unverified_context'):
 
 config_file = str(sys.argv[1])
 
-print 'Reading the configuration file ', config_file
+print('Reading the configuration file ', config_file)
 
 config = yaml.load(open(config_file))
 
diff --git a/docs/source/ocw/overview.rst b/docs/source/ocw/overview.rst
index 13f4aba..702f538 100644
--- a/docs/source/ocw/overview.rst
+++ b/docs/source/ocw/overview.rst
@@ -68,7 +68,7 @@ In general, it's uncommon to run a metric outside of an evaluation, however you
 >>> import ocw.metrics
 >>> # Load 2 datasets
 >>> bias = ocw.metrics.Bias()
->>> print bias.run(dataset1, dataset2)
+>>> print(bias.run(dataset1, dataset2))
 
 While this can be useful for one-off situations, it's far more likely that you'll need to run a number of metrics over a number of datasets. This is where running metrics within an evaluation comes in (covered in greater detail below).
 
@@ -141,8 +141,8 @@ When you have a large collection of datasets and a large collection of metrics t
 >>>
 >>> new_eval = eval.Evaluation(ref_dataset, target_datasets, metrics)
 >>> new_eval.run()
->>> print new_eval.results
->>> print new_eval.unary_results
+>>> print(new_eval.results)
+>>> print(new_eval.unary_results)
 
 First, we load the datasets to process and perform any necessary manipulations (which are omitted for brevity). Then, we load the metrics that we want to run (namely, ``Bias`` and ``TemporalStdDev``). We then load our evaluation object::
 
diff --git a/obs4MIPs/Toolbox/CMORresources.py b/obs4MIPs/Toolbox/CMORresources.py
index d20f971..4aab0fc 100644
--- a/obs4MIPs/Toolbox/CMORresources.py
+++ b/obs4MIPs/Toolbox/CMORresources.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from __future__ import print_function
+
 import netCDF4
 import re
 import pdb
@@ -34,7 +36,7 @@ class CMORTable:
         f=open( inpath + '/' + table, 'r')
 
         if( f == None ):
-            print "Table file %s does  not exist " % (inpath + "/" + table )
+            print("Table file {} does  not exist ".format(inpath + "/" + table))
 
         lines = f.readlines()
 
diff --git a/obs4MIPs/Toolbox/ESGFexcel.py b/obs4MIPs/Toolbox/ESGFexcel.py
index 92fd4df..e559e2a 100644
--- a/obs4MIPs/Toolbox/ESGFexcel.py
+++ b/obs4MIPs/Toolbox/ESGFexcel.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from __future__ import print_function
 
 import pdb
 import xlrd
@@ -39,8 +40,8 @@ class ESGFexcel:
         if( os.path.isfile(self.xcl) ):
                 wb=xlrd.open_workbook(self.xcl)
         else:
-           print "****** Could not find "+self.xcl+" file ****"
-           print "****** Please check excel file name ****"
+           print("****** Could not find {} file ****".format(self.xcl))
+           print("****** Please check excel file name ****")
            raise NameError(self.xcl)
 
         sheet=wb.sheet_by_name('Resources')
@@ -55,7 +56,7 @@ class ESGFexcel:
                                  for i in  arange(sheet.nrows-1) + 1] ] )
         pdb.set_trace()
         self.ReadXCL()
-        print self.resources.keys()
+        print(self.resources.keys())
 
     def ReadXCL(self):
         '''
@@ -64,14 +65,14 @@ class ESGFexcel:
         try:
            import xlrd
         except:
-           print "****** Could not find xlrd Python Package ****"
-           print "****** Please install xlrd package to read excel files ****"
+           print("****** Could not find xlrd Python Package ****")
+           print("****** Please install xlrd package to read excel files ****")
 
         if( os.path.isfile(self.xcl) ):
                 wb=xlrd.open_workbook(self.xcl)
         else:
-           print "****** Could not find "+self.xcl+" file ****"
-           print "****** Please check excel file name ****"
+           print("****** Could not find {} file ****".format(self.xcl))
+           print("****** Please check excel file name ****")
            raise NameError(self.xcl)
 
         sheet=wb.sheet_by_name('Variables')
diff --git a/obs4MIPs/Toolbox/ESGFresources.py b/obs4MIPs/Toolbox/ESGFresources.py
index ddbfe60..57378ad 100644
--- a/obs4MIPs/Toolbox/ESGFresources.py
+++ b/obs4MIPs/Toolbox/ESGFresources.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from __future__ import print_function
 
 import pdb
 import shutil
@@ -83,14 +84,14 @@ class ESGFresources:
         try:
            import xlrd
         except:
-           print "****** Could not find xlrd Python Package ****"
-           print "****** Please install xlrd package to read excel files ****"
+           print("****** Could not find xlrd Python Package ****")
+           print("****** Please install xlrd package to read excel files ****")
 
         if( os.path.isfile(self.xcl) ):
 		wb=xlrd.open_workbook(self.xcl)
         else:
-           print "****** Could not find "+self.xcl+" file ****"
-           print "****** Please check excel file name ****"
+           print("****** Could not find {} file ****".format(self.xcl))
+           print("****** Please check excel file name ****")
            raise NameError(self.xcl)
 
         sheet=wb.sheet_by_name('Variables')
@@ -184,7 +185,7 @@ def movefiles(rc):
             if files.endswith(".nc"):
                 filetimestamp = files.split('_')[-1].strip(".nc")
                 file = os.path.join(r,files)
-                print file
+                print(file)
                 # -----------------
                 # Delete attributes
                 # ------------------
@@ -192,7 +193,7 @@ def movefiles(rc):
                 DelGlbAttributes=eval(rc['DelGlbAttributes'].\
                                       replace('\\','\''))
                 for attribute in DelGlbAttributes:
-                    print "Deleting attribute: %s" % attribute
+                    print("Deleting attribute: {}".format(attribute))
                     Attr.GlbDel(attribute)
                 # -----------------
                 # set attributes
@@ -200,7 +201,7 @@ def movefiles(rc):
                 SetGlbAttributes=eval(rc['SetGlbAttributes'].\
                                       replace('\\','\''))
                 for (attribute,Value) in SetGlbAttributes:
-                    print "Assigning attribute (%s,%s)" % (attribute,Value)
+                    print("Assigning attribute ({},{})".format(attribute, Value))
                     Attr.GlbSet(attribute,Value)
                 Attr.close()
 
@@ -221,8 +222,8 @@ def movefiles(rc):
                 # -----------
                 # Move files
                 # -----------
-                print file
-                print newfilename
+                print(file)
+                print(newfilename)
                 os.rename(file,newfilename)
 
                     
diff --git a/obs4MIPs/factory/formats.py b/obs4MIPs/factory/formats.py
index ced7d74..ed5091c 100644
--- a/obs4MIPs/factory/formats.py
+++ b/obs4MIPs/factory/formats.py
@@ -19,6 +19,8 @@
 #
 #  Select the right handler depending on the file format
 
+from __future__ import print_function
+
 import os
 import pdb
 import sys
@@ -220,7 +222,7 @@ class HandlerNCAggregate(object):
         for file in self.flist:
             filename=file.strip()
             if( not os.path.exists(filename) ):
-                print "File %s does not exist in filelist" % filename
+                print("File {} does not exist in filelist".format(filename))
 
         # --------------------------------------------------------
         # Extract General information from first file in the list
@@ -252,7 +254,7 @@ class HandlerNCAggregate(object):
         # Concatenate following files
         # ---------------------------
         for filename in self.flist[ 1: ]:
-            print "reading %s" % filename.strip()
+            print("reading {}".format(filename.strip()))
             f = cdms2.open( filename.strip(), 'r' )
             data2 = f(self.vartoread)[:]
             data = numpy.concatenate((data,data2), axis=0)
diff --git a/obs4MIPs/obs4MIPs_process.py b/obs4MIPs/obs4MIPs_process.py
index 3370100..3a03c92 100755
--- a/obs4MIPs/obs4MIPs_process.py
+++ b/obs4MIPs/obs4MIPs_process.py
@@ -17,6 +17,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from __future__ import print_function
+
 import cdms2
 import cdtime
 import cmor
@@ -62,12 +64,12 @@ def process( rc ):
             except:
                 tmplFile = rc['file_template'].format(year)
             if( not os.path.isfile( tmplFile) ) :
-                print "**** Warning %s not found\n" % ( tmplFile )
+                print("**** Warning {} not found\n".format(tmplFile))
                 continue
             files= os.popen( "ls " + tmplFile).readlines()
 
         if( files == [] ):
-            print "No file found: Check your resource file"
+            print("No file found: Check your resource file")
             return -1
         # ------------------------------------------------
         # Get the right handler to manage this file format
@@ -137,13 +139,13 @@ def process( rc ):
                     variable=aVariable[j]
                     Handler.open(fnm, variable=variable)
                     rc['cvrt_original_var']   = aVariable[j]
-                    print "Working on variable %s " % variable
+                    print("Working on variable {} ".format(variable))
                 except:
                     if( aVariable[j] != 'equation' ) :
-                        print "Variable %s can't open" % variable
+                        print("Variable {} can't open".format(variable))
                         continue
                     else:
-                        print "Executing %s " % eval(rc['equation'])[j]
+                        print("Executing {} ".format(eval(rc['equation'])[j]))
                 
 #                pdb.set_trace()
                 rc['cvrt_original_units'] = eval(rc['original_units'])[j]
@@ -405,19 +407,19 @@ def usage(message):
     '''
     Describe program synopsis.
     '''
-    print
-    print "*************************"
-    print message
-    print "*************************"
-    print
-    print
-    print "obs4MIPS_process.py [-h] -r resource"
-    print "   resource:   File containing Global attributes"
-    print ""
-    print "obs4MIPS will convert an input data file into CMIP5 format using "
-    print "CMOR.  A directory path will be creating using CMOR by default or "
-    print "using a template provided in the resource file."
-    print
+    print()
+    print("*************************")
+    print(message)
+    print("*************************")
+    print()
+    print()
+    print("obs4MIPS_process.py [-h] -r resource")
+    print("   resource:   File containing Global attributes")
+    print("")
+    print("obs4MIPS will convert an input data file into CMIP5 format using ")
+    print("CMOR.  A directory path will be creating using CMOR by default or ")
+    print("using a template provided in the resource file.")
+    print()
    
 # ********************************************************************
 #