Changeset 77


Ignore:
Timestamp:
22/10/13 14:04:47 (7 years ago)
Author:
mjuckes
Message:

Corrected bugs related to (1) cell_methods; (2) cordex time range for 3hr data

Location:
CCCC/trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • CCCC/trunk/utils_c4.py

    r76 r77  
    11 
    2 import string, re, os, sys 
     2import string, re, os, sys, traceback 
    33 
    44from fcc_utils import mipTableScan 
     
    126126 
    127127  def logMessage(self, msg, error=False ): 
    128     if self.parent.log != None: 
     128    if self.parent != None and self.parent.log != None: 
    129129       if error: 
    130130         self.parent.log.error( msg ) 
     
    135135 
    136136  def log_exception( self, msg): 
    137     if self.parent.log != None: 
     137    if self.parent != None and self.parent.log != None: 
    138138        self.parent.log.error("Exception has occured" ,exc_info=1) 
    139139    else: 
     
    216216      checkTrangeLen = True 
    217217      self.domain = self.fnParts[1] 
    218       self.freq = self.fnParts[7] 
    219218    elif self.cls == 'SPECS': 
    220219      self.domain = None 
    221       self.freq = self.fnParts[1] 
    222220      self.fnPartsOkLen = [6,7] 
    223221      self.fnPartsOkFixedLen = [6,] 
    224222      self.fnPartsOkUnfixedLen = [7,] 
    225223      checkTrangeLen = False 
     224 
    226225    self.test( len(bits) in self.fnPartsOkLen, 'File name not parsed in %s elements [%s]' % (str(self.fnPartsOkLen),str(bits)), abort=True ) 
     226 
     227    if self.cls == 'CORDEX': 
     228      self.freq = self.fnParts[7] 
     229    elif self.cls == 'SPECS': 
     230      self.freq = self.fnParts[1] 
    227231 
    228232    self.var = self.fnParts[0] 
     
    250254    self.checkId, ok = ('004',True) 
    251255    if len(self.fnParts) == 9 and checkTrangeLen: 
    252       ltr = { 'mon':6, 'sem':6, 'day':8, '3hr':10, '6hr':10 } 
     256      ltr = { 'mon':6, 'sem':6, 'day':8, '3hr':[10,12], '6hr':10 } 
    253257      ok &=self.test( self.freq in ltr.keys(), 'Frequency [%s] not recognised' % self.freq, part=True ) 
    254258      if ok: 
    255         msg = 'Length of time range parts [%s,%s] not equal to required length [%s] for frequency %s' % (self.fnTimeParts[0],self.fnTimeParts[1],ltr[self.freq],self.freq) 
    256         ok &= self.test( len(self.fnTimeParts[0]) == ltr[self.freq], msg, part=True ) 
     259        if type( ltr[self.freq] ) == type(0): 
     260          msg = 'Length of time range parts [%s,%s] not equal to required length [%s] for frequency %s' % (self.fnTimeParts[0],self.fnTimeParts[1],ltr[self.freq],self.freq) 
     261          ok &= self.test( len(self.fnTimeParts[0]) == ltr[self.freq], msg, part=True ) 
     262        elif type( ltr[self.freq] ) in [type([]),type( () )]: 
     263          msg = 'Length of time range parts [%s,%s] not in acceptable list [%s] for frequency %s' % (self.fnTimeParts[0],self.fnTimeParts[1],str(ltr[self.freq]),self.freq) 
     264          ok &= self.test( len(self.fnTimeParts[0]) in ltr[self.freq], msg, part=True ) 
    257265 
    258266      if ok: 
     
    322330    self.checkId = '004' 
    323331    m = [] 
    324     reqAts = self.requiredVarAttributes 
     332    reqAts = self.requiredVarAttributes[:] 
    325333    if varGroup != 'fx': 
    326334      reqAts.append( 'cell_methods' ) 
     
    709717    self.ee = ee 
    710718 
    711   def check(self, recorder=None,calendar='None'): 
     719  def check(self, recorder=None,calendar='None',norun=False): 
    712720    self.errorCount = 0 
    713721    self.recorder=recorder 
     
    717725    else: 
    718726      self.enddec = 31 
    719  
    720     self.runChecks() 
     727    mm = { 'enddec':self.enddec } 
     728    self.pats = {'mon':('(?P<d>[0-9]{3})101','(?P<e>[0-9]{3})012'), \ 
     729            'sem':('(?P<d>[0-9]{3})012','(?P<e>[0-9]{3})011'), \ 
     730            'day':('(?P<d>[0-9]{3}[16])0101','(?P<e>[0-9]{3}[50])12%(enddec)s' % mm), \ 
     731            'subd':('(?P<d>[0-9]{4})0101(?P<h1>[0-9]{2})(?P<mm>[30]0){0,1}$', '(?P<e>[0-9]{4})12%(enddec)s(?P<h2>[0-9]{2})([30]0){0,1}$' % mm ), \ 
     732            'subd2':('(?P<d>[0-9]{4})0101(?P<h1>[0-9]{2})', '(?P<e>[0-9]{4})010100' ) } 
     733 
     734    if not norun: 
     735      self.runChecks() 
    721736 
    722737  def checkTrange(self): 
     
    731746 
    732747  def checkThisTrange( self, tt, group, var): 
    733     mm = { 'enddec':self.enddec } 
    734     pats = {'mon':('(?P<d>[0-9]{3})101','(?P<e>[0-9]{3})012'), \ 
    735             'sem':('(?P<d>[0-9]{3})012','(?P<e>[0-9]{3})011'), \ 
    736             'day':('(?P<d>[0-9]{3}[16])0101','(?P<e>[0-9]{3}[50])12%(enddec)s' % mm), \ 
    737             'subd':('(?P<d>[0-9]{4})0101(?P<h1>[0-9]{2})', '(?P<e>[0-9]{4})12%(enddec)s(?P<h2>[0-9]{2})' % mm ), \ 
    738             'subd2':('(?P<d>[0-9]{4})0101(?P<h1>[0-9]{2})', '(?P<e>[0-9]{4})010100' ) } 
    739748 
    740749    if group in ['3hr','6hr']: 
     
    742751    else: 
    743752       kg = group 
    744     ps = pats[kg] 
     753    ps = self.pats[kg] 
    745754    rere = (re.compile( ps[0] ), re.compile( ps[1] ) ) 
    746755 
Note: See TracChangeset for help on using the changeset viewer.