Changeset 143


Ignore:
Timestamp:
01/04/14 10:21:59 (6 years ago)
Author:
mjuckes
Message:

extended attribute mapping support to prompt for missing global attriutes

Location:
CCCC/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • CCCC/trunk/amap2nco.py

    r141 r143  
    104104  import sys 
    105105  if len(sys.argv) != 4: 
    106     print """USAGE: 
    107 python map2nco.py   mappingsFile  inputDirectoryBase outputDirectoryBase 
     106    if os.path.isfile( 'USAGE_amap2nco.txt' ): 
     107      for l in open( 'USAGE_amap2nco.txt').readlines(): 
     108        print string.strip(l) 
     109    else: 
     110      print """USAGE: 
     111python amap2nco.py   mappingsFile  inputDirectoryBase outputDirectoryBase 
    108112mappingsFile: text file containing mapping information, generated by c4.py 
    109113inputDirectoryBase: initial part of the directory tree, to be replaced for corrected files 
    110114outputDirectoryBase: initial part of directory tree to be used for corrected files. 
    111115 
    112 WARNING 
    113 Note that this feature will only correct errors where there is an unambiguous correct value 
    114 Users should check intermediary files to ensure that changes make sense 
    115  
    116 e.g. 
    117 ## run the checking program 
    118 python c4.py -p CORDEX -D /tmp/batch1 --ld batch1_logs 
    119 ## after checking, mv the amapDraft.txt file generated by c4.py 
    120 mv amapDraft.txt amap_batch1.txt 
    121 ## run the checking program in 'virtual substition' mode.  If all errors are captured by the  
    122 ## substition list generated the code will indicate that there are no remaining errors. 
    123 python c4.py -p CORDEX -D /tmp/batch1 --ld batch1_logs  --aMap amap_batch1.txt 
    124  
    125 ## the "amapDraft.txt" file contains a condensed view of substistution -- the 2nd run of c4.py  
    126 ## will create an extended list in "attributeMappingsLog.txt" 
    127  
    128 ## Generate a script to correct files 
    129 python map2nco.py   attributeMappingsLog.txt /tmp/batch1 /tmp/batch1_corrected 
    130 ## 
    131 ## Run the script 
    132 bash ncoscript.sh 
    133  
    134 ## 
    135 ## check the modified files 
    136 python c4.py -p CORDEX -D /tmp/batch1_corrected --ld batch1_corrected_logs""" 
     116See file USAGE_amap2nco.txt in code repository for more detail""" 
    137117 
    138118  else: 
  • CCCC/trunk/c4.py

    r141 r143  
    133133              self.da[m[1][0][1]][targ] = m[2][1] 
    134134              self.atMapLog.write( '@ax:"%s","%s","%s","%s","%s"\n' % (self.fpath, m[1][0][1], targ, thisval, m[2][1]) ) 
    135         elif m[1][0][0][0] != "@": 
     135        elif m[1][0][0] == "@": 
    136136            this = self.ga 
    137137            apThis = True 
    138             for c in m[1]: 
     138## apply change where attribute absent only 
     139            for c in m[1][1:]: 
    139140              if c[0] not in this.keys(): 
    140                 apThis = False 
    141               elif c[1] != this[c[0]]: 
     141                if c[1] != '__absent__': 
     142                  apThis = False 
     143              elif c[1] == '__absent__' or c[1] != this[c[0]]: 
    142144                apThis = False 
    143145            if m[2][0] != '': 
     
    148150              if log != None: 
    149151                log.info( 'Setting %s to %s' % (targ,m[2][1]) ) 
    150               print 'Setting %s:%s to %s' % (m[1][0][1],targ,m[2][1]) 
     152              ##print 'Setting %s to %s' % (targ,m[2][1]) 
    151153              thisval = self.ga.get( targ, None ) 
    152154              self.ga[targ] = m[2][1] 
  • CCCC/trunk/utils_c4.py

    r141 r143  
    106106    self.messageCount = 0 
    107107    self.init() 
     108    if not hasattr( self.parent, 'amapListDraft' ): 
     109      self.parent.amapListDraft = [] 
    108110 
    109111  def isInt(self,x): 
     
    337339         m.append(k) 
    338340 
    339     gaerr = not self.test( len(m)  == 0, 'Required global attributes missing: %s' % str(m) ) 
     341    if not self.test( len(m)  == 0, 'Required global attributes missing: %s' % str(m) ): 
     342      gaerr = True 
     343      for k in m: 
     344        self.parent.amapListDraft.append( '#@;%s=%s|%s=%s' % (k,'__absent__',k,'<insert attribute value and uncomment>') ) 
    340345 
    341346    self.checkId = '002' 
     
    357362      if not varAts[varName].has_key(k): 
    358363         m.append(k) 
    359     vaerr = not self.test( len(m)  == 0, 'Required variable attributes missing: %s' % str(m) ) 
     364    if not self.test( len(m)  == 0, 'Required variable attributes missing: %s' % str(m) ): 
     365      vaerr = True 
     366      for k in m: 
     367        self.parent.amapListDraft.append( '#@var=%s;%s=%s|%s=%s' % (varName,k,'__absent__',k,'<insert attribute value and uncomment>') ) 
     368        print self.parent.amapListDraft[-1] 
     369    ##vaerr = not self.test( len(m)  == 0, 'Required variable attributes missing: %s' % str(m) ) 
    360370 
    361371    ##if vaerr or gaerr: 
     
    417427          raise 
    418428 
    419     self.test( len(m)  == 0, 'Global attributes do not match constraints: %s' % str(m) ) 
     429    if not self.test( len(m)  == 0, 'Global attributes do not match constraints: %s' % str(m) ): 
     430      for t in m: 
     431        self.parent.amapListDraft.append( '#@;%s=%s|%s=%s' % (t[0],str(t[1]),t[0],'<insert attribute value and uncomment>' + str(t[2]) ) ) 
    420432 
    421433    self.checkId = '007' 
Note: See TracChangeset for help on using the changeset viewer.