Changeset 2234 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Nov 16, 2018, 8:01:24 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `join_NOstrlist': Function to join a non-string list of values
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2230 r2234  
    129129# int_to_roman: Convert an integer to Roman numerals
    130130# IsNumber: Function to determine if a given String is a given type of number
     131# join_NOstrlist: Function to join a non-string list of values
    131132# julday_360d: Function to provide the julian day of a date in a 360 days/yr (or 12 30-days months) calendar
    132133# latex_fig_array: Function to add an array of figures to an existing tex file
     
    1497014971    return slices, Nslices
    1497114972
     14973def percentiles_idims(values, axis, Npercen=20):
     14974    """ Function to compute percentiles of a given variable along different runing
     14975        dimensions
     14976      values = array of values
     14977      axis= list of axis indices to use to compute the percentiles
     14978      Npercen= number of pecentiles (default 20)
     14979    """
     14980    fname = 'percentiles_idims'
     14981
     14982    for iaxis in axis:
     14983        if iaxis >= len(values.shape):
     14984            print errormsg
     14985            print '  ' + fname + ': wrong axis value !!'
     14986            print '    variable is of rank:', len(values.shape), ' and you provided',\
     14987              'axis:', iaxis
     14988            quit(-1)
     14989
     14990    for j in range(dimy):
     14991        for i in range(dimx):
     14992            percents[:,j,i] = Quantiles(vals[:,j,i],20).quantilesv
     14993
     14994    return percentiles
     14995
     14996def join_NOstrlist(listv, char):
     14997    """ Function to join a non-string list of values
     14998    >>> join_NOstrlist(range(10), ',')
     14999    0,1,2,3,4,5,6,7,8,9
     15000    """
     15001    fname = 'join_NOstrlist'
     15002
     15003    strlist = ''
     15004    for lv in listv:
     15005        if lv == listv[0]: strlist = str(lv)
     15006        else: strlist = strlist + char + str(lv)
     15007
     15008    return strlist
     15009
    1497215010#quit()
    1497315011
Note: See TracChangeset for help on using the changeset viewer.