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 »

I can get the time from the image by using the .getStartTime() method on the NavigatedImage object. However, the toString() method failed to provide the string in the format needed for makeTimeFIeldFromFlatFields. It should be a simple fix, but with limited time, I was not able to get it right. I think the string must be in the format of "yyyy-mm-dd HH:mm:ssZ" and it should work. I have failed to get that format correct using simpleDateFormat.

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-

When you call getStartTime() you get back a DateTime object which can be used directly in "makeSingleTimeField" without messing with string conversions, etc. So, in makeSingleTimeField change this line:

Code: Select all

dateTime = DateTime.createDateTime(time,DateTime.DEFAULT_TIME_FORMAT,DateTime.DEFAULT_TIMEZONE)

to:

Code: Select all

dateTime = time # (or just change input argument name to dateTime, or whatever you want)

Then your calling code would look something like this:

Code: Select all

times = []
images = []
for pos in range(-5, 0):
    metadata, data = getADDEImage(**parms)
    images.append(data)
    times.append(data.getStartTime())

timeField = makeTimeFieldFromFlatFields(data, times)
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: displaying a time series of RGB images

Post by ghansham »

I really like the method given by tomR sir. I knew it was gonna be like that. But due to busy schedule could not find time to get it running. I think same method can be extended to make a time sequence for images by giving same number of times. Such method can be used for single and multiple images. I think we should have a formula for that with date and time chooser for assigning time.
Another issue i want to address is related to the filters, they work only on time sequences, not on flatfields that do not have time domain. I think it should be fixed.
Cheers
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 »

Mike,

This does not seem to be the case for me, unless I am missing something. When the function makeSingleTimeField is called from within makeTimeFieldFromFlatFields, the time is not in the correct format when taken in directly as a visad.DateTime object.

Error: Traceback (most recent call last): File " ", line 44, in File " ", line 28, in makeTimeFieldFromFlatFields File " ", line 35, in makeSingleTimeField TypeError: createDateTime(): 1st arg can't be coerced to String


I have never tried to use makeTimeFieldFromFlatFields with a time from an image directly. I have always supplied a date in string format. As I stated earlier, using the toString method on the dateTime object does not seem to be enough, but I am not sure what is needed.

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 »

ghansham

I have used Tom's code exactly for the reason of making time series of data products which have a time associated with the file when loaded into McIDAS-V. It has been a very useful tool for this purpose.

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-

After my modification, createDateTime should not be getting called. (You should delete the line of code that does createDateTime, and add in the "dateTime = time" line in the same spot. Or even better would be to just rename the input argument from "time" to "dateTime").

I can envision where the "createDateTime" thing would be useful, but in this case the NavigatedImage already has a proper DateTime so there is no need to recreate it.

Mike
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 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: Select all

"yyyy-MM-dd HH:mm:ss"


When you do "someNavigatedImage.getStartTime().toString()", the result is something like:

Code: Select all

2012-09-17 14:15:00Z

(I believe the "Z" is just seen as a trailing character and ignored... so this string works with "createDateTime").

I still need to think about the possibility of adding some helper functions for the user to help with date formatting. Let me know if you have any ideas on what type of specific functionality the user might need...

Thanks,
Mike
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,

As a start, I often convert back and forth from julian date to various year, month, day formats for use in strings and for general information. For that purpose, I use the datelist code I wrote often.

(Updated to printDate: http://mcidasv.ssec.wisc.edu/forums/vie ... afe3a8cee3)

I have no means for dealing with the time in this code. Ideally, ways to format the entire date string would include formatting for the entire date/time of a string.

Finally, is is not always obvious to me the format needed for a date string within visad. Is there a standard format that works, or is this dependent on the defaults set for the McIDAS-V session?

Not sure if this helps.
Joleen
Last edited by joleenf on Wed May 06, 2015 1:45 pm, edited 1 time in total.
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 »

joleenf wrote:As a start, I often convert back and forth from julian date to various year, month, day formats for use in strings and for general information. For that purpose, I use the datelist code I wrote often.

viewtopic.php?f=14&t=766&hilit=datelist


That's a great looking utility--particularly all the docstrings!

Often, at the command line, I want an immediate printing of the date conversion, increment from date, or current date. I have used a wrapper which prints the returned date without the status information attached. If I would rewrite this now, I would change the error handling at least. Right now, I have a complicated means of creating a string in the format I want, (ie. form=["yyyy","-","mon","-","dd"]), it is ugly, and I really need an easier way of achieving this formatting. Also, I have not means for dealing with the time in this code. Ideally, ways to format the entire date string would include formatting for the entire date/time of a string.


I didn't get any sleep last night, so maybe I'm being overly dense…but some examples would be helpful (for me, at least). [ Things like function calls using things as they currently are, plus some examples of how you'd like 'em to look. ]

Finally, is is not always obvious to me the format needed for a date string within visad. Is there a standard format that works, or is this dependent on the defaults set for the McIDAS-V session?


visad.DateTime is generally using the JDK's SimpleDateFormat to convert formatting strings into a date/time…unfortunately that includes the kinda bizarre formatting convention. Java's Date/Time handling is pretty well known for being terrible, though this is supposed to change with the arrival of JDK 8.

In the meantime, I suggest attempting to avoid Java's Date/Time handling whenever possible…one alternative is to use Python's datetime module and just convert to Java-specific stuff for the things that require it. Mike's suggestion of helper functions sounds especially nice in this context!

And FWIW, I feel like I should issue a disclaimer: I've never really come across a date/time library that doesn't have some clunkiness to it, including Python's datetime. My instinct is that the underlying "model" of applying arbitrary rules upon lengths of time introduces so many edge cases that any so-called "complete" API can't hide all the tedium.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: displaying a time series of RGB images

Post by joleenf »

I didn't get any sleep last night, so maybe I'm being overly dense…but some examples would be helpful (for me, at least). [ Things like function calls using things as they currently are, plus some examples of how you'd like 'em to look. ]


No, you are not dense, no examples make it more difficult...

In my scripts, I include the status checks and put the date into a string for use later...

Code: Select all

adate, status=datelist(inc=-1,form=['yyyy','ddd'])
         print "Take from current date", adate, status
         if (status == 0):
             removeFileName=dataDir+outDirRoot+strProjection+"_"+strBand+"_"+adate+"_"+removeTime+"UTC.jpg"
         else:
             #do something about raising an exception, something which I have to learn how to do better...maybe would be better to raise the exception within datelist.

         # may use date for annotation, new filename, file search, etc.



At the command line, I call the wrapper that I made...

Code: Select all

def pd(year=-1, month=-1, day=-1, jday=-1, jul=-1, inc=0, form=["default"]):
   jd, status=datelist(year=year, month=month, day=day, jday=jday, julian=jul, inc=inc, form=form)
   print jd


Screen Shot 2012-09-19 at 9.06.11 AM.png



Joleen
Post Reply