datetime object from loadADDEImage

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

datetime object from loadADDEImage

Post by joleenf »

Is there a way to get a date/time object from the loadADDEImage metadata? I feel like I am going in circles with the code below. I first get each date, time, then create a user customized date string. Then I take that date string and create a DateTime object. I use that object later to find the difference between the image and the point observation time, so I will need the DateTime object. However, it seems if I can grab a DateTime object directly, I could also use the formattedString method of that class to get the various strings I need to create file names and label the image.

Code: Select all

for dateTime in dateTimeList:
       thisTime=dateTime['time']
       thisYearJulianDay=dateTime['day']
       image=loadADDEImage(day=thisYearJulianDay,time=thisTime, **addeLoadParms)
 
      #see repeat of string creation here.  this could be done without the following 5 lines if I could use a DateTime object from the start...
       javaDate,strDate=printDate(thisYearJulianDay, inputFormat='yyyyDDD',outFormat='yyyy-MMM-dd')
       currentDay=strDate[9:]
       currentTime=(''.join(thisTime.split(':')))[0:4]
       dateString=' '.join([strDate, thisTime])
   
       currentDateTime=(DateTime.createDateTime(dateString,'yyyy-MMM-dd HH:mm:ss',tz))

      #If I had a DateTime object, I would only need these two lines...
       currentDay=currentDateTime.formattedString('dd',tz)
       currentTime=currentDateTime.formattedString('HHmm',tz)



Thanks,
Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: datetime object from loadADDEImage

Post by Jon »

Hi Joleen,

Just so we're on the same page, you're looking for something like a 'datetime' key that points to a DateTime object...correct? If so, I should have something committed today.

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

Re: datetime object from loadADDEImage

Post by joleenf »

Jon, that is correct.

Thanks,
Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: datetime object from loadADDEImage

Post by Jon »

FWIW I wrote this up as Inquiry 2178, and here's the commit:

https://github.com/mcidasv/mcidasv/comm ... d6169bcf12
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: datetime object from loadADDEImage

Post by joleenf »

Ugh, :?

I was confusing myself. The time listing from listADDEImages is a string. The object returned from loadADDEImage has a key "nominal-time" in the metadata that always has returned a dateTime object in McIDAS-V 1.5. This means that I caused duplication by requesting a datetime keyword in loadADDEImages metdata. Not too late to remove the duplication? Sorry for the work.

Joleen
User avatar
bobc
Posts: 990
Joined: Mon Nov 15, 2010 5:57 pm

Re: datetime object from loadADDEImage

Post by bobc »

Hi Joleen -

I believe that the reason that the datetime key was added to loadADDEImage was for consistency with listADDEImageTimes. In 1.5, the only two keys returned from listADDEImageTimes were day and time. We added datetime to this output to stitch date and time into one key.

Note that while datetime is now a key in the object returned from loadADDEImage and listADDEImages, there is still a bit of an inconsistency in how they are specified. For example, datetime returned from listADDEImages matches the nominal-time key, while datetime returned from loadADDEImage matches the start-time key. Inquiry 2178 is still in programmer iteration to get this inconsistency looked at.

nominal-time and start-time are still valid keys of listADDEImages and loadADDEImage. So there is some duplication in the keys returned from the commands, but we wanted to keep consistency between the functions, so datetime is now applicable everywhere. We kept start-time and nominal-time around so user's scripts wouldn't break.

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

Re: datetime object from loadADDEImage

Post by joleenf »

Thanks for the clarification Bob and consistency makes sense. datetime as a keyword in the listing will be very useful. (For original reason I posted this message).

Thanks,
Joleen
Post Reply