Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(0)  |  Derive(0)  |  Import(1)
Convert the CAMx irr files for the 4-k and 1-k simulations to the NetCDF format

        def irr2ncf(irrinf,irroutf,lay=None,row=None,col=None,verbose=False):
    """
    Convert the CAMx irr files for the 4-k and 1-k simulations to the NetCDF format
    """
    if type(irrinf)==str:
        try:
            irrinf=irr_memmap(irrinf)
        except OverflowError:
            irrinf=irr(irrinf)

    if type(irroutf)==str:
        irroutf=ncf(irroutf,'w+')

    if lay==None:
        lay=int(irrinf.dimensions['LAY'])
    
    if row==None:
        row=int(irrinf.dimensions['ROW'])
    
    if col==None:
        col=int(irrinf.dimensions['COL'])
    
    if verbose:
        print >> sys.stderr, "Add irr Globals"
    irroutf.UPNAM = "irr FILE         " ;
    irroutf.GDNAM = "" ;
    irroutf.IOAPI_VERSION = "2.2 2003141 (May 21, 2003)" ;
    irroutf.FILEDESC = irrinf.rffile.infile.name
    irroutf.VGTYP = 2 ;
    irroutf.GDTYP = 2 ;
    irroutf.FTYPE = 1 ;
    irroutf.HISTORY = "New File written by irr2ncf" ;
    irroutf.EXEC_ID = "" ;
    irroutf.NLAYS = lay ;
    irroutf.NROWS = row ;
    irroutf.NCOLS = col ;
    irroutf.NVARS = 2 ;
    irroutf.NTHIK = 1 ;
    try:
        irroutf.SDATE = irrinf.SDATE ;
        irroutf.STIME = irrinf.STIME ;
        irroutf.TSTEP = irrinf.TSTEP ;
    except:
        irroutf.SDATE = irrinf.start_date ;
        irroutf.STIME = irrinf.start_time ;
        irroutf.TSTEP = irrinf.time_step ;
        

    if verbose:
        print >> sys.stderr, "Add irr Dimensions"
        
    irroutf.createDimension('VAR',int(irroutf.NVARS))
    irroutf.createDimension('LAY',int(irroutf.NLAYS))
    irroutf.createDimension('ROW',int(irroutf.NROWS))
    irroutf.createDimension('COL',int(irroutf.NCOLS))
    irroutf.createDimension('TSTEP',None)

    if verbose:
        print >> sys.stderr, "Create Variables"
        
    rxn_iter=[i for i in irrinf.variables.keys()]
    
    try:
        j=array(irrinf.memmaps['J'])
        i=array(irrinf.memmaps['I'])
        rowwindow=slice(j.min()-1,j.max())
        colwindow=slice(i.min()-1,i.max())
    except:
        dom=irrinf.activedomain
        rowwindow=slice(dom['jstart']-1,dom['jend'])
        colwindow=slice(dom['istart']-1,dom['iend'])

        
    for rxn in rxn_iter:
            print >> sys.stderr, rxn
            tmp_var=irroutf.createVariable(rxn,'f',('TSTEP','LAY','ROW','COL'))
            tmp_var.long_name=rxn
            tmp_var.var_desc=tmp_var.long_name
            tmp_var.units='ppm'
            irroutf.sync()

    if verbose:
        print >> sys.stderr, "irr Variables Fill"

    for rxn in rxn_iter:
            print >> sys.stderr, rxn
            tmp_var=irroutf.variables[rxn]
            tmp_var[:] = 0
            tmp_var[:,:,rowwindow,colwindow]=irrinf.variables[rxn]
            irroutf.sync()
    
    irrinf.close()
    if verbose:
        print >> sys.stderr, "irr Done"
        
    return irroutf
        


src/p/y/pyPA-1.0rc/src/pyPA/utils/CAMxFiles.py   pyPA(Download)
gridded_emissions=uamiv
 
from CAMxFileConverter import irr2ncf,ipr2ncf
 
__doc__="""