Changeset 383 for CMIP6dreqbuild/trunk/src
- Timestamp:
- 15/09/15 11:55:28 (7 years ago)
- Location:
- CMIP6dreqbuild/trunk/src/workbook
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
CMIP6dreqbuild/trunk/src/workbook/importShDreq.py
r382 r383 13 13 from utils_wb import uniCleanFunc 14 14 15 class s1(object): 16 def __init__(self): 17 self.a = collections.defaultdict( list ) 18 15 19 empty=re.compile('^$') 16 20 … … 39 43 self.upda = {} 40 44 self.insert = {} 45 46 self.objectives = collections.defaultdict( dict ) 47 self.objectiveLinks = collections.defaultdict( dict ) 48 41 49 if repl: 42 50 self.importRepl() … … 50 58 assert all( fok), 'Required input file(s) missing' 51 59 52 for sh in [rq. refti, rq.revti, rq.vars, rq.grps, rq.rqvg, rq.rqli, rq.rqit, rq.rqsect]:60 for sh in [rq.objec,rq.refti, rq.revti, rq.vars, rq.grps, rq.rqvg, rq.rqli, rq.rqit, rq.rqsect]: 53 61 print sh['__info__'] 54 62 … … 103 111 assert len( dups ) == 0, 'Duplicate refs: %s, %s' % (str(dups),str(map( lambda x: rq.rqvg[x[1]], dups )) ) 104 112 105 for k in [ 'var','ovar','groupitem', 'revisedtabitem', 'requestlink', 'requestitem','requestvargroup','tablesection' ]: 113 for k in [ 'objective','var','ovar','groupitem', 'revisedtabitem', 'requestlink', 'requestitem','requestvargroup','tablesection' ]: 114 ## set labmod False for section in which label coercion is not wanted 115 labmod = True 106 116 ##for k in [ 'var']: 107 thissh = {'var':rq.vars,'ovar':rq.refti, 'groupitem':rq.grps, \ 117 ## keys here match section element names in schema 118 thissh = {'objective':rq.objec, 'var':rq.vars,'ovar':rq.refti, 'groupitem':rq.grps, \ 108 119 'revisedtabitem':rq.revti, 'requestlink':rq.rqli, 'requestitem':rq.rqit, \ 109 120 'requestvargroup':rq.rqvg, 'tablesection':rq.rqsect}[k] … … 126 137 ######### NEED TO CLEAN THIS IF ITEMS FROM OTHER SECTIONS ARE FILTERED 127 138 ####################################################################### 139 dothis = True 128 140 if k != 'var': 129 141 item = doc.createElement( 'item' ) 130 item.setAttribute( 'id', 'tmpid.%4.4i' % idk ) 131 dothis = True 132 if k == 'var': 142 if k == 'objective': 143 ## - mip; tab; expt; rlid; ny 144 labmod = False 145 kk = ['mip', 'label', 'title', 'description'] 146 thisl = string.replace(string.strip(str( ll[1] ) ), '-', ' ') 147 ## camelcase this label. 148 thisl = string.replace( string.capwords( thisl ), ' ', '' ) 149 mip = str( ll[0] ) 150 self.objectives[mip][thisl] = i 151 for j in range(len(kk)): 152 thisv = str( ll[j] ) 153 item.setAttribute( kk[j], thisv ) 154 item.setAttribute( 'uuid', str(i) ) 155 elif k == 'var': 133 156 ##- sn; units; description; procnote; procComment; prov 134 157 ##['label', 'title', 'sn', 'units', 'description', 'procnote', 'procComment', 'prov'] … … 169 192 u'PMIP3_Oclim':'monClim', u'SPECS_Amon':'mon', u'SPECS_Lmon':'mon', u'CMIP5_cf3hr':'3hr', u'CORDEX_3h':'3hr', \ 170 193 u'CCMI1_annual':'yr', u'CMIP5_Oyr':'yr'} 171 kk = ['uuid', 'comment', 'deflate_level', 'shuffle', 'ok_max_mean_abs', 'flag_meanings', 'type', 'ok_min_mean_abs', 'sn', 'deflate', 'title', 'valid_min', 'cell_methods', 'flag_values', 'cell_measures', 'out_name', 'modeling_realm', 'units', 'cell_methods_xx', 'valid_max', 'positive', 'var', 'mipTable', 'dimensions', 'vid', 'gpid','rowIndex' ]194 kk = ['uuid', 'comment', 'deflate_level', 'shuffle', 'ok_max_mean_abs', 'flag_meanings', 'type', 'ok_min_mean_abs', 'sn', 'deflate', 'title', 'valid_min', 'cell_methods', 'flag_values', 'cell_measures', 'out_name', 'modeling_realm', 'units', 'cell_methods_xx', 'valid_max', 'positive', 'var', 'mipTable', 'dimensions', 'vid', 'gpid','rowIndex','priority'] 172 195 ## uuid; comment; deflate_level; shuffle; ok_max_mean_abs; flag_meanings; type; ok_min_mean_abs; sn; deflate; valid_min; cell_methods; flag_values; cell_measures; out_name; modeling_realm; units; cell_methods_xx; valid_max; positive; var; mipTable; dimensions; vid 196 ix_gpid = kk.index( 'gpid' ) 173 197 174 198 thisl = string.strip( str( ll[21] ) ) 175 199 for j in range( min(len(kk),len(ll)) ): 200 if kk[j] == 'priority': 201 ll[j] = int(ll[j]) 202 176 203 if j != 21: 177 204 item.setAttribute( kk[j], str( ll[j] ) ) 205 178 206 if len(ll) < len(kk): 179 207 print 'ERROR.015.0001: record length short %s (%s):: %s' % (len(ll),len(kk),ll) … … 197 225 assert len(kk) == len(ll), 'length mismatch, %s %s' % (len(kk),len(ll)) 198 226 # - group; table; freq; descriptionEx; shape; levels; tstyle; mask; mip; mip2; uuid; new; vid 227 ix_gpid = kk.index( 'gpid' ) 199 228 thisl = string.strip(str( ll[1] ) ) 200 229 for j in range(len(kk)): … … 209 238 thisl = string.split(thisl)[0] 210 239 thisuuid = ll[11] 211 gpid = str(ll[-3]) 240 241 gpid = str(ll[ix_gpid]) 212 242 if not rq.rqvg.has_key(gpid): 213 243 print 'ERROR.015.0010: gpid not found %s' % str(ll) … … 262 292 kk = ['uid', 'mip', 'tab', 'objective', 'grid', 'gridreq', 'comment', 'opt','opar','ref', 'refNote', 'refid'] 263 293 emap = {'uid':'uuid'} 294 mip = string.strip(str( ll[1] ) ) 295 obj = string.strip(str( ll[3] ) ) 296 if mip == "GMMIP": 297 bits = string.split( obj, ' ' ) 298 else: 299 bits = [ string.replace( string.capwords( string.strip(x) ), ' ', '' ) for x in string.split( obj, ',' ) ] 300 for b in bits: 301 self.objectiveLinks[mip][b] = str( ll[0] ) 302 264 303 thisl = string.strip(str( ll[2] ) ) 265 304 for j in range(len(kk)): … … 279 318 for j in range(len(kk)): 280 319 if kk[j] == 'ny': 281 thisv = str( int(ll[j]) ) 320 if ll[j] == '': 321 thisv = 0 322 else: 323 try: 324 thisv = str( int(ll[j]) ) 325 except: 326 print 'SEVERE: failed to set "ny": %s' % str(ll) 327 thisv = 999 282 328 else: 283 329 thisv = str( ll[j] ) … … 296 342 #### 297 343 if dothis: 298 if string.find( thisl, '_' ) != -1: 344 if labmod: 345 if string.find( thisl, '_' ) != -1: 299 346 #print 'WARNING: underscore in label', ll 300 thisl = string.replace( thisl, '_', '-' )301 if string.find( thisl, '*' ) != -1:302 #print 'WARNING: star in label', ll303 thisl = string.replace( thisl, '*', '-' )304 if string.find( thisl, '!' ) != -1:347 thisl = string.replace( thisl, '_', '-' ) 348 if string.find( thisl, '*' ) != -1: 349 #print 'WARNING: star in label', ll 350 thisl = string.replace( thisl, '*', '-' ) 351 if string.find( thisl, '!' ) != -1: 305 352 #print 'WARNING: exclamation in label', ll 306 thisl = string.replace( thisl, '!', '-' )307 if string.find( thisl, ' ' ) != -1:353 thisl = string.replace( thisl, '!', '-' ) 354 if string.find( thisl, ' ' ) != -1: 308 355 #print 'WARNING: space in label', ll 309 thisl = string.replace( thisl, ' ', '-' )310 if string.find( thisl, ':' ) != -1:356 thisl = string.replace( thisl, ' ', '-' ) 357 if string.find( thisl, ':' ) != -1: 311 358 #print 'WARNING: colon in label', ll 312 thisl = string.replace( thisl, ':', '-' )359 thisl = string.replace( thisl, ':', '-' ) 313 360 item.setAttribute( 'label', thisl ) 314 361 if k == 'var': … … 321 368 print '******************************************' 322 369 323 ##for k in rqvg_extra.keys(): 324 ##item = doc.createElement( 'item' ) 325 ##ff['...' ][0].appendChild( item ) 326 370 371 372 373 def finish(self): 327 374 this = doc.getElementsByTagName('remarks')[0] 328 375 dil = this.getElementsByTagName('item') -
CMIP6dreqbuild/trunk/src/workbook/scansh.py
r382 r383 24 24 self.rqvg = sopen( 'requestVarGroup' ) 25 25 self.rqsect = sopen( 'requestVarSections' ) 26 self.objec = sopen( 'objectives' ) 26 27 27 28 self.cmip5Grps = shelve.open( '%s/cmip5Groups' % odir, 'r' ) -
CMIP6dreqbuild/trunk/src/workbook/utils_wb.py
r336 r383 14 14 if type(ss) in [type('x'),type(u'x')]: 15 15 ss = string.replace( ss, u'\u2013', '-' ) 16 ss = string.replace( ss, u'\u2014', '-u2014-' ) 16 17 ss = string.replace( ss, u'\u2010', '-' ) 17 18 ss = string.replace( ss, u'\u2018', "'" )
Note: See TracChangeset
for help on using the changeset viewer.