Skip to content

Commit

Permalink
Compatibility for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
dmricciuto committed May 10, 2020
1 parent 492b193 commit ee58b28
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 130 deletions.
18 changes: 9 additions & 9 deletions OLMT_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def OnMakePlots(self,event):
sites_toplot=self.m_site.GetSelections()
doall = False
for i in sites_toplot:
if (i == 0):
if (i == 0):
doall=True
thisrow=0
mysite=''
Expand Down Expand Up @@ -503,8 +503,8 @@ def OnMakePlots(self,event):

#if len(mycaseprefix.split(',') > 1:

print 'python plotcase.py --case '+mycaseprefix+' --site '+mysite[:-1] \
+' --compset '+compset+' --spinup'+' --vars '+myvar[:-1]+' --csmdir '+rundir
print('python plotcase.py --case '+mycaseprefix+' --site '+mysite[:-1] \
+' --compset '+compset+' --spinup'+' --vars '+myvar[:-1]+' --csmdir '+rundir)
os.system('python plotcase.py --case '+mycaseprefix+' --site '+mysite[:-1] \
+' --compset '+compset+' --spinup'+' --vars '+myvar[:-1]+' --csmdir '+rundir)

Expand Down Expand Up @@ -611,7 +611,7 @@ def OnRun(self, event):
sites_torun = self.m_site.GetSelections()
doall = False
for i in sites_torun:
if (i == 0):
if (i == 0):
doall=True

mysites=[]
Expand Down Expand Up @@ -643,7 +643,7 @@ def OnRun(self, event):
myconly=self.conly.GetValue()
mycnonly=self.cnonly.GetValue()
mycpl_bypass=self.cpl_bypass.GetValue()
myonehour=self.onehour.GetValue()
myonehour=self.onehour.GetValue()
mycruncep=self.cruncep.GetValue()
mygswp3=self.gswp3.GetValue()
myc14=self.c14.GetValue()
Expand Down Expand Up @@ -727,7 +727,7 @@ def OnRun(self, event):
cmd = cmd+' --C14'
cmd = cmd+' --runroot '+rundir

print cmd
print(cmd)
os.system(cmd)

def OnAbout(self, event):
Expand All @@ -754,8 +754,8 @@ def OnAbout(self, event):
ccsm_input = '/lustre/atlas/world-shared/cli900/cesm/inputdata'
rundir = '/lustre/atlas/scratch/cli112/'+username
else:
ccsm_input='/home/'+username+'/models/ccsm_inputdata'
machine=oic2
ccsm_input='/home/'+username+'/models/inputdata'
machine='oic2'

os.chdir(ccsm_input+'/lnd/clm2/PTCLM')

Expand Down Expand Up @@ -783,7 +783,7 @@ def OnAbout(self, event):

#load site information for default group
fname="./"+mysitegroup_current+"_sitedata.txt"
AFdatareader = csv.reader(open(fname,"rb"))
AFdatareader = csv.reader(open(fname,"r"))
nsites=0
for row in AFdatareader:
if nsites > 0:
Expand Down
12 changes: 6 additions & 6 deletions adjust_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
casename = options.casename
if (options.restart_year == ''):
#if restart_year not provided, take the last existing restart file
restart_file = glob.glob(options.rundir+'/'+casename+'.clm2.r.*.nc')
restart_file = glob.glob(options.rundir+'/'+casename+'.clm2.r.*.nc')
if (len(restart_file) > 1):
restart_file_last = restart_file[-1]
restart_file_last = restart_file[-1]
else:
restart_file_last = restart_file[0]
year = int(restart_file_last[-19:-15])
restart_file_last = restart_file[0]
year = int(restart_file_last[-19:-15])
else:
year = int(options.restart_year)
year = int(options.restart_year)

if ('BGC' in casename):
options.bgc = True
Expand Down Expand Up @@ -77,7 +77,7 @@
rest_vals[i] = rest_vals[i]*0.05
if (var_names_harvest[v] == 'LEAFC'):
rest_vals[i] = 0.33/0.03
print rest_vals[i]
print(rest_vals[i])
elif (var_names_harvest[v] == 'FROOTC'):
rest_vals[i] = 0.33/0.03*0.666
elif (var_names_harvest[v] == 'LEAFN'):
Expand Down
10 changes: 5 additions & 5 deletions case_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
new_dir = orig_dir.replace(options.site_orig, options.site_new)
if (options.suffix != ''):
new_dir = new_dir.replace(casename,casename+'_'+options.suffix)
print 'Copying from '+orig_dir+' to \n'+new_dir
print('Copying from '+orig_dir+' to \n'+new_dir)
if (new_dir == orig_dir):
print 'Error: New and old directories are the same. Exiting'
print('Error: New and old directories are the same. Exiting')
sys.exit(1)

#copy files to new directory
Expand Down Expand Up @@ -120,7 +120,7 @@
s_out = s_out.replace(casename,casename+'_'+options.suffix)
elif ('diri' in s and 'lnd' in f):
exedir = s.split()[2][1:-4]
print exedir
print(exedir)
s_out = s
else:
s_out = s
Expand Down Expand Up @@ -165,7 +165,7 @@
file_out.write(mpicmd+' '+exedir+'/e3sm.exe\n')
file_in.close()
file_out.close()
print "Submitting the job:"
print("Submitting the job:")
if ('cades' in options.machine or 'cori' in options.machine or 'edison' in options.machine):
os.system('sbatch temp/global_'+options.casename+'_'+options.suffix+'.pbs')
else:
Expand All @@ -186,7 +186,7 @@
args = s.split(' ')
if ('--case' in args):
caseind = args.index('--case')
print caseind
print(caseind)
args[caseind+1] = args[caseind+1].replace(options.site_orig,options.site_new)
siteind = args.index('--site')
args[siteind+1] = args[siteind+1].replace(options.site_orig,options.site_new)
Expand Down
6 changes: 3 additions & 3 deletions ensemble_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
if ('1850' in casename and not ('ad_spinup' in casename)):
finidat_file_path = os.path.abspath(options.runroot)+'/UQ/'+casename.replace('1850CNP','1850CN')+'_ad_spinup/g'+gst[1:]
if (os.path.exists(finidat_file_path)):
finidat_file_orig = finidat_file_path+'/*.clm2.r.*.nc'
os.system('python adjust_restart.py --rundir '+finidat_file_path+' --casename '+ \
casename.replace('1850CNP','1850CN')+'_ad_spinup')
finidat_file_orig = finidat_file_path+'/*.clm2.r.*.nc'
os.system('python adjust_restart.py --rundir '+finidat_file_path+' --casename '+ \
casename.replace('1850CNP','1850CN')+'_ad_spinup')
if ('20TR' in casename):
finidat_file_path = os.path.abspath(options.runroot)+'/UQ/'+casename.replace('20TR','1850')+ \
'/g'+gst[1:]
Expand Down
4 changes: 2 additions & 2 deletions ensemble_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def putvar(fname, varname, varvals):
myind = 0
for p in parm_names:
myoutput.write(str(parm_names[myind])+' '+str(parm_indices[myind])+' '+str(parm_values[myind])+'\n')
myind = myind+1
myind = myind+1

for filename in os.listdir(UQdir+'/'+options.constraints):
if (not os.path.isdir(filename)):
Expand Down Expand Up @@ -289,7 +289,7 @@ def putvar(fname, varname, varvals):
#PFT-specific constraints
model_val = myvals[doy,PFT-1]
if (unc < 0):
unc = value*0.25 #default uncertainty set to 25%
unc = value*0.25 #default uncertainty set to 25%
sse = sse + ((model_val-value) /unc)**2
myoutput.write(str(myvarname)+' '+yst+' '+str(doy)+' '+str(PFT)+' '+ \
str(model_val)+' '+str(value)+' '+str(unc)+' '+str(sse)+'\n')
Expand Down
10 changes: 5 additions & 5 deletions global_fullrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_regional_bounds(myregion):
elif ('compy' in options.machine):
ccsm_input = '/compyfs/inputdata'

print options.machine
print(options.machine)
#default compilers
if (options.compiler == ''):
if (options.machine == 'titan' or options.machine == 'metis'):
Expand All @@ -273,7 +273,7 @@ def get_regional_bounds(myregion):
elif ('compy' in options.machine):
options.mpilib = 'impi'

print options.mpilib
print(options.mpilib)
mycaseid = options.mycaseid
srcmods = options.srcmods_loc

Expand All @@ -294,11 +294,11 @@ def get_regional_bounds(myregion):
myproject = options.project
else:
if (os.path.exists(os.environ.get('HOME')+'/.cesm_proj')):
print 'Getting project from '+os.environ.get('HOME')+'/.cesm_proj'
print('Getting project from '+os.environ.get('HOME')+'/.cesm_proj')
myinput = open(os.environ.get('HOME')+'/.cesm_proj','r')
for s in myinput:
myproject=s[:-1]
print 'Project = '+myproject
print('Project = '+myproject)

#case run and case root directories
if (options.runroot == ''):
Expand Down Expand Up @@ -666,7 +666,7 @@ def get_regional_bounds(myregion):
elif (os.path.isfile(caseroot+'/'+c+'/.case.run')):
input = open(caseroot+'/'+c+'/.case.run')
else:
print 'case.run file not found. Aborting'
print('case.run file not found. Aborting')
sys.exit(1)

for s in input:
Expand Down
44 changes: 22 additions & 22 deletions makepointdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
n_grids=0
point_pfts=[]
for s in input_file:
if (n_grids == 0):
header = s.split()
if (n_grids == 0):
header = s.split()
else:
data = s.split()
dnum=0
Expand All @@ -141,7 +141,7 @@
elif (options.site != ''):
print('\nCreating datasets for '+options.site+' using '+options.res+' resolution')
issite = True
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_sitedata.txt',"rb"))
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_sitedata.txt',"r"))
for row in AFdatareader:
if row[0] == options.site:
mylon=float(row[3])
Expand Down Expand Up @@ -255,10 +255,10 @@
lat = lat_uniq
point_pfts = point_pfts_uniq
n_grids = n_grids_uniq
print n_grids, ' Unique points'
print n_dups, ' duplicate points removed'
print len(point_index)
print point_index
print(n_grids, ' Unique points')
print(n_dups, ' duplicate points removed')
print(len(point_index))
print(point_index)
#---------------------Create domain data --------------------------------------------------

print('Creating domain data')
Expand Down Expand Up @@ -310,7 +310,7 @@
ierr = nffun.putvar(domainfile_new, 'mask', mask)
os.system('ncks -O --mk_rec_dim nj '+domainfile_new+' '+domainfile_new)
elif (options.mymask != ''):
print 'Applying mask from '+options.mymask
print('Applying mask from '+options.mymask)
os.system('ncks -d lon,'+str(xgrid_min[n])+','+str(xgrid_max[n])+' -d lat,'+str(ygrid_min[n])+ \
','+str(ygrid_max[n])+' '+options.mymask+' mask_temp.nc')
newmask = nffun.getvar('mask_temp.nc', 'PNW_mask')
Expand Down Expand Up @@ -342,7 +342,7 @@
nst = str(100000+n)[1:]
surffile_new = './temp/surfdata'+nst+'.nc'
if (not os.path.exists(surffile_orig)):
print 'Error: '+surffile_orig+' does not exist. Aborting'
print('Error: '+surffile_orig+' does not exist. Aborting')
sys.exit(1)
if (isglobal):
os.system('cp '+surffile_orig+' '+surffile_new)
Expand Down Expand Up @@ -396,15 +396,15 @@
mypct_clay = 0.0

if (options.surfdata_grid == False and options.site != ''):
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_pftdata.txt','rb'))
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_pftdata.txt','r'))
for row in AFdatareader:
if row[0] == options.site:
for thispft in range(0,5):
mypft_frac[int(row[2+2*thispft])]=float(row[1+2*thispft])
if (sum(mypft_frac[0:npft]) == 0.0):
print('*** Warning: PFT data NOT found. Using gridded data ***')
#read file for site-specific soil information
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_soildata.txt','rb'))
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_soildata.txt','r'))
for row in AFdatareader:
if row[0] == options.site:
mypct_sand = row[4]
Expand Down Expand Up @@ -443,10 +443,10 @@
for k in range(0,3):
pct_urban[k][0][0] = 0.0
for k in range(0,10):
if (mypct_sand > 0.0 or mypct_clay > 0.0):
if (float(mypct_sand) > 0.0 or float(mypct_clay) > 0.0):
if (k == 0):
print 'Setting %sand to '+str(mypct_sand)
print 'Setting %clay to '+str(mypct_clay)
print('Setting %sand to '+str(mypct_sand))
print('Setting %clay to '+str(mypct_clay))
pct_sand[k][0][0] = mypct_sand
pct_clay[k][0][0] = mypct_clay
if ('US-SPR' in options.site):
Expand All @@ -459,18 +459,18 @@
, 'DB Shrub Temperate', 'BD Shrub Boreal', 'C3 arctic grass', \
'C3 non-arctic grass', 'C4 grass', 'Crop','xxx','xxx']
if (options.mypft >= 0):
print 'Setting PFT '+str(options.mypft)+'('+pft_names[int(options.mypft)]+') to 100%'
print('Setting PFT '+str(options.mypft)+'('+pft_names[int(options.mypft)]+') to 100%')
pct_pft[:,0,0] = 0.0
pct_pft[int(options.mypft),0,0] = 100.0
else:
for p in range(0,npft):
if (sum(mypft_frac[0:npft]) > 0.0):
if (mypft_frac[p] > 0.0):
if (p < 16):
print 'Setting PFT '+str(p)+'('+pft_names[p]+') to '+ \
str(mypft_frac[p])+'%'
print('Setting PFT '+str(p)+'('+pft_names[p]+') to '+ \
str(mypft_frac[p])+'%')
else:
print 'Setting PFT '+str(p)+' to '+str(mypft_frac[p])+'%'
print('Setting PFT '+str(p)+' to '+str(mypft_frac[p])+'%')
pct_pft[p][0][0] = mypft_frac[p]
#maxlai = (monthly_lai).max(axis=0)
for t in range(0,12):
Expand Down Expand Up @@ -546,7 +546,7 @@
pftdyn_new = './temp/surfdata.pftdyn'+nst+'.nc'

if (not os.path.exists(pftdyn_orig)):
print 'Error: '+pftdyn_orig+' does not exist. Aborting'
print('Error: '+pftdyn_orig+' does not exist. Aborting')
sys.exit(1)
if (isglobal):
os.system('cp '+pftdyn_orig+' '+pftdyn_new)
Expand Down Expand Up @@ -582,7 +582,7 @@
dynexist = False
mypft_frac=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
if (options.surfdata_grid == False and options.site != ''):
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_pftdata.txt','rb'))
AFdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.sitegroup+'_pftdata.txt','r'))
for row in AFdatareader:
#print(row[0], row[1], options.site)
if row[0] == options.site:
Expand All @@ -591,7 +591,7 @@

if (os.path.exists(ccsm_input+'/lnd/clm2/PTCLM/'+options.site+'_dynpftdata.txt')):
dynexist = True
DYdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.site+'_dynpftdata.txt','rb'))
DYdatareader = csv.reader(open(ccsm_input+'/lnd/clm2/PTCLM/'+options.site+'_dynpftdata.txt','r'))
dim = (19,200)
pftdata = numpy.zeros(dim)
for row in DYdatareader:
Expand Down Expand Up @@ -657,7 +657,7 @@
harvest_vh2[t][0][0] = 0.
else:
#use time-varying files from gridded file
print 'using '+surffile_new+' for 1850 information'
print('using '+surffile_new+' for 1850 information')
nonpft = float(pct_lake_1850[n]+pct_glacier_1850[n]+ \
pct_wetland_1850[n]+sum(pct_urban_1850[0:3,n]))
if (options.mymodel == 'CLM5'):
Expand Down
10 changes: 5 additions & 5 deletions manage_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def postproc(myvars, myyear_start, myyear_end, myday_start, myday_end, myavg, \
else:
output.append(mydata[0,myindex]*myfactor[index]+myoffset[index])
for i in range(0,ndays_total/myavg[index]):
data[thiscol] = sum(output[(i*myavg[index]):((i+1)*myavg[index])])/myavg[index]
data[thiscol] = sum(output[(i*myavg[index]):((i+1)*myavg[index])])/myavg[index]
thiscol=thiscol+1
index=index+1
if (options.microbe):
Expand Down Expand Up @@ -256,7 +256,7 @@ def postproc(myvars, myyear_start, myyear_end, myday_start, myday_end, myavg, \
data[:,thisjob-1] = data_row
parm_row = comm.recv(source=process, tag=6)
parms[:,thisjob-1] = parm_row
print 'Received', thisjob
print('Received', thisjob)
n_done = n_done+1
comm.send(n_job, dest=process, tag=1)
comm.send(0, dest=process, tag=2)
Expand All @@ -269,7 +269,7 @@ def postproc(myvars, myyear_start, myyear_end, myday_start, myday_end, myavg, \
data[:,thisjob-1] = data_row
parm_row = comm.recv(source=process, tag=6)
parms[:,thisjob-1] = parm_row
print 'Received', thisjob
print('Received', thisjob)
n_done = n_done+1
comm.send(-1, dest=process, tag=1)
comm.send(-1, dest=process, tag=2)
Expand Down Expand Up @@ -307,7 +307,7 @@ def postproc(myvars, myyear_start, myyear_end, myday_start, myday_end, myavg, \
for p in range(0,len(pmin)):
myoutput.write(pmin[p]+' '+pmax[p]+'\n')
myoutput.close()
print np.hstack((parm_out,data_out))
print(np.hstack((parm_out,data_out)))
np.savetxt(UQ_output+'/foreden.csv', np.hstack((parm_out,data_out)), delimiter=',', header=eden_header[:-1])

MPI.Finalize()
Expand Down Expand Up @@ -352,5 +352,5 @@ def postproc(myvars, myyear_start, myyear_end, myday_start, myday_end, myavg, \
comm.send(rank, dest=0, tag=3)
comm.send(myjob, dest=0, tag=4)

print rank, ' complete'
print(rank, ' complete')
MPI.Finalize()
Loading

0 comments on commit ee58b28

Please sign in to comment.