[cmor] 04/13: more changes to python3

Alastair McKinstry mckinstry at moszumanska.debian.org
Thu Apr 20 10:37:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch debian/master
in repository cmor.

commit 37cf4a70e42fb8aa637e97dbbb362b7774be095c
Author: Alastair McKinstry <mckinstry at debian.org>
Date:   Tue Dec 20 12:33:15 2016 +0000

    more changes to python3
---
 debian/patches/python3.patch | 342 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 339 insertions(+), 3 deletions(-)

diff --git a/debian/patches/python3.patch b/debian/patches/python3.patch
index 40b8cf7..f692db3 100644
--- a/debian/patches/python3.patch
+++ b/debian/patches/python3.patch
@@ -270,6 +270,42 @@ Index: cmor-3.2.1/Lib/pywrapper.py
      else:
          if has_cdms2 and isinstance(coord_vals,cdms2.axis.TransientAxis):
              if units is None:
+@@ -296,10 +300,10 @@ def axis(table_entry,units=None,length=N
+             coord_vals = numpy.ascontiguousarray(coord_vals.filled())
+ 
+         if not isinstance(coord_vals,numpy.ndarray):
+-            raise Exception, "Error coord_vals must be an array or cdms2 axis or list/tuple"
++            raise Exception("Error coord_vals must be an array or cdms2 axis or list/tuple")
+ 
+         if numpy.ndim(coord_vals)>1:
+-            raise Exception, "Error, you must pass a 1D array!"
++            raise Exception("Error, you must pass a 1D array!")
+ 
+     if numpy.ma.isMA(cell_bounds):
+         cell_bounds = numpy.ascontiguousarray(cell_bounds.filled())
+@@ -314,18 +318,18 @@ def axis(table_entry,units=None,length=N
+ 
+     if cell_bounds is not None:
+         if numpy.ndim(cell_bounds)>2:
+-            raise Exception, "Error cell_bounds rank must be at most 2"
++            raise Exception("Error cell_bounds rank must be at most 2")
+         if numpy.ndim(cell_bounds)==2:
+             if cell_bounds.shape[0]!=coord_vals.shape[0]:
+-                raise Exception, "Error, coord_vals and cell_bounds do not have the same length"
++                raise Exception("Error, coord_vals and cell_bounds do not have the same length")
+             if cell_bounds.shape[1]!=2:
+-                raise Exception, "Error, cell_bounds' second dimension must be of length 2"
++                raise Exception("Error, cell_bounds' second dimension must be of length 2")
+             cbnds = 2
+             cell_bounds = numpy.ascontiguousarray(numpy.ravel(cell_bounds))
+         else:
+             cbnds = 1
+             if len(cell_bounds)!=len(coord_vals)+1:
+-                raise Exception, "error cell_bounds are %i long and axes coord_vals are %i long this is not consistent" % (len(cell_bounds),len(coord_vals))
++                raise Exception("error cell_bounds are %i long and axes coord_vals are %i long this is not consistent" % (len(cell_bounds),len(coord_vals)))
+     else:
+         cbnds = 0
+ 
 @@ -334,7 +338,7 @@ def axis(table_entry,units=None,length=N
          type = coord_vals.dtype.char[0]
  
@@ -288,6 +324,61 @@ Index: cmor-3.2.1/Lib/pywrapper.py
          else:
              units = "1"
  
+@@ -369,26 +373,26 @@ def axis(table_entry,units=None,length=N
+ def variable(table_entry,units,axis_ids,type='f',missing_value=None,tolerance = 1.e-4,positive=None,original_name=None,history=None,comment=None):
+ 
+     if not isinstance(table_entry,str):
+-        raise Exception, "Error you must pass a string for the variable table_entry"
++        raise Exception("Error you must pass a string for the variable table_entry")
+ 
+     if not isinstance(units,str):
+-        raise Exception, "Error you must pass a string for the variable units"
++        raise Exception("Error you must pass a string for the variable units")
+ 
+     if original_name is not None:
+         if not isinstance(original_name,str):
+-            raise Exception, "Error you must pass a string for the variable original_name"
++            raise Exception("Error you must pass a string for the variable original_name")
+     else:
+         original_name = ""
+ 
+     if history is not None:
+         if not isinstance(history,str):
+-            raise Exception, "Error you must pass a string for the variable history"
++            raise Exception("Error you must pass a string for the variable history")
+     else:
+         history = ""
+ 
+     if comment is not None:
+         if not isinstance(comment,str):
+-            raise Exception, "Error you must pass a string for the variable comment"
++            raise Exception("Error you must pass a string for the variable comment")
+     else:
+         comment = ""
+ 
+@@ -401,18 +405,18 @@ def variable(table_entry,units,axis_ids,
+     elif isinstance(axis_ids,(list,tuple)):
+         axis_ids = numpy.ascontiguousarray(axis_ids)
+     elif not isinstance(axis_ids, numpy.ndarray):
+-        raise Exception, "Error could not convert axis_ids list to a numpy array"
++        raise Exception("Error could not convert axis_ids list to a numpy array")
+ 
+     if numpy.ndim(axis_ids)>1:
+-        raise Exception, "error axis_ids list/array must be 1D"
++        raise Exception("error axis_ids list/array must be 1D")
+ 
+     if not isinstance(type,str):
+-        raise Exception, "error tpye must a a string"
++        raise Exception("error tpye must a a string")
+     type = type.lower()
+     if type == 's':
+         type ='c'
+     if not type in ["c","d","f","l","i"]:
+-        raise Exception, 'error unknown type: "%s", must be one of: "c","d","f","l","i"'
++        raise Exception('error unknown type: "%s", must be one of: "c","d","f","l","i"')
+ 
+     ndims = len(axis_ids)
+ 
 @@ -432,13 +436,13 @@ def variable(table_entry,units,axis_ids,
          comment = str(comment)
  
@@ -304,6 +395,37 @@ Index: cmor-3.2.1/Lib/pywrapper.py
  
          missing_value = float(missing_value)
  
+@@ -448,14 +452,14 @@ def variable(table_entry,units,axis_ids,
+ def zfactor(zaxis_id,zfactor_name,units="",axis_ids=None,type=None,zfactor_values=None,zfactor_bounds=None):
+ 
+     if not isinstance(zaxis_id,(int,numpy.int,numpy.int32)):
+-        raise Exception, "error zaxis_id must be a number"
++        raise Exception("error zaxis_id must be a number")
+     zaxis_id = int(zaxis_id)
+ 
+     if not isinstance(zfactor_name,str):
+-        raise Exception, "Error you must pass a string for the variable zfactor_name"
++        raise Exception("Error you must pass a string for the variable zfactor_name")
+ 
+     if not isinstance(units,str):
+-        raise Exception, "Error you must pass a string for the variable units"
++        raise Exception("Error you must pass a string for the variable units")
+ 
+     if numpy.ma.isMA(axis_ids):
+         axis_ids = numpy.ascontiguousarray(axis_ids.filled())
+@@ -472,10 +476,10 @@ def zfactor(zaxis_id,zfactor_name,units=
+     elif isinstance(axis_ids,(int,numpy.int,numpy.int32)):
+         axis_ids = numpy.array([axis_ids,])
+     elif not isinstance(axis_ids, numpy.ndarray):
+-        raise Exception, "Error could not convert axis_ids list to a numpy array"
++        raise Exception("Error could not convert axis_ids list to a numpy array")
+ 
+     if numpy.ndim(axis_ids)>1:
+-        raise Exception, "error axis_ids list/array must be 1D"
++        raise Exception("error axis_ids list/array must be 1D")
+ 
+     if axis_ids is None:
+         ndims = 0
 @@ -484,9 +488,9 @@ def zfactor(zaxis_id,zfactor_name,units=
          ndims = len(axis_ids)
  
@@ -325,6 +447,52 @@ Index: cmor-3.2.1/Lib/pywrapper.py
  
          if type is None:
              try:
+@@ -511,18 +515,18 @@ def zfactor(zaxis_id,zfactor_name,units=
+                 elif isinstance(zfactor_values,(int,numpy.int,numpy.int32)):
+                     type = 'd'
+                 else:
+-                    raise Exception, "Error unknown type for zfactor_values: %s" % repr(zfactor_values)
++                    raise Exception("Error unknown type for zfactor_values: %s" % repr(zfactor_values))
+     elif type is None:
+         type='d'
+ 
+ 
+     if not isinstance(type,str):
+-        raise Exception, "error tpye must a a string"
++        raise Exception("error tpye must a a string")
+     type = type.lower()
+     if type == 's':
+         type ='c'
+     if not type in ["c","d","f","l","i"]:
+-        raise Exception, 'error unknown type: "%s", must be one of: "c","d","f","l","i"'
++        raise Exception('error unknown type: "%s", must be one of: "c","d","f","l","i"')
+ 
+     if zfactor_bounds is not None:
+         if numpy.ma.isMA(zfactor_bounds):
+@@ -534,19 +538,19 @@ def zfactor(zaxis_id,zfactor_name,units=
+         elif isinstance(zfactor_bounds,(list,tuple)):
+             zfactor_bounds = numpy.ascontiguousarray(zfactor_bounds)
+         elif not isinstance(zfactor_bounds, numpy.ndarray):
+-            raise Exception, "Error could not convert zfactor_bounds to a numpy array"
++            raise Exception("Error could not convert zfactor_bounds to a numpy array")
+         if numpy.ndim(zfactor_bounds)>2:
+-            raise Exception, "error zfactor_bounds must be rank 2 at most"
++            raise Exception("error zfactor_bounds must be rank 2 at most")
+         elif numpy.ndim(zfactor_bounds)==2:
+             if zfactor_bounds.shape[1]!=2:
+-                raise Exception, "error zfactor_bounds' 2nd dimension must be of length 2"
++                raise Exception("error zfactor_bounds' 2nd dimension must be of length 2")
+             bnds =[]
+             b = zfactor_bounds[0]
+             for i in range(zfactor_bounds.shape[0]):
+                 b = zfactor_bounds[i]
+                 bnds.append(b[0])
+                 if (i<zfactor_bounds.shape[0]-1) and (b[1]!=zfactor_bounds[i+1][0]):
+-                    raise Exception, "error zfactor_bounds have gaps between them"
++                    raise Exception("error zfactor_bounds have gaps between them")
+             bnds.append(zfactor_bounds[-1][1])
+             zfactor_bounds=numpy.array(bnds)
+     axis_ids = axis_ids.astype('i')
 @@ -561,15 +565,15 @@ def write(var_id,data,ntimes_passed=None
      ierr = write(var_id,data,ntimes_passed=None,file_suffix="",time_vals=None,time_bnds=None,store_with=None
      """
@@ -377,6 +545,32 @@ Index: cmor-3.2.1/Lib/pywrapper.py
      ntimes_passed = int(ntimes_passed)
  
  
+@@ -637,7 +641,7 @@ def write(var_id,data,ntimes_passed=None
+         if goodshape[i]!=0:
+             if sh[j]!=goodshape[i]:
+                 if goodshape[i]!=1:
+-                    raise Exception,"Error: your data shape (%s) does not match the expected variable shape (%s)\nCheck your variable dimensions before caling cmor_write" % (str(osh),str(ogoodshape))
++                    raise Exception("Error: your data shape (%s) does not match the expected variable shape (%s)\nCheck your variable dimensions before caling cmor_write" % (str(osh),str(ogoodshape)))
+             j+=1
+         elif ntimes_passed!=1:
+             j+=1
+@@ -659,13 +663,13 @@ def write(var_id,data,ntimes_passed=None
+         elif isinstance(time_bnds,(list,tuple)):
+             time_bnds = numpy.ascontiguousarray(time_bnds)
+         elif not isinstance(time_bnds, numpy.ndarray):
+-            raise Exception, "Error could not convert time_bnds to a numpy array"
++            raise Exception("Error could not convert time_bnds to a numpy array")
+ 
+         if numpy.ndim(time_bnds)>2:
+-            raise Exception, "bounds rank cannot be greater than 2"
++            raise Exception("bounds rank cannot be greater than 2")
+         elif numpy.ndim(time_bnds)==2:
+             if time_bnds.shape[1]!=2:
+-                raise Exception, "error time_bnds' 2nd dimension must be of length 2"
++                raise Exception("error time_bnds' 2nd dimension must be of length 2")
+             bnds =[]
+             if time_bnds.shape[0] > 1:
+                 _check_time_bounds_contiguous(time_bnds)
 @@ -679,7 +683,7 @@ def write(var_id,data,ntimes_passed=None
              else:
                  ltv=len(time_vals)
@@ -437,16 +631,28 @@ Index: cmor-3.2.1/Lib/pywrapper.py
      return _cmor.setup(inpath,netcdf_file_action,set_verbosity,exit_control,logfile,create_subdirectories)
  
  def load_table(table):
-@@ -754,7 +758,7 @@ def load_table(table):
+@@ -754,9 +758,9 @@ def load_table(table):
      load_table(table)
      """
      if not isinstance(table,str):
 -        raise Exception, "Error, must pass a string"
 +        raise Exception("Error, must pass a string")
  ##     if not os.path.exists(table):
- ##         raise Exception, "Error, the table you specified (%s) does not exists" % table
+-##         raise Exception, "Error, the table you specified (%s) does not exists" % table
++##         raise Exception("Error, the table you specified (%s) does not exists" % table)
      return _cmor.load_table(table)
-@@ -772,7 +776,7 @@ def dataset_json(rcfile):
+ 
+ def dataset_json(rcfile):
+@@ -765,14 +769,14 @@ def dataset_json(rcfile):
+     dataset_json(rcfile)
+     """
+     if not isinstance(rcfile,str):
+-        raise Exception, "Error, must pass a string"
++        raise Exception("Error, must pass a string")
+ ##     if not os.path.exists(table):
+-##         raise Exception, "Error, the table you specified (%s) does not exists" % table
++##         raise Exception("Error, the table you specified (%s) does not exists" % table)
+     return _cmor.dataset_json(rcfile)
  
  def set_table(table):
      if not isinstance(table,int):
@@ -2711,3 +2917,133 @@ Index: cmor-3.2.1/Src/_controlvocabulary.c
 +#endif
  }
  
+Index: cmor-3.2.1/Lib/convertCSVFile.py
+===================================================================
+--- cmor-3.2.1.orig/Lib/convertCSVFile.py
++++ cmor-3.2.1/Lib/convertCSVFile.py
+@@ -1,3 +1,4 @@
++from __future__ import print_function
+ import csv
+ import re
+ import pdb
+@@ -48,8 +49,8 @@ expt_template ="""
+                                "parent_mip_era ":           "CMIP6"
+                           },
+ """
+-print "{"
+-print "    \"experiment_ids\": { "
++print ("{")
++print ("    \"experiment_ids\": { ")
+ with open('../Tables/CMIP6_expt_list_062116.csv', 'rU') as csvfile:
+     spamreader = csv.reader(csvfile, dialect=csv.excel)
+     for row in spamreader:
+@@ -58,7 +59,7 @@ with open('../Tables/CMIP6_expt_list_062
+     expt = ""
+     for  row in spamreader:    
+ ##        if (row[5] == "") & (row[22] != ""):
+-##            print i
++##            print (i)
+         if (row[9] != "" ):
+             expt = expt + expt_template
+             expt = replaceString(expt, row[9], "experiment_id")
+@@ -83,4 +84,4 @@ with open('../Tables/CMIP6_expt_list_062
+ #nexpt = expt + "\"Dummy\":{}\n     }"
+ expt = expt + "\n    }\n}"
+ expt = deleteComa(expt )
+-print expt
++print (expt)
+Index: cmor-3.2.1/LibCV/pywrapper.py
+===================================================================
+--- cmor-3.2.1.orig/LibCV/pywrapper.py
++++ cmor-3.2.1/LibCV/pywrapper.py
+@@ -44,7 +44,7 @@ def _to_numpy(vals, message):
+         try:
+             vals = numpy.ascontiguousarray(vals.filled())
+         except:
+-            raise Exception, "Error could not convert %s to a numpy array" % message
++            raise Exception("Error could not convert %s to a numpy array" % message)
+ 
+     return vals
+ 
+@@ -64,19 +64,19 @@ def setup(inpath='.',
+     if not isinstance(exit_control,int) or not exit_control in [ cmor_const.CMOR_EXIT_ON_WARNING,
+                                                                  cmor_const.CMOR_EXIT_ON_MAJOR,
+                                                                  cmor_const.CMOR_NORMAL]:
+-        raise Exception, "exit_control must an integer valid values are: CMOR_EXIT_ON_WARNING, " \
+-                         "CMOR_EXIT_ON_MAJOR, CMOR_NORMAL"
++        raise Exception("exit_control must an integer valid values are: CMOR_EXIT_ON_WARNING, " \
++                         "CMOR_EXIT_ON_MAJOR, CMOR_NORMAL")
+ 
+     if not isinstance(set_verbosity, int) or not set_verbosity in [ cmor_const.CMOR_QUIET, cmor_const.CMOR_NORMAL]:
+-        raise Exception, "set_verbosity must an integer valid values are: CMOR_QUIET, CMOR_NORMAL"
++        raise Exception("set_verbosity must an integer valid values are: CMOR_QUIET, CMOR_NORMAL")
+ 
+     if not isinstance(inpath, str) and not os.path.exists(inpath):
+-        raise Exception, "path must be a Valid path"
++        raise Exception("path must be a Valid path")
+     if logfile is None:
+         logfile = ""
+ 
+     if create_subdirectories not in [0, 1]:
+-        raise Exception, "create_subdirectories must be 0 or 1"
++        raise Exception("create_subdirectories must be 0 or 1")
+     CMOR_PRESERVE = 10
+     return(_cmip6_cv.setup(inpath, CMOR_PRESERVE, set_verbosity, exit_control, logfile, create_subdirectories))
+ 
+@@ -87,15 +87,15 @@ def load_table(table):
+     load_table(table)
+     """
+     if not isinstance(table, str):
+-        raise Exception, "Error, must pass a string"
++        raise Exception("Error, must pass a string")
+ #     if not os.path.exists(table):
+-#         raise Exception, "Error, the table you specified (%s) does not exists" % table
++#         raise Exception("Error, the table you specified (%s) does not exists" % table)
+     return _cmip6_cv.load_table(table)
+ 
+ 
+ def set_table(table):
+     if not isinstance(table, int):
+-        raise Exception, "error you need to pass and integer as the table id"
++        raise Exception("error you need to pass and integer as the table id")
+     return(_cmip6_cv.set_table(table))
+ 
+ 
+@@ -111,7 +111,7 @@ def close(var_id=None, file_name=False,
+                   definition in CMOR to write more data with this variable (into a new file)
+       """
+     if var_id is not None and not isinstance(var_id, int):
+-        raise Exception, "Error var_id must be None or a integer"
++        raise Exception("Error var_id must be None or a integer")
+ 
+     if (preserve is False):
+         if (file_name is False):
+Index: cmor-3.2.1/Test/test_doc.py
+===================================================================
+--- cmor-3.2.1.orig/Test/test_doc.py
++++ cmor-3.2.1/Test/test_doc.py
+@@ -1,3 +1,4 @@
++from __future__ import print_function
+ import cmor
+ 
+ cmor.setup(inpath='Tables',netcdf_file_action=cmor.CMOR_REPLACE_4)
+@@ -25,7 +26,7 @@ axis_ids = [itime,ilat,ilon]
+ varid = cmor.variable('ts', 'K', axis_ids)
+ cmor.write(varid, [273])
+ outfile=cmor.close(varid, file_name=True)
+-print "File written: ",outfile
++print("File written: ",outfile)
+ cmor.close()
+ 
+ 
+Index: cmor-3.2.1/LibCV/__init__.py
+===================================================================
+--- cmor-3.2.1.orig/LibCV/__init__.py
++++ cmor-3.2.1/LibCV/__init__.py
+@@ -1,4 +1,4 @@
+-from cmor_const import *
++from .cmor_const import *
+ 
+-from pywrapper import setup, load_table, set_table, close, set_cur_dataset_attribute, get_cur_dataset_attribute, has_cur_dataset_attribute, set_variable_attribute, list_variable_attributes, get_variable_attribute, has_variable_attribute, check_institution, check_sourceID, check_experiment, check_grids, check_requiredattributes, check_ISOTime, check_furtherinfourl, get_CV_Error, setup_variable, set_CV_Error
++from .pywrapper import setup, load_table, set_table, close, set_cur_dataset_attribute, get_cur_dataset_attribute, has_cur_dataset_attribute, set_variable_attribute, list_variable_attributes, get_variable_attribute, has_variable_attribute, check_institution, check_sourceID, check_experiment, check_grids, check_requiredattributes, check_ISOTime, check_furtherinfourl, get_CV_Error, setup_variable, set_CV_Error
+ 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cmor.git



More information about the debian-science-commits mailing list