diff --git a/OLMT_GUI.py b/OLMT_GUI.py index be12d9f..7eea779 100755 --- a/OLMT_GUI.py +++ b/OLMT_GUI.py @@ -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='' @@ -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) @@ -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=[] @@ -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() @@ -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): @@ -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') @@ -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: diff --git a/adjust_restart.py b/adjust_restart.py index df2b8cf..bb86d08 100755 --- a/adjust_restart.py +++ b/adjust_restart.py @@ -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 @@ -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'): diff --git a/case_copy.py b/case_copy.py index b0bd2fe..c3fda32 100644 --- a/case_copy.py +++ b/case_copy.py @@ -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 @@ -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 @@ -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: @@ -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) diff --git a/ensemble_copy.py b/ensemble_copy.py index 24cd4d4..3a6b626 100755 --- a/ensemble_copy.py +++ b/ensemble_copy.py @@ -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:] diff --git a/ensemble_run.py b/ensemble_run.py index ab4360d..6ef9c31 100755 --- a/ensemble_run.py +++ b/ensemble_run.py @@ -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)): @@ -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') diff --git a/global_fullrun.py b/global_fullrun.py index ccbe4f0..8ae02fc 100755 --- a/global_fullrun.py +++ b/global_fullrun.py @@ -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'): @@ -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 @@ -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 == ''): @@ -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: diff --git a/makepointdata.py b/makepointdata.py index efc76c2..adad601 100755 --- a/makepointdata.py +++ b/makepointdata.py @@ -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 @@ -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]) @@ -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') @@ -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') @@ -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) @@ -396,7 +396,7 @@ 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): @@ -404,7 +404,7 @@ 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] @@ -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): @@ -459,7 +459,7 @@ , '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: @@ -467,10 +467,10 @@ 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): @@ -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) @@ -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: @@ -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: @@ -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'): diff --git a/manage_ensemble.py b/manage_ensemble.py index 4b478e5..f25f875 100644 --- a/manage_ensemble.py +++ b/manage_ensemble.py @@ -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): @@ -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) @@ -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) @@ -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() @@ -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() diff --git a/netcdf_functions.py b/netcdf_functions.py index e7829ff..e3c6d48 100755 --- a/netcdf_functions.py +++ b/netcdf_functions.py @@ -35,8 +35,7 @@ def putvar(fname, varname, varvals): if (len(varvals) > 1): var[:] = varvals else: - - nffile.close() + nffile.close() else: nffile = netcdf.NetCDFFile(fname,"a") var = nffile.variables[varname] diff --git a/plotcase.py b/plotcase.py index 9e8f2c0..07f8bbd 100755 --- a/plotcase.py +++ b/plotcase.py @@ -199,8 +199,8 @@ def getvar(fname, varname, npf, index, scale_factor): tstep=-999 input = open(mydir+"/lnd_in") for s in input: - if ('hist_mfilt' in s): - mfiltinfo = s.split()[2] + if ('hist_mfilt' in s): + mfiltinfo = s.split()[2] npf = int(mfiltinfo.split(',')[0]) if (options.h1): npf = int(mfiltinfo.split(',')[1]) @@ -348,7 +348,7 @@ def getvar(fname, varname, npf, index, scale_factor): thisrow = thisrow+1 myobs_in.close() else: - print 'Error reading observations for '+mysites[c] + print('Error reading observations for '+mysites[c]) #read monthly .nc files (default output) if (ftype == 'default'): @@ -393,7 +393,7 @@ def getvar(fname, varname, npf, index, scale_factor): mydata[v,nsteps] = mydata[v,nsteps]+myvar_temp2 else: if (v == 0 and m == 0): - print 'Warning: '+myfile+' does not exist' + print('Warning: '+myfile+' does not exist') x[nsteps] = y+m/12.0 mydata[v,nsteps] = numpy.NaN if (y-1 < yend_all): @@ -492,7 +492,7 @@ def getvar(fname, varname, npf, index, scale_factor): x[myind] = ystart+(ylast*n*nypf+y*nypf) + nypf*(i*1.0-0.5)/npf mydata[v,myind] = numpy.NaN nsteps=nsteps+1 - else: + else: if (v == 0): print('Warning: '+myfile+' does not exist') if (y-1 < yend_all): diff --git a/runcase.py b/runcase.py index 50a7a21..1f3f04a 100755 --- a/runcase.py +++ b/runcase.py @@ -264,12 +264,12 @@ if (options.csmdir == ''): if (os.path.exists('../E3SM')): options.csmdir = os.path.abspath('../E3SM') - print 'Model root not specified. Defaulting to '+options.csmdir + print('Model root not specified. Defaulting to '+options.csmdir) else: - print 'Error: Model root not specified. Please set using --model_root' + print('Error: Model root not specified. Please set using --model_root') sys.exit(1) elif (not os.path.exists(options.csmdir)): - print 'Error: Model root '+options.csmdir+' does not exist.' + print('Error: Model root '+options.csmdir+' does not exist.') sys.exit(1) #machine info: cores per node @@ -277,8 +277,8 @@ if ('titan' in options.machine): ppn=16 if (int(options.walltime) > 2 and int(options.ng) < 2048): - print 'Requested walltime too long' - print 'Setting to 2 hours.' + print('Requested walltime too long') + print('Setting to 2 hours.') options.walltime=2 elif ('metis' in options.machine): ppn=16 @@ -308,7 +308,7 @@ elif ('E3SM' in options.csmdir or 'ACME' in options.csmdir): options.mymodel = 'ELM' else: - print 'Error: Model not specified' + print('Error: Model not specified') sys.exit(1) #check for valid csm directory @@ -567,7 +567,7 @@ #Clean up os.system('rm makepointdata_rhea*') else: - print ptcmd + print(ptcmd) result = os.system(ptcmd) if (result > 0): print ('PointCLM: Error creating point data. Aborting') @@ -577,7 +577,7 @@ sitedatadir = os.path.abspath(PTCLMfiledir) os.chdir(sitedatadir) if (isglobal == False): - AFdatareader = csv.reader(open(options.sitegroup+'_sitedata.txt',"rb")) + AFdatareader = csv.reader(open(options.sitegroup+'_sitedata.txt',"r")) for row in AFdatareader: if row[0] == options.site: if (use_reanalysis): @@ -640,7 +640,7 @@ os.system('nccopy -3 '+options.ccsm_input+'/lnd/clm2/paramdata/'+parm_file+' ' \ +tmpdir+'/clm_params.nc') myncap = 'ncap' - if ('compy' in options.machine): + if ('compy' in options.machine or 'ubuntu' in options.machine): myncap='ncap2' if (options.humhol): print('Adding hummock-hollow parameters (default for SPRUCE site)') @@ -685,10 +685,10 @@ parms = options.parm_vals.split('/') nparms = len(parms) for n in range(0,nparms): - parm_data=parms[n].split(',') + parm_data=parms[n].split(',') thisvar = nffun.getvar(pftfile, parm_data[0]) if (len(parm_data) == 2): - thisvar[...] = float(parm_data[1]) + thisvar[...] = float(parm_data[1]) elif (len(parm_data) == 3): if (float(parm_data[1]) >= 0): thisvar[int(parm_data[1])] = float(parm_data[2]) @@ -849,7 +849,7 @@ comps = ['ATM','LND','ICE','OCN','CPL','GLC','ROF','WAV'] for c in comps: - print 'Setting NTASKS_'+c+' to '+str(options.np) + print('Setting NTASKS_'+c+' to '+str(options.np)) os.system('./xmlchange NTASKS_'+c+'='+str(options.np)) os.system('./xmlchange NTHRDS_'+c+'=1') @@ -865,7 +865,7 @@ os.system('./xmlchange STOP_N='+str(options.run_n)) if (options.rest_n > 0): - print 'Setting REST_N to '+str(options.rest_n) + print('Setting REST_N to '+str(options.rest_n)) os.system('./xmlchange REST_N='+str(options.rest_n)) #--------------------------CESM setup ---------------------------------------- @@ -977,8 +977,8 @@ if ('20TR' not in compset and int(options.hist_mfilt) == -1): #default to annual for spinup runs if not specified - options.hist_mfilt = 1 - options.hist_nhtfrq = -8760 + options.hist_mfilt = 1 + options.hist_nhtfrq = -8760 if (options.hist_mfilt != -1 and not options.diags): if (options.ad_spinup): @@ -1037,7 +1037,7 @@ output.write(" hist_empty_htapes = .true.\n") h0varst = " hist_fincl1 = " for v in var_list_spinup: - h0varst = h0varst+"'"+v+"'," + h0varst = h0varst+"'"+v+"'," h0varst = h0varst[:-1]+"\n" output.write(h0varst) @@ -1067,14 +1067,14 @@ output.write(h3varst) output.write(h4varst) elif ('20TR' in compset and (options.trans_varlist != '' or options.ilambvars)): - trans_varlist = options.trans_varlist.split(',') + trans_varlist = options.trans_varlist.split(',') if (options.ilambvars): trans_varlist = ilamb_outputs - output.write(" hist_empty_htapes = .true.\n") + output.write(" hist_empty_htapes = .true.\n") h0varst = " hist_fincl1 = " - for v in trans_varlist: - h0varst = h0varst+"'"+v+"'," - h0varst = h0varst[:-1]+"\n" + for v in trans_varlist: + h0varst = h0varst+"'"+v+"'," + h0varst = h0varst[:-1]+"\n" output.write(h0varst) if (options.ad_spinup): @@ -1251,10 +1251,10 @@ #if (isglobal): os.system("./xmlchange -id BATCH_SYSTEM --val none") if (options.no_config == False): - print 'Running case.setup' + print('Running case.setup') result = os.system('./case.setup > case_setup.log') if (result > 0): - print 'Error: runcase.py failed to setup case' + print('Error: runcase.py failed to setup case') sys.exit(1) else: print("Warning: No case configure performed") @@ -1282,7 +1282,7 @@ outfile.close() os.system('mv Macros.make.tmp Macros.make') -if (options.mymodel == 'ELM'): +if (options.mymodel == 'ELM' and not ('ubuntu' in options.machine)): infile = open("./Macros.cmake") outfile = open("./Macros.cmake.tmp",'a') @@ -1317,15 +1317,15 @@ os.system('./case.build --clean') #compile cesm if (options.no_build == False): - print 'Running case.build' + print('Running case.build') if ('edison' in options.machine or 'titan' in options.machine): #send output to screen since build times are very slow result = os.system('./case.build') else: result = os.system('./case.build > case_build.log') if (result > 0): - print 'Error: Pointclm.py failed to build case. Aborting' - print 'See '+os.getcwd()+'/case_build.log for details' + print('Error: Pointclm.py failed to build case. Aborting') + print('See '+os.getcwd()+'/case_build.log for details') sys.exit(1) else: os.system('./xmlchange BUILD_COMPLETE=TRUE') @@ -1440,7 +1440,7 @@ if (options.ensemble_file != '' or int(options.mc_ensemble) != -1): if (not(os.path.isfile(options.parm_list))): - print('parm_list file does not exist') + print('parm_list file does not exist') sys.exit(1) elif (isglobal): print('Ensemble simulations not supported for regional/global simulations') @@ -1451,7 +1451,7 @@ param_max=[] input = open(options.parm_list,'r') for s in input: - if (s): + if (s): param_names.append(s.split()[0]) if (int(options.mc_ensemble) > 0): if (len(s.split()) == 3): @@ -1486,8 +1486,8 @@ numpy.savetxt('mcsamples_'+casename+'.txt', numpy.transpose(samples)) options.ensemble_file = 'mcsamples_'+casename+'.txt' - print str(n_parameters)+' parameters are being modified' - print str(nsamples)+' parameter samples provided' + print(str(n_parameters)+' parameters are being modified') + print(str(nsamples)+' parameter samples provided') #total number of processors required in each pbs script np_total = int(options.np)*int(options.ng) @@ -1532,7 +1532,7 @@ if (options.debug): output_run.write('#SBATCH --qos=debug\n') else: - output_run.write('#SBATCH --qos=regular\n') + output_run.write('#SBATCH --qos=regular\n') if ('haswell' in options.machine): output_run.write('#SBATCH --constraint=haswell\n') if ('knl' in options.machine): @@ -1549,7 +1549,7 @@ output_run.write('source $MODULESHOME/init/csh\n') output_run.write('module load nco\n') output_run.write('module load cray-netcdf\n') - output_run.write('module unload python\n') + output_run.write('module unload python\n') output_run.write('module load python/2.7.5\n') output_run.write('module unload PrgEnv-intel\n') output_run.write('module load PrgEnv-gnu\n') diff --git a/site_fullrun.py b/site_fullrun.py index 828eca7..3f3fb75 100755 --- a/site_fullrun.py +++ b/site_fullrun.py @@ -178,7 +178,7 @@ def submit(fname, submit_type='qsub', job_depend=''): job_depend_flag = ' -W depend=afterok:' if ('sbatch' in submit_type): - job_depend_flag = ' --dependency=afterok:' + job_depend_flag = ' --dependency=afterok:' if (job_depend != '' and submit_type != ''): os.system(submit_type+job_depend_flag+job_depend+' '+fname+' > temp/jobinfo') else: @@ -203,19 +203,19 @@ def submit(fname, submit_type='qsub', job_depend=''): if (options.csmdir == ''): if (os.path.exists('../E3SM')): options.csmdir = os.path.abspath('../E3SM') - print 'Model root not specified. Defaulting to '+options.csmdir + print('Model root not specified. Defaulting to '+options.csmdir) else: - print 'Error: Model root not specified. Please set using --model_root' + print('Error: Model root not specified. Please set using --model_root') sys.exit(1) elif (not os.path.exists(options.csmdir)): - print 'Error: Model root '+options.csmdir+' does not exist.' + print('Error: Model root '+options.csmdir+' does not exist.') sys.exit(1) #get machine info if not specified npernode=32 if (options.machine == ''): hostname = socket.gethostname() - print 'Machine not specified. Using hostname '+hostname+' to determine machine' + print('Machine not specified. Using hostname '+hostname+' to determine machine') if ('or-condo' in hostname): options.machine = 'cades' npernode=32 @@ -223,7 +223,7 @@ def submit(fname, submit_type='qsub', job_depend=''): options.machine = 'edison' npernode = 24 elif ('cori' in hostname): - print 'Cori machine not specified. Setting to cori-haswell' + print('Cori machine not specified. Setting to cori-haswell') options.machine = 'cori-haswell' npernode=32 elif ('titan' in hostname): @@ -233,14 +233,14 @@ def submit(fname, submit_type='qsub', job_depend=''): options.machine = 'eos' npernode=32 elif ('blues' in hostname or 'blogin' in hostname): - print 'Hostname = '+hostname+' and machine not specified. Assuming anvil' + print('Hostname = '+hostname+' and machine not specified. Assuming anvil') options.machine = 'anvil' npernode=36 elif ('compy' in hostname): options.machine = 'compy' npernode=40 else: - print 'ERROR in site_fullrun.py: Machine not specified. Aborting' + print('ERROR in site_fullrun.py: Machine not specified. Aborting') sys.exit(1) if (options.ccsm_input != ''): @@ -289,7 +289,7 @@ def submit(fname, submit_type='qsub', job_depend=''): if (options.machine == 'titan' or options.machine == 'eos'): myinput = open('/ccs/home/'+myuser+'/.cesm_proj','r') for s in myinput: - myproject=s[:-1] + myproject=s[:-1] runroot='/lustre/atlas/scratch/'+myuser+'/'+myproject elif (options.machine == 'cades'): runroot='/lustre/or-hydra/cades-ccsi/scratch/'+myuser @@ -321,7 +321,7 @@ def submit(fname, submit_type='qsub', job_depend=''): #create ensemble file if requested (so that all cases use the same) if (int(options.mc_ensemble) != -1): if (not(os.path.isfile(options.parm_list))): - print('parm_list file does not exist') + print('parm_list file does not exist') sys.exit() else: param_names=[] @@ -329,7 +329,7 @@ def submit(fname, submit_type='qsub', job_depend=''): param_max=[] input = open(options.parm_list,'r') for s in input: - if (s): + if (s): param_names.append(s.split()[0]) if (int(options.mc_ensemble) > 0): if (len(s.split()) == 3): @@ -380,7 +380,7 @@ def submit(fname, submit_type='qsub', job_depend=''): site_endyear = int(row[7]) ncycle = endyear-startyear+1 #number of years in met cycle ny_ad = options.ny_ad - ny_fin = options.nyears_final_spinup + ny_fin = options.nyears_final_spinup if (int(options.ny_ad) % ncycle != 0): #AD spinup and final spinup lengths must be multiples of met data cyle. ny_ad = str(int(ny_ad) + ncycle - (int(ny_ad) % ncycle)) @@ -388,11 +388,11 @@ def submit(fname, submit_type='qsub', job_depend=''): ny_fin = str(int(ny_fin) + ncycle - (int(ny_fin) % ncycle)) if (options.nyears_transient == -1): - translen = endyear-1850+1 #length of transient run - if (options.cpl_bypass and (options.cruncep or options.gswp3 or \ - options.princeton or options.cruncepv8)): - print(endyear_trans, site_endyear) - translen = min(site_endyear,endyear_trans)-1850+1 + translen = endyear-1850+1 #length of transient run + if (options.cpl_bypass and (options.cruncep or options.gswp3 or \ + options.princeton or options.cruncepv8)): + print(endyear_trans, site_endyear) + translen = min(site_endyear,endyear_trans)-1850+1 #use site parameter file if it exists if (options.siteparms): @@ -525,7 +525,7 @@ def submit(fname, submit_type='qsub', job_depend=''): else: decomp_model = 'CTC' if (options.eca): - mycompset = nutrients+'ECA'+decomp_model + mycompset = nutrients+'ECA'+decomp_model elif (options.fates): mycompset = 'CLM45ED' else: @@ -553,8 +553,8 @@ def submit(fname, submit_type='qsub', job_depend=''): if (sitenum == 0): if (options.exeroot != ''): if (os.path.isfile(options.exeroot+'/'+myexe) == False): - print 'Error: '+options.exeroot+' does not exist or does '+ \ - 'not contain an executable. Exiting' + print('Error: '+options.exeroot+' does not exist or does '+ \ + 'not contain an executable. Exiting') sys.exit(1) else: ad_exeroot = options.exeroot @@ -571,7 +571,7 @@ def submit(fname, submit_type='qsub', job_depend=''): cmd_adsp = cmd_adsp+' --compset I1850'+mycompset_adsp ad_case = site+'_I1850'+mycompset_adsp if (options.noad == False): - ad_case = ad_case+'_ad_spinup' + ad_case = ad_case+'_ad_spinup' if (options.makemet): cmd_adsp = cmd_adsp+' --makemetdat' if (options.spinup_vars): @@ -604,8 +604,8 @@ def submit(fname, submit_type='qsub', job_depend=''): cmd_fnsp = cmd_fnsp+' --run_startyear '+str(options.run_startyear) if (options.exeroot != ''): if (os.path.isfile(options.exeroot+'/'+myexe) == False): - print 'Error: '+options.exeroot+' does not exist or does '+ \ - 'not contain an executable. Exiting' + print('Error: '+options.exeroot+' does not exist or does '+ \ + 'not contain an executable. Exiting') sys.exit(1) else: ad_exeroot=options.exeroot @@ -632,7 +632,7 @@ def submit(fname, submit_type='qsub', job_depend=''): else: cmd_fnsp = cmd_fnsp+' --compset I1850'+mycompset if (options.spinup_vars): - cmd_fnsp = cmd_fnsp+' --spinup_vars' + cmd_fnsp = cmd_fnsp+' --spinup_vars' if (options.ensemble_file != '' and options.notrans): cmd_fnsp = cmd_fnsp + ' --postproc_file '+options.postproc_file @@ -686,7 +686,7 @@ def submit(fname, submit_type='qsub', job_depend=''): #If not the first site, create point data here if ((sitenum > 0) and not options.nopointdata): - print 'Creating point data for '+site + print('Creating point data for '+site) ptcmd = 'python makepointdata.py '+ \ ' --site '+site+' --sitegroup '+options.sitegroup+ \ ' --ccsm_input '+ccsm_input+' --model '+mymodel @@ -696,7 +696,7 @@ def submit(fname, submit_type='qsub', job_depend=''): ptcmd = ptcmd+' --pft '+str(options.mypft) result = os.system(ptcmd) if (result > 0): - print 'Site_fullrun: Error creating point data for '+site + print('Site_fullrun: Error creating point data for '+site) sys.exit(1) #Build Cases @@ -713,7 +713,7 @@ def submit(fname, submit_type='qsub', job_depend=''): +str(endyear-startyear+1) result = os.system(ptcmd) if (result > 0): - print 'Site_fullrun: Error in runcase.py for ad_spinup ' + print('Site_fullrun: Error in runcase.py for ad_spinup ') sys.exit(1) else: ad_case_firstsite = ad_case @@ -732,7 +732,7 @@ def submit(fname, submit_type='qsub', job_depend=''): +str(int(ny_ad)+1)+' --spin_cycle '+str(endyear-startyear+1) result = os.system(ptcmd) if (result > 0): - print 'Site_fullrun: Error in runcase.py final spinup' + print('Site_fullrun: Error in runcase.py final spinup') sys.exit(1) if (options.notrans == False): @@ -751,7 +751,7 @@ def submit(fname, submit_type='qsub', job_depend=''): result = os.system(cmd_trns2) if (result > 0): - print 'Site_fullrun: Error in runcase.py for transient' + print('Site_fullrun: Error in runcase.py for transient') sys.exit(1) @@ -771,7 +771,7 @@ def submit(fname, submit_type='qsub', job_depend=''): for c in case_list: mysubmit_type = 'qsub' - groupnum = sitenum/npernode + groupnum = int(sitenum/npernode) if ('cades' in options.machine or 'anvil' in options.machine or 'compy' in options.machine or 'cori' in options.machine): mysubmit_type = 'sbatch' if ('ubuntu' in options.machine): @@ -782,7 +782,7 @@ def submit(fname, submit_type='qsub', job_depend=''): elif (os.path.isfile(caseroot+'/'+ad_case_firstsite+'/.case.run')): input = open(caseroot+'/'+ad_case_firstsite+'/.case.run') else: - print caseroot+'/'+ad_case_firstsite+'/case.run file not found. Aborting' + print(caseroot+'/'+ad_case_firstsite+'/case.run file not found. Aborting') sys.exit(1) output = open('./scripts/'+myscriptsdir+'/'+c+'_group'+str(groupnum)+'.pbs','w') for s in input: @@ -978,7 +978,7 @@ def submit(fname, submit_type='qsub', job_depend=''): #Submit PBS scripts for multi-site simualtions on 1 node if (options.ensemble_file == ''): - for g in range(0,groupnum+1): + for g in range(0,int(groupnum)+1): job_depend_run='' for thiscase in case_list: output = open('./scripts/'+myscriptsdir+'/'+thiscase+'_group'+str(g)+'.pbs','a') @@ -986,6 +986,10 @@ def submit(fname, submit_type='qsub', job_depend=''): if ('trans_diags' in thiscase and options.machine == 'cades'): output.write("scp -r ./plots/"+mycaseid+" acme-webserver.ornl.gov:~/www/single_point/plots\n") output.close() - job_depend_run = submit('scripts/'+myscriptsdir+'/'+thiscase+'_group'+str(g)+'.pbs',job_depend= \ + if (mysubmit_type == ''): + os.system('chmod u+x ./scripts/'+myscriptsdir+'/'+thiscase+'_group'+str(g)+'.pbs') + os.system('./scripts/'+myscriptsdir+'/'+thiscase+'_group'+str(g)+'.pbs') + else: + job_depend_run = submit('scripts/'+myscriptsdir+'/'+thiscase+'_group'+str(g)+'.pbs',job_depend= \ job_depend_run, submit_type=mysubmit_type)