Changeset 911 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 20, 2016, 1:40:59 PM (8 years ago)
Author:
lfita
Message:

Removing spurious prints

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r904 r911  
    4141# significant_decomposition: Function to decompose a given number by its signifcant potencies
    4242# singleline_printing_class: Function to print all the values of a given class in a single line to be parseavel
     43# stagger_unstagger: Function to de-stagger a variable
    4344# str_list: Function to obtain a list from a string givin a split character
    4445# subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips
     
    463464    if totunits == 'second':
    464465        itime = dt.datetime(int(iyrS),int(imoS),int(idaS),int(ihoS),int(imiS),int(iseS))
    465         print 'Lluis ', edate[12:15], '00'
    466466        if edate[12:15] != '00':
    467467            etime = dt.datetime(int(eyrS), int(emoS), int(edaS), int(ehoS), int(emiS), int(eseS)+1)
     
    628628    CFvar_DIAGvar(varn)
    629629      [varn]= CF name of the variable
    630     >>> CFvar_MODvar('pr')
     630    >>> CFvar_DIAGvar('pr')
    631631    {'RAINTOT': ['RAINC', 'RAINNC']}
    632     >>> CFvar_MODvar('hurs')
     632    >>> CFvar_DIAGvar('hurs')
    633633    {'TSrhs': ['psfc', 't', 'q'], 'LMDZrhs': ['psol', 't2m', 'q2m'], 'WRFrhs': ['PSFC', 'T2', 'Q2']}
    634634    """
     
    64426442#                quit(-1)
    64436443            if np.mod(iptpos,fracs) == 0:
    6444                 print 'Lluis syncronizing!'
    64456444                onc.sync()
    64466445    if out:
     
    78667865    return listv
    78677866
     7867def stagger_unstagger(varv, dndims, udims):
     7868    """ Function to de-stagger a variable
     7869      varv= values of the variable to de-stagger
     7870      dndims = dn[x/y/z/t] list of the names of the dimenions of the variable     
     7871      udims = ud[x/y/z/t] unstaggered dictionary with the dimenions of the variable
     7872
     7873    >>> mat = np.arange((20), dtype=np.float).reshape(5,4)
     7874    >>> dmat = ['dystaggered','dx']
     7875    >>> unstagdims = {'dy': 4, 'dx': 4}
     7876    >>> stagger_unstagger(mat, dmat, unstagdims)
     7877    [[  2.   3.   4.   5.]
     7878     [  6.   7.   8.   9.]
     7879     [ 10.  11.  12.  13.]
     7880     [ 14.  15.  16.  17.]]
     7881    """
     7882    fname = 'stagger_unstagger'
     7883
     7884    udndims = list(udims.keys())
     7885
     7886    idim = 0
     7887    vdstaggered = {}
     7888    newdims = []
     7889
     7890    idim = 0
     7891    for vd in dndims:
     7892        idim = dndims.index(vd)
     7893        if searchInlist(udndims, vd):
     7894            if varv.shape[idim] - 1 == udims[vd]:
     7895                vdstaggered[vd] =  varv.shape[idim] - 1
     7896            else:
     7897                vdstaggered[vd] = varv.shape[idim]
     7898        else:
     7899            vdstaggered[vd] = varv.shape[idim] - 1
     7900            print '  ' + fname + ": new dimension '" + vd + "' with length :",       \
     7901              varv.shape[idim], 'as staggered dim'
     7902        newdims.append(vdstaggered[vd])
     7903
     7904    if len(vdstaggered) > 1:
     7905        destagger_varv = np.zeros(tuple(newdims), dtype=np.float)
     7906
     7907        ndim = 0
     7908        upstagslc = []
     7909        downstagslc = []
     7910        for vd in vdstaggered.keys():
     7911            idim = dndims.index(vd)
     7912            if vdstaggered[vd] != varv.shape[idim]:
     7913                upstagslc.append(slice(1,varv.shape[idim]))
     7914                downstagslc.append(slice(0,varv.shape[idim]-1))
     7915            else:
     7916                upstagslc.append(slice(0,varv.shape[idim]))
     7917                downstagslc.append(slice(0,varv.shape[idim]))
     7918        destagger_varv = 0.5*(varv[tuple(upstagslc)] + varv[tuple(downstagslc)])
     7919   
     7920        return destagger_varv
     7921    else:
     7922        return varv
     7923
    78687924#quit()
    78697925
Note: See TracChangeset for help on using the changeset viewer.