List Info

Thread: Raster time series and R - timezones?




Raster time series and R - timezones?
user name
2006-06-20 22:31:57
On Tue, Jun 20, 2006 at 12:04:27PM +1200, Hamish wrote:
> > I am processing daily time series of MODIS but
cannot
> > figure out how to use time stamps properly. With
r.what
> > I am looping over the maps and add a timestamp
like
> > this "7 Apr 2006 10:30:00 UTC" to each
extracted value.
> 
> 
> > > strptime(mytime,"%d %b %Y
%H:%M:%S")
> > [1] "2006-04-07 10:30:00"
> > -> UTC lost
> 
> add %Z to include timezone?

This is the lacking feature... strptime doesn't care of %Z.
 
But I am getting closer (R news article is unfortunately
already dated):

# Running R in German location

# this fails since May isn't German:
> mytime <- "7 May 2006 10:30:00 UTC"
> strptime(mytime,"%d %b %Y %H:%M:%S")
[1] NA

# set to C locale at least for LC_TIME:
> Sys.setlocale("LC_TIME", "C")
[1] "C"
> Sys.getlocale(category = "LC_ALL")
[1]
"LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLAT
E=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-
8;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUR
EMENT=C;LC_IDENTIFICATION=C"

> Sys.getlocale(category = "LC_TIME")
[1] "C"

# test if May now works in previously German locale:
> mytime <- "7 May 2006 10:30:00 UTC"
> strptime(mytime,"%d %b %Y %H:%M:%S")
[1] "2006-05-07 10:30:00"

# now that works.

# Next a funky conversion:
> mytime
[1] "7 May 2006 10:30:00 UTC"
> as.POSIXlt(as.POSIXct(strptime(mytime,"%d %b %Y
%H:%M:%S")),tz="GMT")
[1] "2006-05-07 08:30:00 GMT"

# -> time differs by 2 hours, apparently the input is
treated as CEST
#    (current time today in Itay)

# checking change of time zone (as parameter to
as.POSIXct()):
> as.POSIXlt(as.POSIXct(strptime(mytime,"%d %b %Y
%H:%M:%S"),tz="CEST"))
[1] "2006-05-07 10:30:00 CEST"

# also works. Remaining problem: The input 'mytime' was
already GMT, no
# need to shift for 2 hours.

# So we do extra funky tricks:
> mytime
[1] "7 May 2006 10:30:00 UTC"
> as.POSIXlt(as.POSIXct(strptime(mytime,"%d %b %Y
%H:%M:%S")),tz="GMT-2")
[1] "2006-05-07 10:30:00 GMT"
# -> works. Now the input is as we wanted.

> dt.mytime <-
as.POSIXlt(as.POSIXct(strptime(mytime,"%d %b %Y
%H:%M:%S")),tz="GMT-2")
> dt.mytime
[1] "2006-05-07 10:30:00 GMT"
str(dt.mytime)
'POSIXlt', format: chr "2006-05-07 10:30:00"

# final test on new object:
> as.POSIXct(dt.mytime, tz="CET")
[1] "2006-05-07 11:30:00 CEST"
# -> partially works: I asked CET, not CEST. The result
is CET, not CEST (wrongly
#                     indicated...)

# day light saving time?
dt.mytime[["isdst"]]
[1] 0
# -> also wrong. Gotcha. In May we have DST.

Sys.timezone()
[1] ""
# -> Why empty? Due to my LC_TIME="C" change?


Really intuitive and well documented... sigh.
Further pointers are welcome.

I just want to avoid that the daylight saving time built-in
in R shifts my satellite observations which are given in
UTC.

Markus

_______________________________________________
statsgrass mailing list
statsgrassgrass.itc.it
http:
//grass.itc.it/mailman/listinfo/statsgrass
Raster time series and R - timezones?
user name
2006-06-21 02:45:57
Markus wrote:

> > > > strptime(mytime,"%d %b %Y
%H:%M:%S")
> > > [1] "2006-04-07 10:30:00"
> > > -> UTC lost
> > 
> > add %Z to include timezone?
> 
> This is the lacking feature... strptime doesn't care
of %Z.


Then it's R's strptime() which has a problem. 

I found %Z on the glibc <time.h> strptime() help page.

Maybe it is best to write a little bash script using `date
--iso` or
tiny C program using time.h's strptime() to pre-process the
data?
I take it R lets you do system() calls somehow.
versus fighting R for a feature which doesn't exist.

does R have a gmtime() or localtime() equivalent?


Hamish

_______________________________________________
statsgrass mailing list
statsgrassgrass.itc.it
http:
//grass.itc.it/mailman/listinfo/statsgrass
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )