Changeset 1570 in lmdz_wrf for trunk


Ignore:
Timestamp:
May 12, 2017, 5:20:10 PM (8 years ago)
Author:
lfita
Message:

Adding:

`minmax_range': Function to provide a range for a given pair of minimum and maximum

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1561 r1570  
    9595# list_differences: Function to provide the differences between two lists
    9696# list_norepeatcombos: Function to all possible (Num-1)-combinations of a Num values without repetitions
    97 # lstring_values: Function to provide a new list-string from a string which is a list of word separated by a character if some values
    98 #   are repeated they are not included
     97# lstring_values: Function to provide a new list-string from a string which is a list of word separated by a character if some values are repeated they are not included
     98# minmax_range: Function to provide a range for a given pair of minimum and maximum
    9999# multi_index_mat: Function to provide the multiple coordinates of a given value inside a matrix
    100100# multi_index_string: Function to provide the indeces of every repetition of a group of characters within a string
     
    1196511965    return slices
    1196611966
     11967def minmax_range(minv,maxv,rangekind):
     11968    """ Function to provide a range for a given pair of minimum and maximum
     11969      minv: minimum value from data
     11970      maxv: maximum value from data
     11971      rangekind: kind of range
     11972        [val1],[val2]: tacking the provided ',' separated list of desired [val1] and [val2]
     11973        'auto': automatically set up range using minv and maxv
     11974        'extremescentered': extremes automatically centered on zero by computing from data -absmax, absmax;
     11975          absmax=max(abs(minval),maxval)
     11976        'meancentered': extremes automatically centered on mean by computing from data minv+meanv, maxv-meanv;
     11977          meanv=(minval + maxval)/2.
     11978      >>> minmax_range(-3.25, 4.75, '-2.0,2.0')
     11979        [-2.0, 2.0]
     11980      >>> minmax_range(-3.25, 4.75, 'extremescentered')
     11981        [-4.75, 4.75]
     11982      >>> minmax_range(-3.25, 4.75, 'meancentered')
     11983        [-2.5, 4.0]
     11984    """
     11985    possibleranges = ['auto', 'extremescentered', 'meancentered']
     11986    if rangekind == 'None':
     11987        valmin = minv
     11988        valmax = maxv
     11989    else:
     11990        if not searchInlist(possibleranges, rangekind):
     11991            valmin = np.float(rangekind.split(',')[0])
     11992            valmax = np.float(rangekind.split(',')[1])
     11993        else:
     11994            if rangekind == 'auto':
     11995                valmin = minv
     11996                valmax = maxv
     11997            elif rangekind == 'extremescentered':
     11998                absmax = np.max([np.abs(minv), maxv])
     11999                valmin = -absmax*1.
     12000                valmax = absmax
     12001            elif rangekind == 'meancentered':
     12002                meanv = (minv + maxv)/2.
     12003                valmin = minv+meanv
     12004                valmax = maxv-meanv
     12005            else:
     12006                print errormsg
     12007                print '  ' +fname+ ": type of range '" + rangekind + "' not ready !!"
     12008                print '    available ones:', possibleranges
     12009                quit(-1)           
     12010
     12011    return [valmin, valmax]
     12012
    1196712013#quit()
Note: See TracChangeset for help on using the changeset viewer.