[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20051108: IDV extract image time



>From: "Valentijn Venus" <address@hidden>
>Organization: ITC
>Keywords: 200511081635.jA8GZT7s003999 IDV jython formula

Hi Valentijn-

>I'm trying to extend on your "IDV extract image time" example.
>Eventually I would like to  evaluating the image observation time (of an
>image object in an imageSequence) against the sunset hour for that
>particular day. We added a function that makes the hour of sunset
>available (UTC) available for a particular day in the year. If the image
>object is younger than the hour of sunset, then a certain bandmath
>formula (Land surface temperature) is used, and otherwise a nighttime
>LST algorithm should be used. I'm struggeling to get the two time
>objects in the same format in order to evaluate them:
>
>Traceback (innermost last):
>  File "<string>", line 1, in ?
>  File "<string>", line 22, in getImageTime
>AttributeError: 'None' object has no attribute 'setFormatPattern'

The problem is that you define dateTime as None and then
try to set the format pattern on it.  Essentially, you get
a NullPointerException.  If you comment out the :

    dateFormat = dateTime.setFormatPattern("yyyy")

then you'll not get the exception.  You set the pattern later and
that's what it will use.

Instead of calling:

     dateTime.setFormatPattern("yyyy")
     year = dateTime.toString()

I would call:

(set this before the loop)
     tz = TimeZone.getTimeZone("GMT");

then inside the loop:

     year = dateTime.formattedString("yyyy", tz)

When you are calling setFormatPattern, that sets a static
variable for any DateTime object.  The latter only formats
the output.

I couldn't test this because I don't have the atof
function, but hopefully you'll get the idea.

>The function looks like this:
>
>import java
>
>def getImageTime(imagesequence, i):
>   import sys;
>   sys.add_package('visad.meteorology');
>   sys.add_package('GridUtil');
>   #import java.text.SimpleDateFormat;
>   #import java.util.TimeZone;
>
>   from java.text import SimpleDateFormat
>   from visad import DateTime
>   from visad.meteorology import ImageSequence
>   from visad.meteorology import SingleBandedImage
>
>   lineValuesA = imagesequence.getFloats()
>   newd = imagesequence.clone()
>   dateTime = None
>   dateFormat = dateTime.setFormatPattern("yyyy")
>
>   if isinstance(imagesequence, ImageSequence):
>       sbi = imagesequence.getImage(int(i))
>       dateTime = sbi.getStartTime()
>   elif isinstance(imagesequence, SingleBandedImage):
>       dateTime = imagesequence.getStartTime()
>   for i in xrange(imagesequence.getDomainSet().getLength()):
>      dateTime.setFormatPattern("yyyy")
>      year = dateTime.toString()
>      lineValuesA[0][i] = atof(year)
>   newd.setSamples(lineValuesA)
> 
>   return newd 
>
>Any ideas?

Alternatively, you could use dateTime.getValue() to get
the seconds, multiply that by 1000 to get milliseconds
and create a Java Date object and use that for your
calculations if you are more familiar with manipulating
Java Date objects.

Don Murray
NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publicly available
through the web.  If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.