Skip to content

Commit

Permalink
Convert some python files to python3
Browse files Browse the repository at this point in the history
These aren't actually used in ESMPy so haven't been causing an issue,
but can create errors in some circumstances.

Resolves #331
  • Loading branch information
billsacks committed Dec 13, 2024
1 parent 8093deb commit 36025dd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/addon/esmpy/doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ MPI.Spawn
raise ValueError('Could not connect to parent - ' + usage)

# worker code goes here, regridding etc..
print "Hello World from PET #"+str(rank)
print("Hello World from PET #"+str(rank))

# Shutdown
comm.Disconnect()
Expand Down
5 changes: 3 additions & 2 deletions src/addon/esmpy/examples/mpi_spawn_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from esmpy.util.cache_data import DATA_DIR
from esmpy.util.exceptions import DataMissing
from functools import reduce

# The data files can be retrieved from the ESMF data repository by uncommenting the
# following block of code:
Expand Down Expand Up @@ -94,8 +95,8 @@ def compute_error(dstfield, xctfield):
meanrelerr = relerr / num_nodes

meanrelerr = relerr / num_nodes
print "ESMPy regridding as a spawned MPI process:"
print " interpolation mean relative error = {0}".format(meanrelerr)
print("ESMPy regridding as a spawned MPI process:")
print(" interpolation mean relative error = {0}".format(meanrelerr))


########################################### MAIN #############################
Expand Down
51 changes: 26 additions & 25 deletions src/addon/esmpy/src/esmpy/fragments/dump_esmf_internal_info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import reduce
# This file contains old routines to dump internal ESMF info from ESMPy Grid and Field objects
# This code is likely obsolete, but was useful in the original development process ..
# so it is being kept for a rainy day situation
Expand All @@ -6,11 +7,11 @@ def dump_gridinfo(self, stagger):

[x,y,z] = [0,1,2]

print "bounds - low, high"
print self.lower_bounds[stagger], \
self.upper_bounds[stagger]
print "shape - [x, y, z] or [lat, lon]"
print self.coords[stagger][0].shape
print("bounds - low, high")
print(self.lower_bounds[stagger], \
self.upper_bounds[stagger])
print("shape - [x, y, z] or [lat, lon]")
print(self.coords[stagger][0].shape)

if self.rank == 2:
return [self.coords[stagger][x], self.coords[stagger][y]]
Expand All @@ -20,11 +21,11 @@ def dump_gridinfo(self, stagger):
def dump_gridinfo_lower(self, stagger):
[x, y, z] = [0, 1, 2]

print "bounds - low, high"
print self.lower_bounds[stagger], \
self.upper_bounds[stagger]
print "shape - [x, y, z] or [lat, lon]"
print self.coords[stagger][0].shape
print("bounds - low, high")
print(self.lower_bounds[stagger], \
self.upper_bounds[stagger])
print("shape - [x, y, z] or [lat, lon]")
print(self.coords[stagger][0].shape)

# retrieve buffers to esmf coordinate memory
gridptrX = self.get_grid_coords_from_esmc(x, stagger)
Expand Down Expand Up @@ -67,10 +68,10 @@ def dump_gridinfo_ctypes(self, stagger, dim=2):
np.dtype(constants._ESMF2PythonType[self.type]).itemsize*size)
ycoords = np.frombuffer(ybuffer, constants._ESMF2PythonType[self.type])

print "DIAGNOSTICS:"
print "self.type = ", self.type
print "constants._ESMF2PythonType", constants._ESMF2PythonType[self.type]
print "constants._ESMF2PythonType.itemsize", constants._ESMF2PythonType[self.type].itemsize
print("DIAGNOSTICS:")
print("self.type = ", self.type)
print("constants._ESMF2PythonType", constants._ESMF2PythonType[self.type])
print("constants._ESMF2PythonType.itemsize", constants._ESMF2PythonType[self.type].itemsize)


# find the size of the local coordinates at this stagger location
Expand All @@ -80,12 +81,12 @@ def dump_gridinfo_ctypes(self, stagger, dim=2):
# these appear to both return bounds information only
lb, ub = ESMP_GridGetCoordBounds(self, staggerloc=stagger)

print "Bounds:"
print " ESMPy.Grid: ", size
print " ESMPy.ctypes1: ", lb, ub
print("Bounds:")
print(" ESMPy.Grid: ", size)
print(" ESMPy.ctypes1: ", lb, ub)


print "Coordinates:"
print("Coordinates:")
I = ub[x]-lb[x]
J = ub[y]-lb[y]
if dim == 3:
Expand All @@ -103,7 +104,7 @@ def dump_gridinfo_ctypes(self, stagger, dim=2):
(ycoords[ind] > -1e-10 and 1e-10 > ycoords[ind] and ycoords[ind] != 0) or \
ycoords[ind] > 90:

print "[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]"
print("[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]")

coordcount += 1
elif dim == 3:
Expand All @@ -113,20 +114,20 @@ def dump_gridinfo_ctypes(self, stagger, dim=2):
np.dtype(constants._ESMF2PythonType[self.type]).itemsize*size)
zcoords = np.frombuffer(zbuffer, constants._ESMF2PythonType[self.type])

for i in xrange(I):
for j in xrange(J):
for k in xrange(K):
for i in range(I):
for j in range(J):
for k in range(K):
ind = i*I + j*J + k
if (1e-10 > xcoords[ind] and xcoords[ind] != 0) or \
xcoords[ind] > 360 or \
-90 > ycoords[ind] or \
(ycoords[ind] > -1e-10 and 1e-10 > ycoords[ind] and ycoords[ind] != 0) or \
ycoords[ind] > 90:

print "[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]"
print("[", i, ", ", j, "] = [", xcoords[ind], ", ", ycoords[ind], "]")
coordcount += 1

print "Coordcount = ", coordcount
print("Coordcount = ", coordcount)
'''
# create a numpy array to point to the ESMF allocation
# reshape the numpy array of coordinates using Fortran ordering in Grid
Expand All @@ -148,4 +149,4 @@ def _dump_field_coords_(self):
np.dtype(constants._ESMF2PythonType[self.type]).itemsize*size)
esmf_coords = np.frombuffer(buffer, constants._ESMF2PythonType[self.type])

print esmf_coords
print(esmf_coords)
10 changes: 5 additions & 5 deletions src/addon/esmpy/src/esmpy/fragments/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def ESMP_ArraySpecSet(arrayspec, rank, typekind):
if rc != _ESMP_SUCCESS:
raise NameError('ESMC_ArraySpecSet() failed with rc = '+str(rc))
arrayspec.shallowMem = las.value
print 'sizeof(arrayspec) = '+str(sizeof(arrayspec))
print 'arrayspec = '+str(arrayspec)
print 'sizeof(las) = '+str(sizeof(las))
print 'las = '+str(las)
print "\n"
print('sizeof(arrayspec) = '+str(sizeof(arrayspec)))
print('arrayspec = '+str(arrayspec))
print('sizeof(las) = '+str(sizeof(las)))
print('las = '+str(las))
print("\n")

return arrayspec

Expand Down
6 changes: 3 additions & 3 deletions src/addon/esmpy/src/esmpy/fragments/remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def remap(srcgrid, dstgrid, weights, method='bilinear'):
if os.environ.get('ESMF_NUM_PROCS'):
NUM_PROCS = os.environ.get('ESMF_NUM_PROCS')
else:
print "ESMF_NUM_PROCS not defined in user environment, using default ESMF_NUM_PROCS=1"
print("ESMF_NUM_PROCS not defined in user environment, using default ESMF_NUM_PROCS=1")
NUM_PROCS = "1"

# read the esmf.mk and get the location of the executable and the OS for
# this system
if os.environ.get('ESMFMKFILE'):
esmfmkfile = open(os.environ.get('ESMFMKFILE'))
else:
print "ESMFMKFILE is not defined!"
print("ESMFMKFILE is not defined!")
sys.exit

for line in esmfmkfile:
Expand Down Expand Up @@ -137,7 +137,7 @@ def remap(srcgrid, dstgrid, weights, method='bilinear'):
options = '-m conserve'
file = 'c'
else:
print 'Method: '+method+' is not supported!'
print('Method: '+method+' is not supported!')
sys.exit

# TODO: what is this cruft?
Expand Down

0 comments on commit 36025dd

Please sign in to comment.