Changeset 429 in lmdz_wrf for trunk


Ignore:
Timestamp:
May 26, 2015, 1:03:19 PM (10 years ago)
Author:
lfita
Message:

Creation of function 'lonlat2D' to provide 2D lon,lat matrices

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r421 r429  
    1084710847    return dist
    1084810848
     10849def lonlat2D(lon,lat):
     10850    """ Function to return lon, lat 2D matrices from any lon,lat matrix
     10851      lon= matrix with longitude values
     10852      lat= matrix with latitude values
     10853    """
     10854    fname = 'lonlat2D'
     10855
     10856    if len(lon.shape) != len(lat.shape):
     10857        print errormsg
     10858        print '  ' + fname + ': longitude values with shape:', lon.shape,            \
     10859          'is different that latitude values with shape:', lat.shape, '(dif. size) !!'
     10860        quit(-1)
     10861
     10862    if len(lon.shape) == 3:
     10863        lonvv = lon[0,:,:]
     10864        latvv = lat[0,:,:]
     10865    elif len(lon.shape) == 2:
     10866        lonvv = lon[:]
     10867        latvv = lat[:]
     10868    elif len(lon.shape) == 1:
     10869        lonlatv = np.meshgrid(lon[:],lat[:])
     10870        lonvv = lonlatv[0]
     10871        latvv = lonlatv[1]
     10872
     10873    return lonvv, latvv
     10874
    1084910875def compute_tevolboxtraj(values, ncfile, varn):
    1085010876    """ Function to compute tevolboxtraj: temporal evolution at a given point along
     
    1087810904    check_arguments(fname,len(arguments.split(',')),arguments,',',8)
    1087910905
    10880 
    1088110906    trajfile = values.split(',')[0].split('@')[0]
    1088210907    Tbeg = int(values.split(',')[0].split('@')[1])
     
    1093110956            varns = [varn]
    1093210957
    10933     if len(lonobj.shape) == 3:
    10934         lonv = lonobj[0,:,:]
    10935         latv = latobj[0,:,:]
    10936     elif len(lonobj.shape) == 2:
    10937         lonv = lonobj[:]
    10938         latv = latobj[:]
     10958    lonv, latv = lonlat2D(lonobj[:],latobj[:])
    1093910959
    1094010960    dimx = lonv.shape[1]
     
    1094210962
    1094310963    timv = timobj[:]
    10944 
    1094510964
    1094610965# Selecting accordingly a trajectory
     
    1113311152    newdim = objofile.createDimension('time', None)
    1113411153
    11135     statnames = ['minbox', 'maxbox', 'meanbox', 'mean2box', 'stdevbox']
     11154    stsn = ['min', 'max', 'mean', 'mean2', 'stdev', 'ac']
    1113611155    vstlname = ['minimum value within', 'maximum value within', 'mean value within', \
    11137       'squared mean value within', 'standard deviation value within']
    11138     cstatnames = ['mincircle','maxcircle','meancircle','mean2circle','stdevcircle']
     11156      'squared mean value within', 'standard deviation value within',                \
     11157      'accumulated value within']
     11158    Nsts = len(stsn)
     11159    statnames = []
     11160    cstatnames = []
     11161    for i in range(Nsts):
     11162        statnames.append(stsn[i] + 'box')
     11163        cstatnames.append(stsn[i] + 'circle')
    1113911164
    1114011165# Getting values
     
    1120011225            rlatvals = np.ones(tuple([Ttraj,dimz,Nrad*2+1,Nrad*2+1]), dtype=np.float)
    1120111226
    11202             statvarvals = np.ones(tuple([Ttraj,dimz,6]), dtype=np.float)
    11203             rstatvarvals = np.ones(tuple([Ttraj,dimz,6]), dtype=np.float)
     11227            statvarvals = np.ones(tuple([Ttraj,dimz,Nsts]), dtype=np.float)
     11228            rstatvarvals = np.ones(tuple([Ttraj,dimz,Nsts]), dtype=np.float)
    1120411229
    1120511230            for it in range(Ttraj):
     
    1124811273                        statvarvals[it,iz,5] = np.sqrt(statvarvals[it,iz,4] -        \
    1124911274                          statvarvals[it,iz,3]*statvarvals[it,iz,3])
     11275                        statvarvals[it,iz,6] = np.sum(varvalst[iz,:,:])
     11276
    1125011277                else:
    1125111278                    slicev.append(slice(0,dimz))
     
    1128011307                        statvarvals[it,iz,5] = np.sqrt(statvarvals[it,iz,4] -        \
    1128111308                          statvarvals[it,iz,3]*statvarvals[it,iz,3])
     11309                        statvarvals[it,iz,6] = np.sum(varvalst[iz,:,:])
    1128211310
    1128311311# Circle values
     
    1132411352                        rstatvarvals[it,iz,5] = np.sqrt(rstatvarvals[it,iz,4] -      \
    1132511353                          rstatvarvals[it,iz,3]*rstatvarvals[it,iz,3])
     11354                        rstatvarvals[it,iz,6] = np.sum(varvalst[iz,:,:])
    1132611355
    1132711356                else:
     
    1136411393                        rstatvarvals[it,iz,5] = np.sqrt(rstatvarvals[it,iz,4] -      \
    1136511394                          rstatvarvals[it,iz,3]*rstatvarvals[it,iz,3])
     11395                        rstatvarvals[it,iz,6] = maskedvals[iz,:,:].sum()
    1136611396
    1136711397#            print 'statistics:',rstatvarvals[it,:]
     
    1144711477            rlatvals = np.ones(tuple([Ttraj,Nrad*2+1,Nrad*2+1]), dtype=np.float)
    1144811478
    11449             statvarvals = np.ones(tuple([Ttraj,6]), dtype=np.float)
    11450             rstatvarvals = np.ones(tuple([Ttraj,6]), dtype=np.float)
     11479            statvarvals = np.ones(tuple([Ttraj,Nsts]), dtype=np.float)
     11480            rstatvarvals = np.ones(tuple([Ttraj,Nsts]), dtype=np.float)
    1145111481
    1145211482            for it in range(Ttraj):
     
    1148911519                    statvarvals[it,5] = np.sqrt(statvarvals[it,4] -                   \
    1149011520                      statvarvals[it,3]*statvarvals[it,3])
     11521                    statvarvals[it,6] = maskedvals.sum()
    1149111522
    1149211523                    varvalst[tuple(slice2D)] = lonv[tuple(slicevnoT)]
     
    1152311554                    statvarvals[it,5] = np.sqrt(statvarvals[it,4] -                  \
    1152411555                      statvarvals[it,3]*statvarvals[it,3])
     11556                    statvarvals[it,6] = np.sum(varvalst)
    1152511557
    1152611558                    varvalst = lonv[tuple(slicevnoT)]
     
    1156111593                    rstatvarvals[it,5] = np.sqrt(rstatvarvals[it,4] -                \
    1156211594                      rstatvarvals[it,3]*rstatvarvals[it,3])
     11595                    rstatvarvals[it,6] = maskedvals2.sum()
    1156311596
    1156411597                else:
     
    1159311626                    rstatvarvals[it,5] = np.sqrt(rstatvarvals[it,4] -                \
    1159411627                      rstatvarvals[it,3]*rstatvarvals[it,3])
     11628                    rstatvarvals[it,6] = maskedvals.sum()
    1159511629
    1159611630#            print 'statistics:',rstatvarvals[it,:]
Note: See TracChangeset for help on using the changeset viewer.