Skip to content

Commit

Permalink
Updated IO interface to netCDF4 in web_enabled version
Browse files Browse the repository at this point in the history
  • Loading branch information
allibco committed Apr 26, 2019
1 parent 31eda0c commit b686250
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 59 deletions.
5 changes: 4 additions & 1 deletion pyCECT.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def main(argv):
print ' '

#make sure these are valid
if os.path.isfile(opts_dict['sumfile']) == False:
if opts_dict['web_enabled'] == False and os.path.isfile(opts_dict['sumfile']) == False:
print "ERROR: Summary file name is not valid."
sys.exit()
if os.path.exists(opts_dict['indir']) == False:
Expand Down Expand Up @@ -187,6 +187,9 @@ def main(argv):
if opts_dict['web_enabled']:
if len(opts_dict['sumfile'])==0:
opts_dict['sumfile']='/glade/p/cesmdata/cseg/inputdata/validation/'
#need to open ifiles


opts_dict['sumfile'],machineid,compiler=pyEnsLib.search_sumfile(opts_dict,ifiles)
if len(machineid)!=0 and len(compiler)!=0:
print ' '
Expand Down
127 changes: 69 additions & 58 deletions pyEnsLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,67 +229,78 @@ def calculate_raw_score(k, v, npts3d, npts2d, ens_avg, ens_stddev, is_SE, opts_d
# /glade/p/cesmdata/cseg/inputdata/validation/ when three
# validation files are input from the web server
#
#AB - needs testing without Nio
# this is assuming that ifiles are already open and we may not want that
# ifiles are not open
def search_sumfile(opts_dict,ifiles):
sumfile_dir=opts_dict['sumfile']
global_att=ifiles[0].ncattrs()
machineid=''
compiler=''
for k,v in global_att.iteritems():
if k=='model_version':
if v.find("-") != -1:
model_version=v[0:v.find('-')]
else:
model_version=v
elif k=='compset':
compset=v
elif k=='testtype':
testtype=v
if v=='UF-ECT':
testtype='uf_ensembles'

sumfile_dir=opts_dict['sumfile']
first_file = nc.Dataset(ifiles[0],"r")
machineid=''
compiler=''

global_att=first_file.ncattrs()
for attr_name in global_att:
val = getattr(first_file, attr_name)
if attr_name == 'model_version':
if val.find("-") != -1:
model_version=val[0:val.find('-')]
else:
model_version=val
elif attr_name == 'compset':
compset=val
elif attr_name == 'testtype':
testtype=val
if val == 'UF-ECT':
testtype = 'uf_ensembles'
opts_dict['eet']=len(ifiles)
elif v=='ECT':
elif val=='ECT':
testtype='ensembles'
elif v=='POP':
testtype=v+'_ensembles'
elif k=='machineid':
machineid=v
elif k=='compiler':
compiler=v
elif k=='grid':
grid=v
if 'testtype' in global_att:
sumfile_dir=sumfile_dir+'/'+testtype+'/'
else:
print "ERROR: No global attribute testtype in your validation file => EXITING...."
sys.exit(2)
if 'model_version' in global_att:
sumfile_dir=sumfile_dir+'/'+model_version+'/'
else:
print "ERROR: No global attribute model_version in your validation file => EXITING...."
sys.exit(2)
if (os.path.exists(sumfile_dir)):
thefile_id=0
for i in os.listdir(sumfile_dir):
if (os.path.isfile(sumfile_dir+i)):
sumfile_id=nc.Dataset(sumfile_dir+i,'r')
sumfile_gatt=sumfile_id.ncattrs()
if 'grid' not in sumfile_gatt and 'resolution' not in sumfile_gatt:
print "ERROR: No global attribute grid or resolution in the summary file => EXITING...."
sys.exit(2)
if 'compset' not in sumfile_gatt:
print "ERROR: No global attribute compset in the summary file"
sys.exit(2)
if sumfile_gatt['resolution']==grid and sumfile_gatt['compset']==compset:
thefile_id=sumfile_id
if thefile_id==0:
print "ERROR: The validation files don't have a matching ensemble summary file to compare => EXITING...."
sys.exit(2)
else:
print "ERROR: Could not locate directory "+sumfile_dir + " => EXITING...."
sys.exit(2)
return sumfile_dir+i,machineid,compiler
elif v=='POP':
testtype=val+'_ensembles'
elif attr_name == 'machineid':
machineid=val
elif attr_name == 'compiler':
compiler=val
elif attr_name == 'grid':
grid=val

if 'testtype' in global_att:
sumfile_dir=sumfile_dir+'/'+testtype+'/'
else:
print "ERROR: No global attribute testtype in your validation file => EXITING...."
sys.exit(2)

if 'model_version' in global_att:
sumfile_dir=sumfile_dir+'/'+model_version+'/'
else:
print "ERROR: No global attribute model_version in your validation file => EXITING...."
sys.exit(2)

first_file.close()

if (os.path.exists(sumfile_dir)):
thefile_id=0
for i in os.listdir(sumfile_dir):
if (os.path.isfile(sumfile_dir+i)):
sumfile_id=nc.Dataset(sumfile_dir+i,'r')
sumfile_gatt=sumfile_id.ncattrs()
if 'grid' not in sumfile_gatt and 'resolution' not in sumfile_gatt:
print "ERROR: No global attribute grid or resolution in the summary file => EXITING...."
sys.exit(2)
if 'compset' not in sumfile_gatt:
print "ERROR: No global attribute compset in the summary file"
sys.exit(2)
if getattr(sumfile_id, 'resolution') == grid and getsttr(sumfile_id, 'compset') == compset:
thefile_id=sumfile_id
sumfile_id.close()
if thefile_id==0:
print "ERROR: The verification files don't have a matching ensemble summary file to compare => EXITING...."
sys.exit(2)
else:
print "ERROR: Could not locate directory "+sumfile_dir + " => EXITING...."
sys.exit(2)


return sumfile_dir+i,machineid,compiler

#
# Create some variables and call a function to calculate PCA
Expand Down

0 comments on commit b686250

Please sign in to comment.