[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[IDV #TCM-505181]: Longtime Average fuction of Gridded Data with apache.org math fuctions



Hi Benjamin-

Sorry for the delay in responding.  I took some time off over
the holidays.

> Full Name: Benjamin Chaos
> Email Address: address@hidden
> Organization: ITC
> Package Version: 2.4b3 build date:2007-12-19 08:05 UTC
> Operating System: Windows XP
> Hardware: Java: home: C:\Program Files\Java\jre1.6.0_03 version: 1.6.0_03 
> j3d:1.3.2 fcs (build12)
> Description of problem:
> 
> Hello Don / Jeff
> 
> Sorry to bother you again. I'm still working with the same OSCAR
> dataset. My last problem was solved with your help by the "color by
> another parameter" option.  I'm now trying to get the same vector flow
> display color by another parameter but this time I want to display  the
> long mean average of the data.  I was doing something similar with
> satellite images using the following function:
> 
> ##########################################################################################################################################################
> # compute average of timesequence imagery (call this jython function only for 
> image sequences)
> ##########################################################################################################################################################
> # Purpose: compute average (per pixel) of timesequence imagery
> # Creator: V. Venus
> #
> 
> 
> def averageImagesSeq (timeSequence,singleBand):
> import sys;
> sys.add_package('visad.meteorology');
> sys.add_package('GridUtil');
> sys.add_package('org.apache.commons.math.stat.descriptive.moment');
> from org.apache.commons.math.stat.descriptive.moment import Mean
> 
> from java.util import TimeZone
> from jarray import zeros
> from java.lang import Float
> from java.lang import Double
> from visad import DateTime
> from visad.meteorology import ImageSequence
> from visad.meteorology import SingleBandedImage
> 
> print "Function getTempDiurnalImage started ..."
> 
> domain = singleBand.getDomainSet()
> cs = domain.getCoordinateSystem()
> len =  domain.getLength()
> 
> # Pass in 0 as false so we don't copy the values
> samples = domain.getSamples(0)
> # Clone the incoming objects
> news = singleBand.clone()
> 
> lineValuesA = singleBand.getFloats()
> 
> 
> 
> meanAlg = Mean()
> 
> #print "Starting for loop ... number of iterations = ", len
> # calculate temperatures for all coordinates (crd) for all times (time)
> for crd in xrange(len):
> #print "Pixel nr. ", crd + 1, " of ", len
> # get length of imageSequence
> seq = timeSequence.getDomainSet().getLength()
> # create array to store temperatures
> arr = zeros(seq, "d")
> # get all temperatures for one coordinate for all times time and put them 
> into arr
> #print "Entering nested forloop 1"
> for time in xrange(seq):
> # get the values
> # Pass in 0 as false so we don't copy the values
> #print "    Retrieving pixel info for image nr. ", time + 1, " of ", seq
> values = timeSequence.getSample(time).getFloats(0)
> #print "    Value for current pixel (#", crd + 1, "): ",values[0][crd]
> arr[time] = values[0][crd]
> #print "Exited nested forloop 1"
> # Calculate the temperatures
> #print "Starting temperature averaging"
> average = meanAlg.evaluate(arr)
> print average
> #print "Finished temperature calculation"
> # feed the temperatures back into the clone newd
> lineValuesA[0][crd] = average
> news.setSamples(lineValuesA)
> return news
> 
> ################################################################################
> ################################################################################
> 
> I want to acomplish something similar but with Grid data.
> I'm trying the following code, but I get an error while filling an
> array with the data from the grid.
> 
> ########################################
> # Ben's new Methods
> #########################################
> # Examples of Jython methods
> # Creator: B. Chaos
> import sys;
> sys.add_package('org.apache.commons.math.stat.descriptive.moment');
> from org.apache.commons.math.stat.descriptive.moment import Mean
> from jarray import zeros
> from java.lang import Float
> 
> 
> def gridAvgOverTime(field):
> 
> if (GridUtil.isTimeSequence(field)==0):
> return field;
> # create array to store all values
> arr = zeros(2, "d")
> meanAlg = Mean()
> domainSet = field.getDomainSet()
> current = None;
> for t in range(domainSet.getLength()):
> rangeValue = field.getSample(t);
> if(current == None):
> current = rangeValue.clone();
> arr[t] = current;
> average = meanAlg.evaluate(arhr)
> return average
> ##############################################
> 
> I think the error is while " arr[t] = current " since I get not only
> the values for the vectors but also the lat /long positions.

rangeValue will be the individual timestep data which is a VisAD
FlatField which has the  structure of (lon,lat) -> (u,v).  To
get the u and v arrays, you'll need to call getFloats()
which will give you a 2D array of floats (u,v).  So, you
could call:

  uv = rangeValue.getFloats()

or 

  uv = rangeValue.getValues()

if you want doubles.  That will make a copy of the data in
the original field so you don't munge it.

> 
> Can you have a look and may be tell me how to get values of a grided
> data into an array so I can later use the Math functions from
> apache.org (Mean, Median, Min, Max.) for other porpuses.

I'm not sure of how these functions work, but if that suggestion
above doesn't help, let me know.
 
> 
> I hope you can help me agaian.
> 
> Happy Holidays.

Same to you.

Don

Ticket Details
===================
Ticket ID: TCM-505181
Department: Support IDV
Priority: Normal
Status: Open