whatType getting Dimensions of array

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

whatType getting Dimensions of array

Post by joleenf »

I am probably making this too hard. When there is a visad data object, it is possible to see if there is a time associated with the object or if it has been omitted:

Code: Select all

print type(bandDiff), whatType(bandDiff)

<type 'visad.meteorology.SingleBandedImageImpl'>
# 11:20:57.308 [Thread-2997] INFO:
FunctionType:
Domain has 2 components:
0. RealType: ImageElement
0. Name = ImageElement
1. RealType: ImageLine
1. Name = ImageLine
Range:
RealTupleType has 1 components:
0. RealType: Band2_TEMP
0. Name = Band2_TEMP
0. Unit: K


and

Code: Select all

print type(d), whatType(d)

<type 'visad.meteorology.ImageSequenceImpl'>
FunctionType:
Domain has 1 components:
0. RealType: Time
0. Name = Time
0. Unit: s since 1970-01-01 00:00:00.000 UTC
Range:
FunctionType:
Domain has 2 components:
0. RealType: ImageElement
0. Name = ImageElement
1. RealType: ImageLine
1. Name = ImageLine
Range:
RealTupleType has 1 components:
0. RealType: Band2_TEMP
0. Name = Band2_TEMP
0. Unit: K




How can that be tested in code? It seems that testing len(d.getDomainSet()) == 1 is sloppy and too narrow. Is there a better way?

Joleen
User avatar
mhiley
Posts: 90
Joined: Mon Jan 23, 2012 10:22 pm

Re: whatType getting Dimensions of array

Post by mhiley »

Hi Joleen,
GridUtil.isTimeSequence should do the trick:

Code: Select all

from ucar.unidata.data.grid import GridUtil
print GridUtil.isTimeSequence(yourData)

To be true, the data object must not be a Flatfield, and its domain must be 1-dimensional and of type Time. So this means you will still get 'true' if your ImageSequenceImpl only has a single time step. For a SingleBandedImageImpl, however, you should always get 'false'.

Hopefully that helps.

-Mike
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: whatType getting Dimensions of array

Post by joleenf »

Thanks Mike, this is useful information.

Joleen
Post Reply