displaying a time series of RGB images

Post any questions, ideas, or topics related to Jython and Python scripting.
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 Mike,

I am responding to this

Hi Joleen,

I looked in to this a little more and it looks like you should be able to use "someImage.getStartTime().toString()" in the "createDateTime" method. The specific script you posted toward the beginning of this thread is probably failing (using your unmodified makeSingleTimeField) because you append "timeOfImage" (a DateTime object) to "timeStrings" instead of "timeOfImage.toString()".

To hopefully clarify this a little, the "DEFAULT_TIME_FORMAT" in the VisAD DateTime class is the following string:
Code:
"yyyy-MM-dd HH:mm:ss"


When you do "someNavigatedImage.getStartTime().toString()", the result is something like:
Code:
2012-09-17 14:15:00Z


Even making this change, did not help, I thought perhaps because my time in not exactly in the form 'yyyy-mm-dd HH:mm:ssZ' but in 'yyyy-mm-dd HH:mm UTC', so I split the string apart, and still get the same error:

Error: Traceback (most recent call last): File " ", line 47, in File " ", line 31, in makeTimeFieldFromFlatFields File " ", line 38, in makeSingleTimeField at visad.DateTime.createDateTime(DateTime.java:510) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) visad.VisADException: visad.VisADException: invalid date string: 2011-08-09 19:15


Am I totally misunderstanding this problem?

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

Re: displaying a time series of RGB images

Post by mhiley »

It looks to me like the "seconds" part of the date/time string is necessary:

Code: Select all

from visad import DateTime

# this fails (no "seconds" field)
print DateTime.createDateTime("2011-08-09 19:15")
 
Error: Traceback (most recent call last): File " ", line 1, in   at visad.DateTime.createDateTime(DateTime.java:510) at visad.DateTime.createDateTime(DateTime.java:472) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) visad.VisADException: visad.VisADException: invalid date string: 2011-08-09 19:15 

# seems to work with a "seconds" field:
print DateTime.createDateTime("2011-08-09 19:15:00")
2011-08-09 19:15:00Z
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,

I ran across another case where the DateTime object was of the format: "yyyy-MM-dd HH:mm" so that I could not use makeTimeFIeldFromFlatFields without adjustment. The method "formattedString" within the visadDateTime object class works for adjustment of the dateTime object:

# get info about the dateTime object in my code
print type(modelTime)

<type 'visad.DateTime'>
print modelTime




Code: Select all

from java.util import SimpleTimeZone
 
# construct a time zone with no offset from GMT time.
tz = SimpleTimeZone(0,"UTC")
reformatModelTime = modelTime.formattedString("yyyy-MM-dd HH:mm:ss", tz)


print reformatModelTime

2012-06-29 21:00:00


Joleen
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,

I am facing a similar problem to the original post. I have a sandwich RGB image created using a script that Mike has developed. Is there a way to create an ImageSequenceImpl from this and display as an RGB Composite?

I have tried the following code with the visible data and cooresponding IR data

print whatType(imgVIS)
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: Band1
0. Name = Band1


Code: Select all

from visad.meteorology import ImageSequenceImpl
rgbImg=[]
for dt in imgVIS.getImageTimes():
   rgbImg.append(sandwich(colorTable[0], imgIR.getImage(counter), guessALB[counter], minIR, maxIR))
   counter=counter+1

test=ImageSequenceImpl([rgbImg])


but this fails, because rgbImg is an array of flat fields not a single banded image.

I have also tried:

Code: Select all

timeString=[]
for dt in imgVIS.getImageTimes():
   timeString.append(dt.toString())
timeField=makeTimeFieldFromFlatFields(rgbImg, timeString)


(where makeTimeFieldFromFlatFields is a function cited earlier in this post.)


and get the following error:


Number of Flat Fields: 3 Number of Times: 3 counter 0 2014-05-20 23:05:00Z
VisAD MathType analysis
FunctionType:
Domain has 2 components:
0. RealType: ImageElement
0. Name = ImageElement
1. RealType: ImageLine
1. Name = ImageLine
Range:
RealTupleType has 3 components:
0. RealType: redimage1
0. Name = redimage1
1. RealType: greenimage1
1. Name = greenimage1
2. RealType: blueimage1
2. Name = blueimage1
DataType
analysis... FlatField of length = 519200
((ImageElement, ImageLine) -> (redimage1, greenimage1, blueimage1))
Domain has 2 components:
Linear2DSet: Length = 519200
0. Linear1DSet (ImageElement) Range = 0.0 to 799.0 step 1.0
1. Linear1DSet (ImageLine) Range = 648.0 to 0.0 step -1.0
CoordinateSystem: (ImageElement, ImageLine) ==> (Latitude, Longitude)
Range has 3 components:
0. FloatSet (redimage1) Dimension = 1
0. number missing = 0
1. FloatSet (greenimage1) Dimension = 1
1. number missing = 0
2. FloatSet (blueimage1) Dimension = 1
2. number missing = 0
Number of Flat Fields: 3 Number of Times: 3 counter 1 2014-05-20 23:06:00Z
FunctionType:
Domain has 2 components:
0. RealType: ImageElement
0. Name = ImageElement
1. RealType: ImageLine
1. Name = ImageLine
Range:
RealTupleType has 3 components:
0. RealType: redimage2
0. Name = redimage2
1. RealType: greenimage2
1. Name = greenimage2
2. RealType: blueimage2
2. Name = blueimage2
DataType
analysis... FlatField of length = 519200
((ImageElement, ImageLine) -> (redimage2, greenimage2, blueimage2))
Domain has 2 components:
Linear2DSet: Length = 519200
0. Linear1DSet (ImageElement) Range = 0.0 to 799.0 step 1.0
1. Linear1DSet (ImageLine) Range = 648.0 to 0.0 step -1.0
CoordinateSystem: (ImageElement, ImageLine) ==> (Latitude, Longitude)
Range has 3 components:
0. FloatSet (redimage2) Dimension = 1
0. number missing = 0
1. FloatSet (greenimage2) Dimension = 1
1. number missing = 0
2. FloatSet (blueimage2) Dimension = 1
2. number missing = 0
Number of Flat Fields: 3 Number of Times: 3 counter 2 2014-05-20 23:07:00Z
FunctionType:
Domain has 2 components:
0. RealType: ImageElement
0. Name = ImageElement
1. RealType: ImageLine
1. Name = ImageLine
Range:
RealTupleType has 3 components:
0. RealType: redimage3
0. Name = redimage3
1. RealType: greenimage3
1. Name = greenimage3
2. RealType: blueimage3
2. Name = blueimage3
DataType
analysis... FlatField of length = 519200
((ImageElement, ImageLine) -> (redimage3, greenimage3, blueimage3))
Domain has 2 components:
Linear2DSet: Length = 519200
0. Linear1DSet (ImageElement) Range = 0.0 to 799.0 step 1.0
1. Linear1DSet (ImageLine) Range = 648.0 to 0.0 step -1.0
CoordinateSystem: (ImageElement, ImageLine) ==> (Latitude, Longitude)
Range has 3 components:
0. FloatSet (redimage3) Dimension = 1
0. number missing = 0
1. FloatSet (greenimage3) Dimension = 1
1. number missing = 0
2. FloatSet (blueimage3) Dimension = 1
2. number missing = 0
visad.TypeException: FieldImpl.setSample: bad range type


Is there a way to make an image sequence out of this?

Joleen
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: displaying a time series of RGB images

Post by ghansham »

Hi joleen
Its doable. I have done it in insat plugin.
I can send you the java code snippet.
Visad imagesequenceImpl wont work
as it does support image sequence of single band images.
I will send it to you by tomorrow.
Meanwhile can you post the body of
makeTimeFieldFromFlatfields method.

Regards
Ghansham
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 Ghansham,

Here is the function:

Code: Select all

 #====================================================================================
# 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)):
   print "Number of Flat Fields:  ", len(fltFlds), "Number of Times: ", len(times), "counter", i,times[i]
 
   printType(fltFlds[i])
   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)
  #dateTime=time
  fncType = FunctionType(RealType.Time, fltFld.getType())
  timeSet = DateTime.makeTimeSet([dateTime])
  newField = FieldImpl(fncType, timeSet)
  # do not make a copy of the values
  newField.setSample(0, fltFld,0)
  return newField


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

Re: displaying a time series of RGB images

Post by mhiley »

Joleen,

I can't think of any obvious reason why setSample would be failing in this scenario.

Just for fun, in the makeSingleTimeField function, you could modify

newField.setSample(0, fltFld,0)

to read

newField.setSample(0, fltFld,0, 0)

This is a different form of setSample that disables the range equality check that is failing. To quote the VisAD javadoc, "use this only if you like shooting yourself in the foot." I'm curious to see what happens though :)

(side note: since the full stack trace got swallowed...I'm not even sure that's the setSample that is failing! There is another one in "makeTimeSequence" that could be the culprit...)
User avatar
hproe
Posts: 504
Joined: Sat Nov 27, 2010 3:46 pm

Re: displaying a time series of RGB images

Post by hproe »

Good people -

Not sure whether a snippet from my code could help. It creates an image sequence of RGBs using one of my RGB formulas (ImS stands for ImageSequencImpl)

Code: Select all

image=VOLC_RGB(ImS([IR87]),ImS([IR108]),ImS([IR120]))
imageSeq.append(image)
imageLoop=makeTimeSequence(imageSeq)
imLayer=imDisplay.createLayer('RGB Composite',imageLoop)

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,

The result of adding the zero to the setSample method is

Number of Flat Fields: 3120000 Number of Times: 3 counter 0 2014-05-20 23:05:00 Z
RealTupleType has 3 components:
0. RealType: redimage16
0. Name = redimage16
1. RealType: greenimage16
1. Name = greenimage16
2. RealType: blueimage16
2. Name = blueimage16
DataType
analysis... RealTuple has 3 components:
0. Real: 0.0
1. Real: 0.0
2. Real: 0.0
Number of Flat Fields: 3120000 Number of Times: 3 counter 1 2014-05-20 23:06:00 Z
RealTupleType has 3 components:
0. RealType: redimage16
0. Name = redimage16
1. RealType: greenimage16
1. Name = greenimage16
2. RealType: blueimage16
2. Name = blueimage16
DataType
analysis... RealTuple has 3 components:
0. Real: 0.0
1. Real: 0.0
2. Real: 0.0
Number of Flat Fields: 3120000 Number of Times: 3 counter 2 2014-05-20 23:07:00 Z
RealTupleType has 3 components:
0. RealType: redimage16
0. Name = redimage16
1. RealType: greenimage16
1. Name = greenimage16
2. RealType: blueimage16
2. Name = blueimage16
DataType
analysis... RealTuple has 3 components:
0. Real: 0.0
1. Real: 0.0
2. Real: 0.0
Number of Flat Fields: 3120000 Number of Times: 3 counter 3
Traceback (most recent call last):
File "<string>", line 87, in <module>
File "<string>", line 15, in makeTimeFieldFromFlatFields
IndexError: index out of range: 3


Joleen
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 tried using the outlined method of creating an ImageSequenceImpl from a list, but this failed for me as well. The sandwich code returns a FlatField, and the ImageSequenceImpl requires a SingleBandedImage. I think SingleBandedImages are usually the result of an ADDE connection to the data.

Joleen
Post Reply