Skip to content

Commit b686250

Browse files
committed
Updated IO interface to netCDF4 in web_enabled version
1 parent 31eda0c commit b686250

File tree

2 files changed

+73
-59
lines changed

2 files changed

+73
-59
lines changed

pyCECT.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def main(argv):
104104
print ' '
105105

106106
#make sure these are valid
107-
if os.path.isfile(opts_dict['sumfile']) == False:
107+
if opts_dict['web_enabled'] == False and os.path.isfile(opts_dict['sumfile']) == False:
108108
print "ERROR: Summary file name is not valid."
109109
sys.exit()
110110
if os.path.exists(opts_dict['indir']) == False:
@@ -187,6 +187,9 @@ def main(argv):
187187
if opts_dict['web_enabled']:
188188
if len(opts_dict['sumfile'])==0:
189189
opts_dict['sumfile']='/glade/p/cesmdata/cseg/inputdata/validation/'
190+
#need to open ifiles
191+
192+
190193
opts_dict['sumfile'],machineid,compiler=pyEnsLib.search_sumfile(opts_dict,ifiles)
191194
if len(machineid)!=0 and len(compiler)!=0:
192195
print ' '

pyEnsLib.py

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -229,67 +229,78 @@ def calculate_raw_score(k, v, npts3d, npts2d, ens_avg, ens_stddev, is_SE, opts_d
229229
# /glade/p/cesmdata/cseg/inputdata/validation/ when three
230230
# validation files are input from the web server
231231
#
232-
#AB - needs testing without Nio
233-
# this is assuming that ifiles are already open and we may not want that
232+
# ifiles are not open
234233
def search_sumfile(opts_dict,ifiles):
235-
sumfile_dir=opts_dict['sumfile']
236-
global_att=ifiles[0].ncattrs()
237-
machineid=''
238-
compiler=''
239-
for k,v in global_att.iteritems():
240-
if k=='model_version':
241-
if v.find("-") != -1:
242-
model_version=v[0:v.find('-')]
243-
else:
244-
model_version=v
245-
elif k=='compset':
246-
compset=v
247-
elif k=='testtype':
248-
testtype=v
249-
if v=='UF-ECT':
250-
testtype='uf_ensembles'
234+
235+
sumfile_dir=opts_dict['sumfile']
236+
first_file = nc.Dataset(ifiles[0],"r")
237+
machineid=''
238+
compiler=''
239+
240+
global_att=first_file.ncattrs()
241+
for attr_name in global_att:
242+
val = getattr(first_file, attr_name)
243+
if attr_name == 'model_version':
244+
if val.find("-") != -1:
245+
model_version=val[0:val.find('-')]
246+
else:
247+
model_version=val
248+
elif attr_name == 'compset':
249+
compset=val
250+
elif attr_name == 'testtype':
251+
testtype=val
252+
if val == 'UF-ECT':
253+
testtype = 'uf_ensembles'
251254
opts_dict['eet']=len(ifiles)
252-
elif v=='ECT':
255+
elif val=='ECT':
253256
testtype='ensembles'
254-
elif v=='POP':
255-
testtype=v+'_ensembles'
256-
elif k=='machineid':
257-
machineid=v
258-
elif k=='compiler':
259-
compiler=v
260-
elif k=='grid':
261-
grid=v
262-
if 'testtype' in global_att:
263-
sumfile_dir=sumfile_dir+'/'+testtype+'/'
264-
else:
265-
print "ERROR: No global attribute testtype in your validation file => EXITING...."
266-
sys.exit(2)
267-
if 'model_version' in global_att:
268-
sumfile_dir=sumfile_dir+'/'+model_version+'/'
269-
else:
270-
print "ERROR: No global attribute model_version in your validation file => EXITING...."
271-
sys.exit(2)
272-
if (os.path.exists(sumfile_dir)):
273-
thefile_id=0
274-
for i in os.listdir(sumfile_dir):
275-
if (os.path.isfile(sumfile_dir+i)):
276-
sumfile_id=nc.Dataset(sumfile_dir+i,'r')
277-
sumfile_gatt=sumfile_id.ncattrs()
278-
if 'grid' not in sumfile_gatt and 'resolution' not in sumfile_gatt:
279-
print "ERROR: No global attribute grid or resolution in the summary file => EXITING...."
280-
sys.exit(2)
281-
if 'compset' not in sumfile_gatt:
282-
print "ERROR: No global attribute compset in the summary file"
283-
sys.exit(2)
284-
if sumfile_gatt['resolution']==grid and sumfile_gatt['compset']==compset:
285-
thefile_id=sumfile_id
286-
if thefile_id==0:
287-
print "ERROR: The validation files don't have a matching ensemble summary file to compare => EXITING...."
288-
sys.exit(2)
289-
else:
290-
print "ERROR: Could not locate directory "+sumfile_dir + " => EXITING...."
291-
sys.exit(2)
292-
return sumfile_dir+i,machineid,compiler
257+
elif v=='POP':
258+
testtype=val+'_ensembles'
259+
elif attr_name == 'machineid':
260+
machineid=val
261+
elif attr_name == 'compiler':
262+
compiler=val
263+
elif attr_name == 'grid':
264+
grid=val
265+
266+
if 'testtype' in global_att:
267+
sumfile_dir=sumfile_dir+'/'+testtype+'/'
268+
else:
269+
print "ERROR: No global attribute testtype in your validation file => EXITING...."
270+
sys.exit(2)
271+
272+
if 'model_version' in global_att:
273+
sumfile_dir=sumfile_dir+'/'+model_version+'/'
274+
else:
275+
print "ERROR: No global attribute model_version in your validation file => EXITING...."
276+
sys.exit(2)
277+
278+
first_file.close()
279+
280+
if (os.path.exists(sumfile_dir)):
281+
thefile_id=0
282+
for i in os.listdir(sumfile_dir):
283+
if (os.path.isfile(sumfile_dir+i)):
284+
sumfile_id=nc.Dataset(sumfile_dir+i,'r')
285+
sumfile_gatt=sumfile_id.ncattrs()
286+
if 'grid' not in sumfile_gatt and 'resolution' not in sumfile_gatt:
287+
print "ERROR: No global attribute grid or resolution in the summary file => EXITING...."
288+
sys.exit(2)
289+
if 'compset' not in sumfile_gatt:
290+
print "ERROR: No global attribute compset in the summary file"
291+
sys.exit(2)
292+
if getattr(sumfile_id, 'resolution') == grid and getsttr(sumfile_id, 'compset') == compset:
293+
thefile_id=sumfile_id
294+
sumfile_id.close()
295+
if thefile_id==0:
296+
print "ERROR: The verification files don't have a matching ensemble summary file to compare => EXITING...."
297+
sys.exit(2)
298+
else:
299+
print "ERROR: Could not locate directory "+sumfile_dir + " => EXITING...."
300+
sys.exit(2)
301+
302+
303+
return sumfile_dir+i,machineid,compiler
293304

294305
#
295306
# Create some variables and call a function to calculate PCA

0 commit comments

Comments
 (0)