Changeset 1561 in lmdz_wrf for trunk


Ignore:
Timestamp:
May 10, 2017, 10:18:47 PM (8 years ago)
Author:
lfita
Message:

Adding 'ifreq_anom', ìfreq_mean', 'ifreq_normmeanstd' in `compute_opersvarsfiles'

Location:
trunk/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/documentation/ncmanage/compute_opersvarsfiles.html

    r1538 r1561  
    3838      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'divc',[modval1]: [prevalues] divide by [modval1]<BR>
    3939      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'forwrdderiv',[N],[ord],[dim]: un-scaled forward [N]-derivative of order [ord] along dimension [dim] of [var]<BR>
     40      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ifreq_anom',[stepdimn],[stepvardimn],[istep]: computing anomalies by substracting sub-means at each<BR>
     41      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;step by averaging from there all values taken every [istep] along dimension [stepdim]. <BR>
     42      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep; Nstep = len(stepdimn)/istep; j=[0,istep]<BR>
     43      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[stepdimn]= name of the dimension along which to sample<BR>
     44      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[stepvardimn]= name of the variable-dimension with the values for [stepdimn]<BR>
     45      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[istep]= frequency to sample<BR>
     46      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ifreq_mean',[stepdimn],[stepvardimn],[istep]: computing sub-means at each step by averaging from <BR>
     47      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;there all values taken every [istep] along dimension [stepdim]. <BR>
     48      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep; Nstep = len(stepdimn)/istep; j=[0,istep]<BR>
     49      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[stepdimn]= name of the dimension along which to sample<BR>
     50      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[stepvardimn]= name of the variable-dimension with the values for [stepdimn]<BR>
     51      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[istep]= frequency to sample<BR>
     52      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'ifreq_normmeanstd',[stepdimn],[stepvardimn],[istep]: nbormalizing anomalies by substracting mean(j)/dtsv(j) <BR>
     53      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sub-stats at each step by averaging from there all values taken every [istep] along dimension[stepdim]. <BR>
     54      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep; std(j) = std(matA[j+k*istep]_k=0,Nstep); <BR>
     55      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nstep = len(stepdimn)/istep; j=[0,istep]<BR>
     56      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[stepdimn]= name of the dimension along which to sample<BR>
     57      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[stepvardimn]= name of the variable-dimension with the values for [stepdimn]<BR>
     58      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[istep]= frequency to sample<BR>
    4059      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'inv': inverting [prevalues] (1/[prevalues])<BR>
    4160      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'lowthres',[modval1],[modval2]: if [prevalues] < [modval1]; prevalues = [modval2]<BR>
     
    4968      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'norm_meanstd',[NOTnormdims]: normalization of data as: (val-<val>)/stdev(val) except along <BR>
    5069      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions)<BR>
    51        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;dimensions [NOTnormdims] (':' list of dimension names)<BR>
     70       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dimensions [NOTnormdims] (':' list of dimension names)<BR>
    5271      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'pot': powering with [var] ([prevalues] ** [var])<BR>
    5372      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'potc',[modval1]: [prevalues] ** [modval1]<BR>
     
    7291    <DIV CLASS="valins">
    7392    * Transforming temperature from Kelvin to &deg;C<BR>
    74     &nbsp;&nbsp;  $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|Times|3@subc,273.15|wrfout_d01_2001-11-11_00:00:00|T2' -v 'tempC,air!temperature,C'<BR>
     93    &nbsp;&nbsp;$ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|Times|3@subc,273.15|wrfout_d01_2001-11-11_00:00:00|T2' -v 'tempC,air!temperature,C'<BR>
    7594    * Computing the x-derivative of first order<BR>
    76     &nbsp;&nbsp;  $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'lon|lon|-1;lat|lat|-1;time_counter|time_counter|-1@forwrdderiv,1,1,2|histday.nc|t2m' -v 'tasderiv,x-derivative|of|air|temperature,K' <BR>
     95    &nbsp;&nbsp;$ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'lon|lon|-1;lat|lat|-1;time_counter|time_counter|-1@forwrdderiv,1,1,2|histday.nc|t2m' -v 'tasderiv,x-derivative|of|air|temperature,K' <BR>
    7796    * Normalizing a variable by substracting its mean and weighting by its standard-deviation<BR>
    78     &nbsp;&nbsp; $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@norm_meanstd,Time|wrfout_d01_1995-01-01_00:00:00|T2' -v 'tasnorm,normalized!2m!temperature!substracting!mean!and!weighting!by!standard!deviation,K' <BR>
     97    &nbsp;&nbsp;$ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@norm_meanstd,Time|wrfout_d01_1995-01-01_00:00:00|T2' -v 'tasnorm,normalized!2m!temperature!substracting!mean!and!weighting!by!standard!deviation,K' <BR>
    7998    * Getting height of the frist level from surface from a WRF file<BR>
    80     &nbsp;&nbsp; $ python $pyHOME/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;bottom_top_stag|ZNW|1@addc,0|wrfout_d01_1995-01-01_00:00:00|PH%west_east|XLONG|-1;south_north|XLAT|-1;bottom_top_stag|ZNW|1@add|wrfout_d01_1995-01-01_00:00:00|PHB%contoperation@divc,9.81%west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@sub|wrfout_d01_1995-01-01_00:00:00|HGT' -v 'height1lev,height!above!surface!of!first!level,m'<BR>
     99    &nbsp;&nbsp;$ python $pyHOME/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;bottom_top_stag|ZNW|1@addc,0|wrfout_d01_1995-01-01_00:00:00|PH%west_east|XLONG|-1;south_north|XLAT|-1;bottom_top_stag|ZNW|1@add|wrfout_d01_1995-01-01_00:00:00|PHB%contoperation@divc,9.81%west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@sub|wrfout_d01_1995-01-01_00:00:00|HGT' -v 'height1lev,height!above!surface!of!first!level,m'<BR>
    81100    * Computing wind-direction from a WRF file<BR>
    82     &nbsp;&nbsp; $ python $pyHOME/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@addc,0|wrfout_d01_1995-01-01_00:00:00|V10%west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@arctan|wrfout_d01_1995-01-01_00:00:00|U10%contoperation@mulc,57.2957795131' -v 'wsdir,2m!wind!direction,Degrees'
     101    &nbsp;&nbsp;$ python $pyHOME/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@addc,0|wrfout_d01_1995-01-01_00:00:00|V10%west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@arctan|wrfout_d01_1995-01-01_00:00:00|U10%contoperation@mulc,57.2957795131' -v 'wsdir,2m!wind!direction,Degrees'
     102    * Computing normalized anomalyes of WRF outputs by the mean and standard deviations of the outputs at the same hour<BR>
     103    &nbsp;&nbsp;$ python nc_var.py -o compute_opersvarsfiles -S 'Time|WRFtime|-1;south_north|XLAT|-1;west_east|XLONG|-1@ifreq_normmeanstd,Time,WRFtime,8|/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00|T2' -v 'tas_ifreqnormmeanstd,tas!anomaly!by!substracting!frequency!mean!at!every!8!time-steps,K'
     104
    83105    </DIV>
    84106  </BODY>
  • trunk/tools/generic_tools.py

    r1558 r1561  
    1020610206        'divc',[modval1]: divide by [modval1]
    1020710207        'forwrdderiv',[N],[ord],[dim]: un-scaled forward [N]-derivative of order [ord] along dimension [dim] of matA
     10208        'ifreq_anom',[dimns],[istep],[stepdimn]: computing anomalues by substracting sub-means at each step by
     10209             averaging from there all values taken every [istep] along dimension [stepdim].
     10210             mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep; Nstep = len(stepdimn)/istep; j=[0,istep]
     10211          [dimns]= ':' list of dimensions of the matrice
     10212          [istep]= frequency to sample
     10213          [stepdimn]= name of the dimension along which to sample
     10214        'ifreq_mean',[dimns],[istep],[stepdimn]: computing sub-means at each step by averaging from there
     10215           all values taken every [istep] along dimension [stepdim]. mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep;
     10216           Nstep = len(stepdimn)/istep; j=[0,istep]
     10217          [dimns]= ':' list of dimensions of the matrice
     10218          [istep]= frequency to sample
     10219          [stepdimn]= name of the dimension along which to sample
    1020810220        'inv': inverting matA (1/matA)
    1020910221        'lowthres',[modval1],[modval2]: if [val] < [modval1]; val = [modval2]
     
    1035010362    # Dictionary with the description of the operations
    1035110363    Lopn = {'add': '+', 'addc': '+', 'arctan': 'arctangent', 'div': '/', 'divc': '/',\
    10352       'inv': '^(-1)', 'lowthres': '<', 'mul': '*', 'mulc': '*',                      \
    10353       'norm_meanminmax': 'Norm_mean_minmax',                                         \
     10364      'ifreq_mean': 'ifreq_mean', 'ifreq_mean': 'ifreq_mean', 'inv': '^(-1)',        \
     10365      'lowthres': '<', 'mul': '*',                                                   \
     10366      'mulc': '*', 'norm_meanminmax': 'Norm_mean_minmax',                            \
    1035410367      'norm_minmax': 'Norm_minmax', 'norm_meanstd': 'Norm_mean_devstd', 'pot': '^',  \
    1035510368      'potc': '^', 'repl': 'repl_excpt', 'replbig': 'repl_excpt_bigger',             \
     
    1036210375    # Available operations
    1036310376    opavail = ['add', 'addc', 'arctan', 'centerderiv', 'div', 'divc', 'forwrdderiv', \
    10364       'inv',    \
     10377      'ifreq_anom', 'ifreq_mean', 'inv',                                             \
    1036510378      'lowthres', 'lowthres@oper', 'mul', 'mulc', 'norm_meanminmax', 'norm_minmax',  \
    1036610379      'norm_meanstd', 'pot', 'potc', 'repl', 'replbig', 'repless', 'sub', 'subc',    \
     
    1043110444            quit(-1)
    1043210445        derivcoeff = forwrdderiv[Nderiv-1,order-1,:]
     10446    elif opN[0:10] == 'ifreq_anom':
     10447        opn = 'ifreq_anom'
     10448        dimns = opN.split(',')[1].split(':')
     10449        istep = int(opN.split(',')[2])
     10450        stepdimn = opN.split(',')[3]
     10451        Lopn['ifreq_anom'] = 'anomaly by substracting ifreq_mean = sum(mat[j+k*' +   \
     10452          str(istep)+']_k=0,Nstep)/Nstep; ' + 'Nstep=len(' + stepdimn + ')/' +       \
     10453          str(istep) + '; j=[0,' + str(istep) + ']'
     10454    elif opN[0:10] == 'ifreq_mean':
     10455        opn = 'ifreq_mean'
     10456        dimns = opN.split(',')[1].split(':')
     10457        istep = int(opN.split(',')[2])
     10458        stepdimn = opN.split(',')[3]
     10459        Lopn['ifreq_mean'] = 'sum(mat[j+k*' +str(istep)+']_k=0,Nstep)/Nstep; ' +     \
     10460          'Nstep=len(' + stepdimn + ')/' + str(istep) + '; j=[0,' + str(istep) + ']'
     10461    elif opN[0:17] == 'ifreq_normmeanstd':
     10462        opn = 'ifreq_normmeanstd'
     10463        dimns = opN.split(',')[1].split(':')
     10464        istep = int(opN.split(',')[2])
     10465        stepdimn = opN.split(',')[3]
     10466        Lopn['ifreq_normmeanstd'] = 'normalization by substracting ' +               \
     10467          'ifreq_mean/ifreq_stdv ifreq_mean= sum(mat[j+k*' + str(istep) +            \
     10468          ']_k=0,Nstep)/Nstep; ifreq_stdv=stdv(mat[j+k*' + str(istep)+']_k=0,Nstep)'+\
     10469          'Nstep=len(' + stepdimn + ')/' + str(istep) + '; j=[0,' + str(istep) + ']'
     10470    elif opN[0:4] == 'inv':
     10471        opn = 'inv'
     10472        Lopn['inv'] = 'inverse'
    1043310473    elif opN[0:8] == 'lowthres' and opN.find('@') == -1:
    1043410474        opn = 'lowthres'
     
    1066210702              matA[tuple(mat5)]*derivcoeff[5] + matA[tuple(mat6)]*derivcoeff[6] +    \
    1066310703              matA[tuple(mat7)]*derivcoeff[7] + matA[tuple(mat8)]*derivcoeff[8]
     10704    elif opn == 'ifreq_anom':
     10705        istepdim = dimns.index(stepdimn)
     10706        lenstepdim = matA.shape[istepdim]
     10707        Nsteps = lenstepdim/istep
     10708
     10709        meannewmatsize = list(matA.shape)
     10710        meannewmatsize[istepdim] = istep
     10711        meannewmat = np.zeros(tuple(meannewmatsize), dtype=valtype)
     10712        matAshape = matA.shape
     10713        NmatAdims = len(matAshape)
     10714
     10715        newmat = np.zeros(tuple(matAshape), dtype=valtype)
     10716        for j in range(istep):
     10717            slicemat = []
     10718            slicenewmat = []
     10719            meandims = []
     10720            for idim in range(NmatAdims):
     10721                if idim == istepdim:
     10722                    slicemat.append(slice(j,j+Nsteps*istep,istep))
     10723                    slicenewmat.append(j)
     10724                    meandims.append(idim)
     10725                else:
     10726                    slicemat.append(slice(0,matAshape[idim]))
     10727                    slicenewmat.append(slice(0,matAshape[idim]))
     10728            mdims=tuple(meandims)
     10729            meannewmat[tuple(slicenewmat)]= np.mean(matA[tuple(slicemat)], axis=mdims)
     10730
     10731            # Computing anomaly
     10732            for it in range(Nsteps):
     10733                slicemat = []
     10734                for idim in range(NmatAdims):
     10735                    if idim == istepdim:
     10736                        slicemat.append(j+it*istep)
     10737                    else:
     10738                        slicemat.append(slice(0,matAshape[idim]))
     10739                newmat[tuple(slicemat)] = matA[tuple(slicemat)] -                    \
     10740                  meannewmat[tuple(slicenewmat)]
     10741        additional = [meannewmat]
     10742
     10743    elif opn == 'ifreq_mean':
     10744        istepdim = dimns.index(stepdimn)
     10745        lenstepdim = matA.shape[istepdim]
     10746        Nsteps = lenstepdim/istep
     10747
     10748        newmatsize = list(matA.shape)
     10749        newmatsize[istepdim] = istep
     10750        newmat = np.zeros(tuple(newmatsize), dtype=valtype)
     10751        matAshape = matA.shape
     10752        NmatAdims = len(matAshape)
     10753
     10754        for j in range(istep):
     10755            slicemat = []
     10756            slicenewmat = []
     10757            meandims = []
     10758            for idim in range(NmatAdims):
     10759                if idim == istepdim:
     10760                    slicemat.append(slice(j,j+Nsteps*istep,istep))
     10761                    slicenewmat.append(j)
     10762                    meandims.append(idim)
     10763                else:
     10764                    slicemat.append(slice(0,matAshape[idim]))
     10765                    slicenewmat.append(slice(0,matAshape[idim]))
     10766            mdims=tuple(meandims)
     10767            newmat[tuple(slicenewmat)] = np.mean(matA[tuple(slicemat)], axis=mdims)
     10768    elif opn == 'ifreq_normmeanstd':
     10769        istepdim = dimns.index(stepdimn)
     10770        lenstepdim = matA.shape[istepdim]
     10771        Nsteps = lenstepdim/istep
     10772
     10773        meannewmatsize = list(matA.shape)
     10774        meannewmatsize[istepdim] = istep
     10775        meannewmat = np.zeros(tuple(meannewmatsize), dtype=valtype)
     10776        stdnewmat = np.zeros(tuple(meannewmatsize), dtype=valtype)
     10777        matAshape = matA.shape
     10778        NmatAdims = len(matAshape)
     10779
     10780        newmat = np.zeros(tuple(matAshape), dtype=valtype)
     10781        for j in range(istep):
     10782            slicemat = []
     10783            slicenewmat = []
     10784            meandims = []
     10785            for idim in range(NmatAdims):
     10786                if idim == istepdim:
     10787                    slicemat.append(slice(j,j+Nsteps*istep,istep))
     10788                    slicenewmat.append(j)
     10789                    meandims.append(idim)
     10790                else:
     10791                    slicemat.append(slice(0,matAshape[idim]))
     10792                    slicenewmat.append(slice(0,matAshape[idim]))
     10793            mdims=tuple(meandims)
     10794            meannewmat[tuple(slicenewmat)]= np.mean(matA[tuple(slicemat)], axis=mdims)
     10795            stdnewmat[tuple(slicenewmat)]= np.std(matA[tuple(slicemat)], axis=mdims)
     10796
     10797            # Computing anomaly
     10798            for it in range(Nsteps):
     10799                slicemat = []
     10800                for idim in range(NmatAdims):
     10801                    if idim == istepdim:
     10802                        slicemat.append(j+it*istep)
     10803                    else:
     10804                        slicemat.append(slice(0,matAshape[idim]))
     10805                newmat[tuple(slicemat)] = (matA[tuple(slicemat)] -                   \
     10806                  meannewmat[tuple(slicenewmat)])/stdnewmat[tuple(slicenewmat)]
     10807        additional = [meannewmat, stdnewmat]
     10808
    1066410809    elif opn == 'inv':
    1066510810        newmat = retype(1., valtype) / matA
  • trunk/tools/nc_var_tools.py

    r1551 r1561  
    813813    Nnewdims = len(newdims)
    814814   
    815     if Nnewdims == 0:
     815    if Nnewdims == 0 or len(newvar.shape) == 0:
    816816        print '%2s %f' % ( 'NC',newvar )
    817817    elif Nnewdims == 1:
     
    72067206             'divc',[modval1]: [prevalues] divide by [modval1]
    72077207             'forwrdderiv',[N],[ord],[dim]: un-scaled forward [N]-derivative of order [ord] along dimension [dim] of [var]
     7208             'ifreq_anom',[stepdimn],[stepvardimn],[istep]: computing anomalies by substracting sub-means at each
     7209                 step by averaging from there all values taken every [istep] along dimension [stepdim].
     7210                 mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep; Nstep = len(stepdimn)/istep; j=[0,istep]
     7211               [stepdimn]= name of the dimension along which to sample
     7212               [stepvardimn]= name of the variable-dimension with the values for [stepdimn]
     7213               [istep]= frequency to sample
     7214             'ifreq_mean',[stepdimn],[stepvardimn],[istep]: computing sub-means at each step by averaging from
     7215                 there all values taken every [istep] along dimension [stepdim].
     7216                 mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep; Nstep = len(stepdimn)/istep; j=[0,istep]
     7217               [stepdimn]= name of the dimension along which to sample
     7218               [stepvardimn]= name of the variable-dimension with the values for [stepdimn]
     7219               [istep]= frequency to sample
     7220             'ifreq_normmeanstd',[stepdimn],[stepvardimn],[istep]: nbormalizing anomalies by substracting mean(j)/dtsv(j)
     7221                 sub-stats at each step by averaging from there all values taken every [istep] along dimension[stepdim].
     7222                 mean(j) = sum(matA[j+k*istep]_k=0,Nstep)/Nstep; std(j) = std(matA[j+k*istep]_k=0,Nstep);
     7223                 Nstep = len(stepdimn)/istep; j=[0,istep]
     7224               [stepdimn]= name of the dimension along which to sample
     7225               [stepvardimn]= name of the variable-dimension with the values for [stepdimn]
     7226               [istep]= frequency to sample
    72087227             'inv': inverting [prevalues] (1/[prevalues])
    72097228             'lowthres',[modval1],[modval2]: if [prevalues] < [modval1]; prevalues = [modval2]
     
    72507269    opinione = ['mul', 'div', 'pot']
    72517270    # Operations which need to deal with dimension's names and indices
    7252     opdim=['norm_meanminmax', 'norm_meanstd', 'norm_minmax']
     7271    opdim = ['ifreq_anom', 'ifreq_mean', 'ifreq_normmeanstd', 'norm_meanminmax',     \
     7272      'norm_meanstd', 'norm_minmax']
     7273    # Operations which require a new dimension
     7274    opnewdim = ['ifreq_mean']
     7275    # istep Operations
     7276    opistep = ['ifreq_anom', 'ifreq_mean', 'ifreq_normmeanstd']
    72537277
    72547278    varname = varinfo.split(',')[0]
     
    73107334    Dadditionalunits = {}
    73117335    # Dictionary with the Headers for the names of the additional variables
    7312     DHadditionalvars = {'norm_meanminmax': ['mean','min','max'],                     \
     7336    DHadditionalvars = {'ifreq_anom': ['ifreq_mean'], 'ifreq_normmeanstd':           \
     7337      ['ifreq_mean', 'ifreq_std'], 'norm_meanminmax': ['mean','min','max'],          \
    73137338      'norm_meanstd': ['mean','std'], 'norm_minmax': ['min','max']}
    73147339
    73157340    prevalues = None
     7341    slicewrft = None
     7342
    73167343    for ifv in range(Nfileopers):
    73177344        operN = opers[ifv]
     
    74297456                    Ddv[dimn] = cftimes
    74307457                    Dtdv[dimn] = np.float
    7431                     Dadv[dimn] = {'stadard_name': 'time', 'long_name': 'time',       \
     7458                    Dadv[dimn] = {'standard_name': 'time', 'long_name': 'time',      \
    74327459                      'units': tunitsval + ' since ' + refdateS}
    74337460
     
    74847511                usedims = 'any'
    74857512            for iv in range(len(normi)): normi[iv] = str(normi[iv])
    7486             opern = opernS + ',' + ':'.join(dimvarvals) + ',' +                  \
     7513            opern = opernS + ',' + ':'.join(dimvarvals) + ',' +                      \
    74877514              operN.split(',')[1] + ',' + ':'.join(normi)
     7515
     7516            if gen.searchInlist(opistep, opernS):
     7517                opern = opernS + ',' + ':'.join(dimvarvals) + ',' +                  \
     7518                  operN.split(',')[3] + ',' + operN.split(',')[1]
     7519                usedims = list(dimvarvals)
     7520
     7521            if gen.searchInlist(opnewdim, opernS):
     7522                # Creation of a new dimension for the operation
     7523                dimv = list(dimvarvals)
     7524                idim = dimv.index(operN.split(',')[1])
     7525                newdimn = opernS + dimv[idim]
     7526                print infmsg
     7527                print '    ' + fname + ": operation '" + opernS + "' will create " + \
     7528                  " a new dimension '" + newdimn + "' !!"
     7529                dimv[idim] = newdimn
     7530                dimvarvals = tuple(dimv)
     7531                vardimnstep = operN.split(',')[2]
     7532                istep = int(operN.split(',')[3])
     7533                if vardimnstep != 'WRFtime':
     7534                    if not objnc.variables.has_key[vardimnstep]:
     7535                        print errormsg
     7536                        print '  ' + fname + ": file '" + filen + "' does not " +    \
     7537                          "have variable '" + vardimnstep + "' to be used for '" +   \
     7538                          "ifreq_mean' !!"
     7539                        print '    available ones:', objnc.variables.keys()
     7540                        quit(-1)
     7541                    odimv = objnc.variables[vardimnstep]
     7542                    varslice, Dddv[newdimn] = SliceVarDict(odimv, dictslice)
     7543                    allvalues = odimv[tuple(varslice)]
     7544                    Dtdv[newdimn] = odimv.dtype
     7545                    dicattrs = {}
     7546                    for attrn in odimv.ncattrs():
     7547                        attrval = odimv.getncattr(attrn)
     7548                        dicattrs[attrn] = attrval
     7549                    Dadv[newdimn] = dicattrs
     7550                else:
     7551                    if slicewrft is None:
     7552                        print infmsg
     7553                        print '  '+fname+ ": computing time-variable from 'WRF'-Time"
     7554                        datesv = []
     7555                        wrft = objnc.variables['Times']
     7556                        slicewrft, dwrfd = SliceVarDict(wrft, dictslice)
     7557                        fdates = wrft[tuple(slicewrft)]
     7558                        refdate = '19491201000000'
     7559                        tunitsval = 'minutes'
     7560                        yrref=refdate[0:4]
     7561                        monref=refdate[4:6]
     7562                        dayref=refdate[6:8]
     7563                        horref=refdate[8:10]
     7564                        minref=refdate[10:12]
     7565                        secref=refdate[12:14]
     7566       
     7567                        refdateS= yrref +'-'+ monref + '-' + dayref + ' ' + horref + \
     7568                          ':' + minref + ':' + secref
     7569       
     7570                        dt = fdates.shape[0]
     7571                        allvalues = np.zeros((dt), dtype=np.float)
     7572                        for it in range(dt):
     7573                            wrfdates = gen.datetimeStr_conversion(wrft[it,:],        \
     7574                             'WRFdatetime', 'matYmdHMS')
     7575                            allvalues[it] = gen.realdatetime1_CFcompilant(wrfdates,  \
     7576                              refdate, tunitsval)
     7577                        tunits = tunitsval + ' since ' + refdateS
     7578                    else:
     7579                        # Using previous computed WRFtime
     7580                        allvalues = cftimes
     7581
     7582                    Dtdv[newdimn] = np.float
     7583                    Dadv[newdimn] = {'standard_name': 'time', 'long_name': 'time',   \
     7584                      'units': tunitsval + ' since ' + refdateS, 'calendar':         \
     7585                      'standard'}
     7586
     7587                # Filling-up new dimension characteristics
     7588                Dds[newdimn] = istep
     7589
     7590                Dddv[newdimn] = [newdimn]
     7591                newdimvals = np.zeros((istep), dtype=Dtdv[newdimn])
     7592                dsize = allvalues.shape[0]
     7593                Nsteps = dsize/istep
     7594                for it in range(istep):
     7595                    newdimvals[it] = np.mean(allvalues[slice(it,istep*Nsteps,istep)])
     7596                Ddv[newdimn] = newdimvals[:]
     7597
    74887598            Dadditionaldim[opernS+'@'+varn] = usedims
     7599
    74897600            if varn != 'continuation':
    74907601                Dadditionalunits[opernS+'@'+varn] = get_varunits(varobj)
     
    75937704                    newvn = Hvarn + '_' + operS + '_' + vnS
    75947705                    newvar = objofile.createVariable(newvn, 'f4', tuple(newvdims))
     7706                    print fname + ': LLuis shapes:', newvar.shape, 'newvdims:', newvdims, 'addvs:', addvs[iHv].shape
    75957707                    newvar[:] = addvs[iHv]
    75967708                    Lattr = Hvarn + ' value for operation ' + operS + ' with variable ' + vnS
Note: See TracChangeset for help on using the changeset viewer.