imgSeq=[] <<getting images by stepping through time>> metaSingChan,img=getADDEImage(...) imgSeq.append(img) <<all time steps done>> imgAverage=averageOverTime(imgSeq)
I might add that imgSeq displays well in 'Image Sequence Display'
Unfortunately we haven't fully worked out the interoperability of formulas like "averageOverTime" and the way we are doing things in the scripting API (appending to Python lists). For the time being, I suspect something like this might do the trick:
# (at top of script): from visad.meteorology import ImageSequenceImpl
# ( ... your script ... )
# running imgSeq through the ImageSequenceImpl "constructor" should # turn it into something that averageOverTime can work with: imgAverage = averageOverTime( ImageSequenceImpl(imgSeq) )
To follow on to what Mike said: Most, if not all, the library functions deal with data objects that are obtained using other library routines -- and these are usually of the type visad.FieldImpl or visad.FlatField (or extensions thereof).
When you create a Python list ("array") of objects and want to work with them, you might need to roll-your-own. In this case, perhaps something like:
...your code... imgAvg = imgSeq[0].clone; for i in xrange(1,len(imgSeq)): imgAvg = imgAvg + imgSeq[i]; imgAvg = imgAvg / len(imgSeq);
But as Mike pointed out, for a time sequence of images, there is a "helper" method to take the "list" and create a suitable FieldImpl object that can then be used with other methods/functions.
HP -- Something in one (or more) of your image domains is not compatible with the other(s). I suggest that, as you read the image files, you print out the domain set....something like:
Please disregard my former email - I have made a mix-up between 2 code version. Running now the intended code with your proposals implented, I get the following error messages:
MIKE: java.lang.NullPointerException
TOM: Traceback (most recent call last): File "<string>", line 1, in <module> File "<string>", line 54, in average_FD TypeError: unsupported operand type(s) for /: 'instancemethod' and 'int' Line 51 refers to the line ' imgAvg = imgAvg/len(imgSeq);'
Is one of the imgSeq items null? How about printing out the domain or the whatTypes() as you loop through? Also, my example will not work at all if the first item in imgSeq is null...
The good news is that both your methods appear to work. When I use Tom's method and print out whatTypes() I get the following analysis (average over 2x2 pixels):
imgSeq(0) FunctionType: Domain has 2 components: 0. RealType: ImageElement 0. Name = ImageElement 1. RealType: ImageLine 1. Name = ImageLine Range: RealTupleType has 1 components: 0. RealType: Band9_TEMP 0. Name = Band9_TEMP 0. Unit: K FlatField of length = 8 ((ImageElement, ImageLine) -> Band9_TEMP) Domain has 2 components: Linear2DSet: Length = 8 0. Linear1DSet (ImageElement) Range = 0.0 to 3.0 step 1.0 1. Linear1DSet (ImageLine) Range = 1.0 to 0.0 step -1.0 CoordinateSystem: (ImageElement, ImageLine) ==> (Latitude, Longitude) Range has 1 components: 0. FloatSet (Band9_TEMP) Dimension = 1 0. number missing = 0
imgSeq(1) FunctionType: Domain has 2 components: 0. RealType: ImageElement 0. Name = ImageElement 1. RealType: ImageLine 1. Name = ImageLine Range: RealTupleType has 1 components: 0. RealType: Band9_TEMP 0. Name = Band9_TEMP 0. Unit: K FlatField of length = 8 ((ImageElement, ImageLine) -> Band9_TEMP) Domain has 2 components: Linear2DSet: Length = 8 0. Linear1DSet (ImageElement) Range = 0.0 to 3.0 step 1.0 1. Linear1DSet (ImageLine) Range = 1.0 to 0.0 step -1.0 CoordinateSystem: (ImageElement, ImageLine) ==> (Latitude, Longitude) Range has 1 components: 0. FloatSet (Band9_TEMP) Dimension = 1 0. number missing = 0
imgAvg FunctionType: Domain has 2 components: 0. RealType: ImageElement 0. Name = ImageElement 1. RealType: ImageLine 1. Name = ImageLine Range: RealTupleType has 1 components: 0. RealType: Band9_TEMP 0. Name = Band9_TEMP 0. Unit: K FlatField of length = 8 ((ImageElement, ImageLine) -> Band9_TEMP) Domain has 2 components: Linear2DSet: Length = 8 0. Linear1DSet (ImageElement) Range = 0.0 to 3.0 step 1.0 1. Linear1DSet (ImageLine) Range = 1.0 to 0.0 step -1.0 CoordinateSystem: (ImageElement, ImageLine) ==> (Latitude, Longitude) Range has 1 components: 0. FloatSet (Band9_TEMP) Dimension = 1 0. number missing = 0
However, I get a NullPointerException when I want to display imgAvg like