Changeset 1993 in lmdz_wrf for trunk/tools/generic_tools.py


Ignore:
Timestamp:
Jul 31, 2018, 8:22:11 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `auto_val_list': Function to provide a list of values following an 'auto' configuration or a single value
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1992 r1993  
    5858# ASCII_WIKItab: Function to pass a line to WIKI table format
    5959# auto_val: Function to provide a value following an 'auto' configuration
     60# auto_val_list: Function to provide a list of values following an 'auto' configuration or a single value
    6061# Capturing: Class to capture the standard output from a function
    6162# CF_gribequiv: Function to provide the GRIB variable code number from a CF name
     
    1198111982    return autoval
    1198211983
     11984def auto_val_list(listchk, Nvals, alist):
     11985    """ Function to provide a list of values following an 'auto' configuration or a single value
     11986      listchk= list to take (if != 'auto'), value is transformed to the type(aval[0])
     11987        *NOTE: if it is a single value, output will be Nvals copies of the single value
     11988      Nvals= number of values to provide.
     11989      alist= list to take when it is configured as 'auto'
     11990      >>> auto_val('auto', 3, drawing_tools.colorsauto)
     11991      ['#FF0000', '#00FF00', '#0000FF']
     11992      >>> auto_val('#00FFAA', 3, drawing_tools.colorsauto)
     11993      ['#00FFAA', '#00FFAA', '#00FFAA']
     11994      >>> auto_val_list(['2.3','2','3.4'], 3, np.arange(3.))
     11995      [2.2999999999999998, 2.0, 3.3999999999999999]
     11996    """
     11997    fname = 'auto_val_list'
     11998
     11999    if type(listchk) == type('S'):
     12000        if listchk == 'auto':
     12001            autoval = alist[0:Nvals]
     12002        else:
     12003            autoval = []
     12004            for i in range(Nvals): autoval.append(retype(listchk, type(alist[0])))
     12005    else:
     12006        autoval = []
     12007        for i in range(Nvals): autoval.append(retype(listchk[i], type(alist[0])))
     12008
     12009    return autoval
     12010
     12011#colorsauto = ['#FF0000', '#00FF00', '#0000FF', '#FF00FF', '#00FFFF', '#FFAA00',      \
     12012#  '#AA0000', '#00AA00', '#0000AA', '#AA00AA', '#00AAAA', '#AA3200', '#AA0032',       \
     12013#  '#32AA00', '#3200AA', '#00AA32', '#0032AA', '#32FF00', '#3200FF', '#0032FF',       \
     12014#  '#FF3200', '#FF0032', '#00FF32', '#323200', '#320032', '#003232']
     12015#print auto_val_list('auto', 3, colorsauto)
     12016#print auto_val_list('#00FFAA', 3, colorsauto)
     12017#print auto_val_list(['2.3','2','3.4'], 3, np.arange(3.))
     12018
     12019quit()
     12020
     12021
     12022
     12023
    1198312024def rectangular_spiral(Ntimes, dunits):
    1198412025    """ Function to provide a rectangular spiral (along x,y-axis values) of values
Note: See TracChangeset for help on using the changeset viewer.