Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge branch 'print'
Browse files Browse the repository at this point in the history
  • Loading branch information
huikyole committed Oct 3, 2019
2 parents cdd0ad3 + b680bee commit 2581d13
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
6 changes: 3 additions & 3 deletions docs/source/ocw/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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::

Expand Down
4 changes: 3 additions & 1 deletion obs4MIPs/Toolbox/CMORresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from __future__ import print_function

import netCDF4
import re
import pdb
Expand All @@ -34,7 +36,7 @@ def __init__( self, inpath, table, entry=None ):
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()

Expand Down
15 changes: 8 additions & 7 deletions obs4MIPs/Toolbox/ESGFexcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from __future__ import print_function

import pdb
import xlrd
Expand All @@ -39,8 +40,8 @@ def __init__(self,excelFile):
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')
Expand All @@ -55,7 +56,7 @@ def __init__(self,excelFile):
for i in arange(sheet.nrows-1) + 1] ] )
pdb.set_trace()
self.ReadXCL()
print self.resources.keys()
print(self.resources.keys())

def ReadXCL(self):
'''
Expand All @@ -64,14 +65,14 @@ def ReadXCL(self):
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')
Expand Down
19 changes: 10 additions & 9 deletions obs4MIPs/Toolbox/ESGFresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from __future__ import print_function

import pdb
import shutil
Expand Down Expand Up @@ -83,14 +84,14 @@ def ReadXCL(self):
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')
Expand Down Expand Up @@ -184,23 +185,23 @@ 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
# ------------------
Attr=CMORAttributes( file )
DelGlbAttributes=eval(rc['DelGlbAttributes'].\
replace('\\','\''))
for attribute in DelGlbAttributes:
print "Deleting attribute: %s" % attribute
print("Deleting attribute: {}".format(attribute))
Attr.GlbDel(attribute)
# -----------------
# set attributes
# ------------------
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()

Expand All @@ -221,8 +222,8 @@ def movefiles(rc):
# -----------
# Move files
# -----------
print file
print newfilename
print(file)
print(newfilename)
os.rename(file,newfilename)


Expand Down
6 changes: 4 additions & 2 deletions obs4MIPs/factory/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#
# Select the right handler depending on the file format

from __future__ import print_function

import os
import pdb
import sys
Expand Down Expand Up @@ -220,7 +222,7 @@ def open(self, file, variable=None):
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
Expand Down Expand Up @@ -252,7 +254,7 @@ def getData(self, variable=None):
# 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)
Expand Down
38 changes: 20 additions & 18 deletions obs4MIPs/obs4MIPs_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# specific language governing permissions and limitations
# under the License.

from __future__ import print_function

import cdms2
import cdtime
import cmor
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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()

# ********************************************************************
#
Expand Down

0 comments on commit 2581d13

Please sign in to comment.