displaying a time series of RGB images

Post any questions, ideas, or topics related to Jython and Python scripting.
User avatar
hproe
Posts: 504
Joined: Sat Nov 27, 2010 3:46 pm

displaying a time series of RGB images

Post by hproe »

Hi -

For displaying a time series of single-channel images the 2012 Training Workshop at Madison gives an example in "Creating Movies in a McIDAS Script" found in the "Introduction to Scripting and Formulas" document. Basically it uses the display type 'Image Sequence Display' to display the aggregated image sequence.

I am interested in doing the same for RGB imagery. It would be nice to have a companion type that would display my RGB sequence (should this be promoted to a feature request?). In the absence of such a method I got the tip (courtesy Tom Whittaker) totransform the aggregated RGB sequence by using the method 'makeTime Sequence' and then display with '3 Color (RGB) Image'. I tested this successfully in May. Taking it up again now the code fails during the call to makeTimeSequence like this:

Error: Traceback (most recent call last): File " ", line 1, in File " ", line 294, in localADDE File " ", line 301, in makeTimeSequence at visad.Set. (Set.java:148) at visad.SimpleSet. (SimpleSet.java:58) at visad.SampledSet. (SampledSet.java:89) at visad.GriddedSet. (GriddedSet.java:72) at visad.Gridded1DSet. (Gridded1DSet.java:130) at visad.Gridded1DDoubleSet. (Gridded1DDoubleSet.java:107) at visad.Gridded1DDoubleSet.create(Gridded1DDoubleSet.java:174) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) visad.UnitException: visad.UnitException: Set: units dimension 1 does not match Domain dimension 2

Here is a snippet of the failing code:

Code: Select all

 myLoop=[]
 for pos in range(-2,1):
  mIR87,IR87=getADDEImage(band=7,position=(pos),**ADDE_params)
  mIR108,IR108=getADDEImage(band=9,position=pos,**ADDE_params)
  mIR120,IR120=getADDEImage(band=10,position=pos,**ADDE_params)
  imDUST=DUST_RGB(IR87,IR108,IR120)
  myLoop.append(imDUST)
 imSeq=makeTimeSequence(myLoop)
 panel=buildWindow(600,600)
 imSeqLayer=panel[0].createLayer('3 Color (RGB) Image',imSeq)


cheers, HP
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: displaying a time series of RGB images

Post by joleenf »

Hi HP,

I am seeing the same error:

viewtopic.php?f=13&t=1129&start=10

I was not able to make it work with NavigatedImage as was suggested or with the method described in your post. I also tried assigning times with makeTimeFieldFromFlatFields, which takes as input an array of flat fields and an array of times, but have struggled to get correct input formats for the data.

Joleen

FWIW, this code is not correct, because it does not work...

Code: Select all

dataSet = 'AVIATION'
imageType = 'GOES'
timesArray = ['18:32:00', '18:45:00', '19:02:00','19:15:00','19:32:00']

desc = getDescriptor(dataSet,imageType)

myLoop=[]
timeStrings=[]

for currTime in timesArray:
   params = dict(
      mag=(1,1),
      size=(600,900),
      location=(31,-84.2),
      place=CENTER,
      coordinateSystem=LATLON,
      time=(currTime,currTime),
   )

   metaData, visALB = getADDEImage(server='localhost:8112',dataset=dataSet, descriptor=desc, unit='ALB', band=1, **params)
   timeOfImage = visALB.getStartTime()
   test=timeOfImage.toString()
   timeStrings.append(timeOfImage)

   metaDataIR2, irTEMP2 = getADDEImage(server='localhost:8112',dataset=dataSet, descriptor=desc, unit='BRIT', band=2, **params)
   ?type(metaDataIR2)

   metaDataIR4, irTEMP4 = getADDEImage(server='localhost:8112',dataset=dataSet, descriptor=desc, unit='TEMP', band=4, **params)
   ?type(metaDataIR4)

   imageType2 = 'CTC'
   descProd = getDescriptor(dataSet, imageType2)
   metaDataProd, prod = getADDEImage(server='localhost:8112',dataset=dataSet, descriptor=descProd, unit='BRIT',**params)

   domainProd=getDomainSet(prod)
   visALBremap=resample(visALB,domainProd)
   irTEMP2remap=resample(irTEMP2,domainProd)
   irTEMP4remap=resample(irTEMP4,domainProd)

   r=(visALBremap+prod)/2
   g=(irTEMP2remap+prod)/2
   b=(irTEMP4remap*prod*.001)+irTEMP4

   myLoop.append(mycombineRGB(r,g,b))

print timeStrings
timeSeq=makeTimeFieldFromFlatFields(myCrazyRGB,timeStrings)
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: displaying a time series of RGB images

Post by ghansham »

Hello everyone,
actually the issue is with the maketimesequence. As far as i know make time sequence tries to create time sequence from NavigatedImage which is derived from singlebandedimageimpl. It is using navigatedimage because it has the imaging time attached to it. Here we are trying to generate a time se
equence from a multiband flatfield. The original 3-color rgb control of idv is a mystery for me. Actually tomR sir's auto scale rgb composite is a better way of doing rgb. There is a need to improve the maketimesequence by detecting the number of range components in the image flatfield functiontype and not use navigatedimage
regards
ghansham
User avatar
mhiley
Posts: 90
Joined: Mon Jan 23, 2012 10:22 pm

Re: displaying a time series of RGB images

Post by mhiley »

Hi HP -

I've got a workaround that isn't very pretty but will hopefully get you going for now. You need to make 2 changes. At the top of your script add this line:

Code: Select all

from visad.meteorology import ImageSequenceImpl


Now, change the following line in your current script:

Code: Select all

  imDUST=DUST_RGB(IR87,IR108,IR120)


To instead look like this:

Code: Select all

  imDUST=DUST_RGB(ImageSequenceImpl([IR87]), ImageSequenceImpl([IR108]), ImageSequenceImpl([IR120]))




(My understanding of) why this works (ignore if not interested in McV implementation stuff!):
NavigatedImage's are weird because they have time info associated with them, but it is accessed via getStartTime() instead of the normal VisAD function type / time domain mechanism. This is a problem in our case because if you send NavigatedImage's through an RGB function, you get a FlatField back, and the time information is essentially lost. So.... if we create an ImageSequenceImpl first out of each NavigatedImage, then the time domain is retained throughout the RGB function and we get back a FieldImpl with a proper time domain (see combineGrids in DerivedGridFactory.java). We pass in the resulting list of FieldImpl's to makeTimeSequence which no longer chokes because it is getting what it expects... Data objects with a domain type of time, but each only containing one time step.



@Joleen:
I can't find makeTimeFieldFromFlatFields anywhere... is this something you wrote yourself?

-Mike
User avatar
hproe
Posts: 504
Joined: Sat Nov 27, 2010 3:46 pm

Re: displaying a time series of RGB images

Post by hproe »

Hello Mike -

I get the following error now

Error: Traceback (most recent call last): File " ", line 1, in File " ", line 288, in localADDE TypeError: visad.meteorology.ImageSequenceImpl(): 1st arg can't be coerced to visad.meteorology.SingleBandedImage[]

Line 288 refers to
imDUST=DUST_RGB(ImageSequenceImpl([IR87]), ImageSequenceImpl([IR108]), ImageSequenceImpl([IR120])

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

Re: displaying a time series of RGB images

Post by mhiley »

hproe wrote:Hello Mike -

I get the following error now

Error: Traceback (most recent call last): File " ", line 1, in File " ", line 288, in localADDE TypeError: visad.meteorology.ImageSequenceImpl(): 1st arg can't be coerced to visad.meteorology.SingleBandedImage[]

Line 288 refers to
imDUST=DUST_RGB(ImageSequenceImpl([IR87]), ImageSequenceImpl([IR108]), ImageSequenceImpl([IR120])

HP


Darn... not sure why this is happening. Could you post the result of the following statements:

Code: Select all

print type(IR87)
print IR87.getType()


Thanks!
Mike
User avatar
hproe
Posts: 504
Joined: Sat Nov 27, 2010 3:46 pm

Re: displaying a time series of RGB images

Post by hproe »

Mike -

Relief. After restarting McV it works now as expected. Not sure what has happened before. In any case here is the requested output:
<type 'visad.meteorology.NavigatedImage'>
((ImageElement, ImageLine) -> Band7_TEMP)

sorry and many thanks, HP
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: displaying a time series of RGB images

Post by joleenf »

Mike,

Sorry, I forgot that is code that Tom R. wrote. I think it accomplishes the same task as you outlined for HP.

Code: Select all


from visad import DateTime, FunctionType, RealType, FieldImpl

# Tom Rink's script to assign a date to a flat field when it is not in the file

def makeTimeFieldFromFlatFields(fltFlds, times):
 snglTimeFlds = []
 for i in xrange(len(fltFlds)):
   fld = makeSingleTimeField(times[i], fltFlds[i])
   snglTimeFlds.append(fld)

 return makeTimeSequence(snglTimeFlds)


def makeSingleTimeField(time, fltFld):
 dateTime = DateTime.createDateTime(time,DateTime.DEFAULT_TIME_FORMAT,DateTime.DEFAULT_TIMEZONE)
 fncType = FunctionType(RealType.Time, fltFld.getType())
 timeSet = DateTime.makeTimeSet([dateTime])
 newField = FieldImpl(fncType, timeSet)
 # do not make a copy of the values
 print type(fltFld)
 newField.setSample(0, fltFld,0)
 return newField
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: displaying a time series of RGB images

Post by Jon »

Hrm. I kinda prefer the "makeTimeFieldFromFlatFields" approach to creating multiple ImageSequenceImpls--seems more straightforward than creating N ImageSequenceImpls to display N images.
User avatar
mhiley
Posts: 90
Joined: Mon Jan 23, 2012 10:22 pm

Re: displaying a time series of RGB images

Post by mhiley »

Jon! wrote:Hrm. I kinda prefer the "makeTimeFieldFromFlatFields" approach to creating multiple ImageSequenceImpls--seems more straightforward than creating N ImageSequenceImpls to display N images.

I agree... the downside is that it forces the user to keep track of time fields explicitly.
Post Reply