Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 0ba41ed

Browse files
Merge pull request #27 from NCAR/update_requiredVars
Add extra features to requested variable
2 parents 6e63a27 + 3be2c92 commit 0ba41ed

File tree

3 files changed

+68
-66
lines changed

3 files changed

+68
-66
lines changed

scripts/createOutputSpecs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def create_output(table_dict, id, definitions, attributes, output_path, args):
7272
#print '\n\n',variables.keys(),'\n\n'#,axes,'\n',table_info
7373

7474
# Get variables needed to piece together the filename
75-
identifier = id.split('_')
75+
identifier = id
7676
if ('model_id') in attributes.keys():
7777
model = attributes['model_id']
7878
else:
@@ -87,7 +87,7 @@ def create_output(table_dict, id, definitions, attributes, output_path, args):
8787
attributes['grid_index']))
8888
else:
8989
ripfg = ''
90-
table = identifier[1]
90+
table = identifier
9191
attributes['experiment_id'] = table
9292
attributes['experiment'] = table
9393
today = datetime.datetime.now()
@@ -125,7 +125,7 @@ def create_output(table_dict, id, definitions, attributes, output_path, args):
125125
var["attributes"] = variables[v]
126126
var["definition"] = definitions[v]
127127
var["filename"] = f_name
128-
if 'type' in variables[v].keys() and variables[v]['type'] != 'None':
128+
if 'type' in variables[v].keys() and variables[v]['type'] != 'None' and variables[v]['type'] != '':
129129
var["datatype"] = data_types[variables[v]['type']]
130130
else:
131131
var["datatype"] = 'None'
@@ -229,6 +229,8 @@ def main(argv=None):
229229
for t in exp_dict.keys():
230230
create_output(exp_dict[t], t, definitions, attributes, args.outputpath, args)
231231

232+
for t in sorted(exp_dict.keys()):
233+
print t, len(exp_dict[t]['variables'])
232234

233235
if __name__ == '__main__':
234236
main()

scripts/requiredVars

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def load(defs):
3333
return def_dict
3434

3535

36-
def write_xls(fn, total_request, request_by, definitions):
36+
def write_xls(fn, total_request, definitions):
3737

3838
# Create an excel workbook and setup some formatting
3939
workbook = xlsxwriter.Workbook(fn)
@@ -47,36 +47,33 @@ def write_xls(fn, total_request, request_by, definitions):
4747
for mt in sorted(total_request):
4848
worksheet = workbook.add_worksheet(mt)
4949
worksheet.set_column(0, 0, 20)
50-
worksheet.set_column(1, 1, 40)
50+
worksheet.set_column(1, 1, 60)
5151
worksheet.set_column(2, 2, 15)
5252
worksheet.set_column(3, 4, 40)
53+
worksheet.set_column(5, 5, 80)
5354
worksheet.write('A1', mt, header)
5455
worksheet.write('B1', ' # of Variables: '+str(len(total_request[mt])), bold)
5556
worksheet.write('A2', 'Variable', bold)
5657
worksheet.write('B2', 'Title', bold)
5758
worksheet.write('C2', 'Units', bold)
5859
worksheet.write('D2', 'Dimensions', bold)
59-
worksheet.write('E2', 'Model->CMIP Definition', bold)
60+
worksheet.write('E2', 'Requested By', bold)
61+
worksheet.write('F2', 'Model->CMIP Definition', bold)
6062
cr = 3
6163
# For each variable requested, add it's name, official title,
6264
# and supply a def if we have one already
6365
for v in sorted(total_request[mt]):
6466
worksheet.write('A'+str(cr), v, format)
65-
var_info = total_request[mt][v].split('-----')
66-
worksheet.write('B'+str(cr), var_info[0], format)
67-
worksheet.write('C'+str(cr), var_info[1], format)
68-
worksheet.write('D'+str(cr), var_info[2], format)
67+
worksheet.write('B'+str(cr), total_request[mt][v]['description'], format)
68+
worksheet.write('C'+str(cr), total_request[mt][v]['units'], format)
69+
worksheet.write('D'+str(cr), total_request[mt][v]['dimensions'], format)
70+
request = ' ,'.join(total_request[mt][v]['req_by'])
71+
worksheet.write('E'+str(cr), request, format)
6972
if v in definitions.keys():
70-
worksheet.write('E'+str(cr), definitions[v], format)
73+
worksheet.write('F'+str(cr), definitions[v], format)
7174
else: # We don't have a definition, create a border around a blank cell
72-
worksheet.write('E'+str(cr), '', format)
75+
worksheet.write('F'+str(cr), '', format)
7376
cr = cr + 1
74-
# List each mip that requested this table
75-
cr = 3
76-
worksheet.write('F2', 'Requested by:', bold)
77-
for m in request_by[mt]:
78-
worksheet.write('F'+str(cr), m)
79-
cr = cr + 1
8077

8178
workbook.close()
8279

@@ -86,7 +83,6 @@ def main(argv=None):
8683
dq = dreq.loadDreq()
8784
total_request = {}
8885
mips = []
89-
request_by = {}
9086
not_recognized = []
9187

9288
# Parse args
@@ -99,59 +95,63 @@ def main(argv=None):
9995

10096
for v in dq.coll['CMORvar'].items:
10197

102-
tab = v.mipTable
103-
if tab not in request_by.keys():
104-
request_by[tab] = []
105-
if v.prov not in request_by[tab]:
106-
request_by[tab].append(v.prov)
98+
if '-copy' not in v.label:
99+
tab = v.mipTable
107100

108-
if tab not in total_request.keys():
109-
total_request[tab] = {}
101+
if tab not in total_request.keys():
102+
total_request[tab] = {}
110103

111-
v_id = v.uid
112-
c_var = dq.inx.uid[v_id]
113-
if hasattr(c_var,'vid'):
114-
v_var = dq.inx.uid[c_var.vid]
115-
else:
116-
print 'Not able to recognize v_var for ', v.label
117-
v_var = None
118-
if hasattr(c_var,'stid'):
119-
s_var = dq.inx.uid[c_var.stid]
120-
if hasattr(s_var,'spid'):
121-
sp_var = dq.inx.uid[s_var.spid]
104+
if v.label not in total_request[tab].keys():
105+
total_request[tab][v.label] = {'req_by':[]}
106+
107+
if v.prov not in total_request[tab][v.label]['req_by']:
108+
total_request[tab][v.label]['req_by'].append(v.prov)
109+
110+
v_id = v.uid
111+
c_var = dq.inx.uid[v_id]
112+
113+
if hasattr(c_var,'vid'):
114+
v_var = dq.inx.uid[c_var.vid]
122115
else:
116+
print 'Not able to recognize v_var for ', v.label
117+
v_var = None
118+
if hasattr(c_var,'stid'):
119+
s_var = dq.inx.uid[c_var.stid]
120+
if hasattr(s_var,'spid'):
121+
sp_var = dq.inx.uid[s_var.spid]
122+
else:
123+
sp_var = None
124+
td = None
125+
if hasattr(s_var,'tmid'):
126+
t_var = dq.inx.uid[s_var.tmid]
127+
if hasattr(t_var,'dimensions'):
128+
t = t_var.dimensions
129+
if t != '' and t != 'None':
130+
td = t+'|'
131+
else:
132+
print 'Not able to recognize s_var for ', v
133+
s_var = None
123134
sp_var = None
124-
td = None
125-
if hasattr(s_var,'tmid'):
126-
t_var = dq.inx.uid[s_var.tmid]
127-
if hasattr(t_var,'dimensions'):
128-
t = t_var.dimensions
129-
if t != '' and t != 'None':
130-
td = t+'|'
131-
else:
132-
print 'Not able to recognize s_var for ', v
133-
s_var = None
134-
sp_var = None
135-
request = c_var.title
136-
if hasattr(v_var,'units'):
137-
request = request + '-----' + v_var.units
138-
else:
139-
request = request + '----- No units listed'
140-
if hasattr(sp_var, 'dimensions'):
141-
if td != None:
142-
request = request + '-----' + td + sp_var.dimensions
135+
total_request[tab][v.label]['description'] = c_var.title
136+
if 'None' not in c_var.description and c_var.description != '':
137+
total_request[tab][v.label]['description'] = total_request[tab][v.label]['description'] + ': ' + c_var.description
138+
if hasattr(v_var,'units'):
139+
total_request[tab][v.label]['units'] = v_var.units
140+
if 'ch4global' in v.label:
141+
print v_var.units
143142
else:
144-
request = request + '-----' + sp_var.dimensions
145-
else:
146-
request = request + '----- No dimensions listed)'
147-
if '-copy' not in v.label:
148-
total_request[tab][v.label] = request
143+
total_request[tab][v.label]['units'] = 'No units listed'
144+
if hasattr(sp_var, 'dimensions'):
145+
if td != None:
146+
total_request[tab][v.label]['dimensions'] = td + sp_var.dimensions
147+
else:
148+
total_request[tab][v.label]['dimensions'] = sp_var.dimensions
149+
else:
150+
total_request[tab][v.label]['dimensions'] = 'No dimensions listed'
149151

150-
# for mt in request_by.keys():
151-
# print '\ntable:', mt, request_by[mt], 'len: ',len(request_by[mt])
152152

153153
# Write out the xls spreadsheet
154-
write_xls(args.outputfile, total_request, request_by, definitions)
154+
write_xls(args.outputfile, total_request, definitions)
155155

156156
# for mt in total_request.keys():
157157
# print '#############################################'

source/pyconform/mip_table_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ def parse_table(self,exp,miptable,table_var_fields,table_axes_fields,table_field
498498
tab_split = dq.inx.uid[u].tab.split('!')
499499
tab = tab_split[len(tab_split)-1]
500500
else:
501-
tab = dq.inx.uid[u].tab
502-
#print miptable, tab
501+
tab = dq.inx.uid[u].tab
502+
print miptable, tab
503503
if miptable == None or miptable == tab:
504504
g_id = dq.inx.requestVarGroup.label[tab]
505505
if len(g_id) > 0:

0 commit comments

Comments
 (0)