Hi,
I would like to get suggestions how to add a user-specified 'time stamp'
to a singleBanded image or 2Dgrid returned by the jython function
included below.
I have 'hacked in' time to the object returned by the aggregate function
listed below, but ideally I would like to prompt the user instead.
'Time' is necessary so that a time animation is made possible, and for
other functions to work properly (i.e. the "Export Grid to
Excel"-function).
i.e. through a "user_mmddyyyy" so the function's formula would become
aggregateSeq(timeSequence,user_mmddyyyy) which would provide the time
for the object to be returned (news).
Any ideas?
Cheers Tyn
########################################################################
##### aggregate timesequence (call this jython function for
image/gridsequences)
########################################################################
#####
# Purpose: aggregate (per pixel) a timesequence
# Creator: V. Venus
#
def aggregateSeq(timeSequence,singleBand):
import sys;
sys.add_package('visad.meteorology');
sys.add_package('GridUtil');
# here we may choose various aggregator offered by the apache.org
"math" package
sys.add_package('org.apache.commons.math.stat.descriptive.moment');
from org.apache.commons.math.stat.descriptive.moment import Mean
#sys.add_package('org.apache.commons.math.stat.descriptive.rank');
#from org.apache.commons.math.stat.descriptive.rank import Percentile
from jarray import zeros
from java.lang import Float
from java.lang import Double
#singleBand = timeSequence.getSample(0)
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()
#newd = timeSequence.clone()
lineValuesA = singleBand.getSample(0).getFloats()
alg = Mean()
#print "Starting for loop ... number of iterations = ", len
# calculate aggregates 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 values
arr = zeros(seq, "d")
# get all values 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)
arr[time] = values[0][crd]
cnt = 0
for i in xrange(seq):
if (arr[i] > 0) and (Double(arr[i]).isNaN() == 0):
cnt = cnt + 1
validArray = zeros(cnt, "d")
index = 0
for i in xrange(seq):
if (arr[i] > 0) and (Double(arr[i]).isNaN() == 0):
validArray[index] = arr[i]
index = index + 1
aggregate = alg.evaluate(validArray)
lineValuesA[0][crd] = aggregate
print "array from timeSequence: ",arr
print "array after filtering: ",validArray
print "aggegated array: ",aggregate
alg.clear()
news.getSample(0).setSamples(lineValuesA)
return news
International Institute for Geo-Information Science and Earth Observation (ITC)
Chamber of Commerce: 410 27 560
E-mail disclaimer
The information in this e-mail, including any attachments, is intended for the
addressee only. If you are not the intended recipient, you are hereby notified
that any disclosure, copying, distribution or action in relation to the content
of this information is strictly prohibited. If you have received this e-mail by
mistake, please delete the message and any attachment and inform the sender by
return e-mail. ITC accepts no liability for any error or omission in the
message content or for damage of any kind that may arise as a result of e-mail
transmission.