Changeset 316 for CCCC


Ignore:
Timestamp:
13/04/15 21:15:57 (5 years ago)
Author:
mjuckes
Message:

class to support time axis interval checks added to utilities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CCCC/trunk/ceda_cc/utils_c4.py

    r307 r316  
    77from fcc_utils import mipTableScan 
    88from xceptions import * 
     9 
     10class timeInt(object): 
     11 
     12   vc = {'gregorian':0, 'standard':0, 'proleptic_gregorian':0, 'noleap':1, '365_day':1, 'all_leap':2, '366_day':2, '360_day':3, 'julian':0, 'none':None} 
     13   mnmx = [ (365,366),(365,365),(366,366),(360,360) ] 
     14   mmnmmx = [ (28,31),(28,31),(29,31),(30,30) ] 
     15   def __init__(self,cal='proleptic_gregorian',dpymn=None, dpymx=None,dpmmn=None,dpmmx=None,tol=1.e-6): 
     16     self.tol = tol 
     17     if not self.vc.has_key(cal) or cal == None: 
     18       assert dpymx != None and dpymn != None, 'If standard calendar is not use, dpymn and dpymx must be set' 
     19       assert dpmmx != None and dpmmn != None, 'If standard calendar is not use, dpmmn and dpmmx must be set' 
     20       self.dpymn = dpymn - tol 
     21       self.dpymx = dpymx + tol 
     22       self.dpmmn = dpmmn - tol 
     23       self.dpmmx = dpmmx + tol 
     24     else: 
     25       self.dpymn = self.mnmx[self.vc[cal]][0] - tol 
     26       self.dpymx = self.mnmx[self.vc[cal]][1] + tol 
     27       self.dpmmn = self.mmnmmx[self.vc[cal]][0] - tol 
     28       self.dpmmx = self.mmnmmx[self.vc[cal]][1] + tol 
     29     self.map = { 'yr':'P1Y','monClim':'P1M','mon':'P1M','day':'P1D','6hr':'P6H','3hr':'P3H'} 
     30     self.nd = { 'x':'y' } 
     31 
     32   def setUnit(self,u): 
     33     if u not in ['days','months','years']: 
     34         print  'Time unit %s not supported' % u 
     35         self.u = None 
     36     else: 
     37         self.u = u 
     38 
     39   def chk(self,v,u,f): 
     40      if not self.map.has_key(f): 
     41         return (0,'No frequency check available for f = %s' % f ) 
     42      if u not in ['days']: 
     43         return (0,'No frequency check available for units = %s' % u ) 
     44      x = self.map(f) 
     45      if x == 'P1Y': 
     46        return (v > self.dpymn) and (v < self.dpymx) 
     47      elif x == 'P1M': 
     48        return (v > self.dpmmn) and (v < self.dpmmx) 
     49      elif x == 'P1D': 
     50        return (v > 1.-self.tol) and (v < 1.+self.tol) 
     51      elif x == 'P6H': 
     52        return (v > 0.25-self.tol) and (v < 0.25+self.tol) 
     53      elif x == 'P3H': 
     54        return (v > 0.125-self.tol) and (v < 0.125+self.tol) 
     55       
    956 
    1057class reportSection(object): 
Note: See TracChangeset for help on using the changeset viewer.