Re: [idvusers] How to use the "applyToRangeValues(function, data)" Jython method

Hi Patrick-

Patrick Koethur wrote:
I have a rather general question about the use of the "applyToRangeValues(function,data)" Jython method.

What is meant by the function argument? What should it look like? Can anyone give an example? Thanks a lot.

The function argument is the name of the function that you
want to apply to each timestep in the field.  An example
might be:

def changeRange(d):
   return   applyToRangeValues('testApplyToRange2',d);

def testApplyToRange(d,**args):
    r = d.getFloats(0)
    total = 0
    for i in xrange(len(r[0])):
        total= total+r[0][i]
    avg = total/len(r[0])
    for i in xrange(len(r[0])):
            r[0][i] = 0;
    return d

This avoids having to have the code like:

    if (GridUtil.isTimeSequence(newData)):
        for t in range(newData.getDomainSet().getLength()):
            rangeValue = newData.getSample(t)
            XXX do something
        rangeValue = newData
        XXX do something

when you might have a time sequence or just a single timestep.

Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307