dnamsel = [['rlon','srlon'],['rlat','srlat']]
for evar in fin.variables:
    # apply the domain selection on all variables that involve these dimensions
    procvar = True
    for ednamsel in dnamsel:
        found = False
        if type(ednamsel).__name__ == 'list':
            for eednamsel in ednamsel:
                if eednamsel in fin.variables[evar].dimensions:
                    found = True
        elif ednamsel in fin.variables[evar].dimensions:
            found = True
        if found == False:
            procvar = False

    if procvar:
        print ('processing variable: ',evar)
        datin =  [{'file':fin,'varname':evar,}]
        datout = [{'file':fout,'varname':evar},]
        pcd.pcd(func,dnamsel,datin,datout,appenddim=True)
    else:
        if evar not in fin.dimensions:
            print ('copying variable: ',evar)
            pcd.nccopyvariable(fin,fout,evar,copyvalues=True)

fout.close();print('output file written to:',fout )
fin.close()
# Unfortunatly, It not superfast. The reason is that the 'preperations' in pcd needs to be redone
# for each variable.

Exemple #2
0
import pynacolada as pcd
from Scientific.IO import NetCDF
fin = NetCDF.NetCDFFile('/home/hendrik/data/belgium_aq/rcm/aq09/stage1/int2lm/laf2009010100_urb_ahf.nc','r')
fout = NetCDF.NetCDFFile('/home/hendrik/data/belgium_aq/rcm/aq09/stage1/int2lm/laf2009010100_urb_ahf_test.nc','w')
pcd.nccopyvariable(fin,fout,'lat',copyvalues=True)
pcd.nccopyvariable(fin,fout,'lon',copyvalues=True)
pcd.nccopyvariable(fin,fout,'rlon',copyvalues=True)
pcd.nccopyvariable(fin,fout,'rlat',copyvalues=True)
pcd.nccopyvariable(fin,fout,'T',copyvalues=True)
pcd.nccopyvariable(fin,fout,'U',copyvalues=True)
pcd.nccopyvariable(fin,fout,'V',copyvalues=True)
pcd.nccopyattrfile(fin,fout)
fin.close()
fout.close()