Changeset 2532 in lmdz_wrf


Ignore:
Timestamp:
May 14, 2019, 4:23:00 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `provide_vals_fromsecs_inlist': Function to provide a list of values from a list as dividing its entries by a given character and combination of different sections from the charcater-driven division
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2519 r2532  
    196196# prime_numbers: Function to find all the prime numbers up to a given value above 17
    197197# printing_dictionary: Function to print the content of a dictionary
     198# provide_vals_fromsecs_inlist: Function to provide a list of values from a list as
     199#   dividing its entries by a given character and combination of different sections
     200#   from the charcater-driven division
    198201# provide_slices: Function to provide a list of slices for a matrix giving a sub-section of running dimensions
    199202# radius_angle: Function to generate a matrix with the angle at a given point
     
    1671816721    return Ntimes
    1671916722
     16723def provide_vals_fromsecs_inlist(listv,cdiv,secs):
     16724    """ Function to provide a list of values from a list as dividing its entries by
     16725        a given character and combination of different sections from the
     16726        charcater-driven division
     16727      listv: list of values
     16728      cdiv: character of division the list-entries
     16729      secs: numbers of the resultant sections to combine
     16730    >>> cmip5hf = ['tasmax_Amon_ACCESS1-0_historical_r1i1p1_185001-200512_slice_Ecuador_19600101000000-19900101000000.nc',
     16731      'tasmax_Amon_ACCESS1-3_historical_r1i1p1_185001-200512_slice_Ecuador_19600101000000-19900101000000.nc',
     16732      'tasmax_Amon_bcc-csm1-1_historical_r1i1p1_185001-201212_slice_Ecuador_19600101000000-19900101000000.nc',
     16733      'tasmax_Amon_BNU-ESM_historical_r1i1p1_185001-200512_slice_Ecuador_19600101000000-19900101000000.nc',
     16734      'tasmax_Amon_CanESM2_historical_r1i1p1_185001-200512_slice_Ecuador_19600101000000-19900101000000.nc',
     16735      'tasmax_Amon_CCSM4_historical_r1i2p1_185001-200512_slice_Ecuador_19600101000000-19900101000000.nc',
     16736      'tasmax_Amon_CNRM-CM5-2_historical_r1i1p1_190001-200512_slice_Ecuador_19600101000000-19900101000000.nc']
     16737    >>> provide_vals_fromsecs_inlist(cmip5hf, '_', [2,3,4])
     16738    ['ACCESS1-0_historical_r1i1p1', 'ACCESS1-3_historical_r1i1p1', 'bcc-csm1-1_historical_r1i1p1',
     16739     'BNU-ESM_historical_r1i1p1', 'CanESM2_historical_r1i1p1', 'CCSM4_historical_r1i2p1',
     16740     'CNRM-CM5-2_historical_r1i1p1']
     16741    """
     16742    fname = 'provide_vals_fromsecs_inlist'
     16743
     16744    values = []
     16745
     16746    xsec = np.max(np.asarray(secs))
     16747
     16748    for lvn in listv:
     16749        lsecs = lvn.split(cdiv)
     16750        if len(lsecs) < xsec+1:
     16751            print errormsg
     16752            print '  ' + fname + ": list value '" + lvn + "' does not have enough" + \
     16753              " sections when divided by '" + cdiv + "' !!"
     16754            print '    resultant number of sections:', len(lsecs), 'sections:', lsecs
     16755            print '    desired combination of sections:', secs
     16756            quit(-1)
     16757
     16758        newval = ''
     16759        for isec in secs:
     16760            if isec == secs[0]: newval = lsecs[isec]
     16761            else: newval = newval + cdiv + lsecs[isec]
     16762
     16763        values.append(newval)
     16764
     16765    return values
     16766
    1672016767#quit()
    1672116768
Note: See TracChangeset for help on using the changeset viewer.