oscarperpinan / solar

Solar Radiation and Photovoltaic Systems with R
http://oscarperpinan.github.io/solar/
GNU General Public License v3.0
35 stars 13 forks source link

calcSol not using correct UTC time stamps #5

Closed fleimgruber closed 9 years ago

fleimgruber commented 9 years ago

Given

library(solaR)

test <- calcSol(48.27, fBTd(mode = "serie",
                            start = as.POSIXct("2015-01-01"),
                            end = as.POSIXct("2015-02-01")),
                sample = "15 min")

head(test@solI$Bo0, n=40)

the resulting test object has the first non-zero value of solI$Bo0 at 8 a.m. UTC. According to another source of sunrise time, the local time (UTC+1 in this case) of sunrise was at 7:45 a.m. So the series of solI$Bo0 seems to be off by one hour.

time(test@solI$Bo0[1])

gives

: [1] "2015-01-01 UTC"

and

Sys.getenv("TZ")

gives "UTC".

sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] solaR_0.41          latticeExtra_0.6-26 RColorBrewer_1.1-2 
[4] lattice_0.20-33     zoo_1.7-12         

loaded via a namespace (and not attached):
[1] compiler_3.2.0 tools_3.2.0    grid_3.2.0
oscarperpinan commented 9 years ago

The use of UTC in solaR is a synonym of mean solar time, as documented in the local2solaR help page (I will add this information in the introductory help page of the package):

It is important to note that the ‘solaR’ package sets the system time zone to ‘UTC’ with ‘Sys.setenv(TZ='UTC')’. Every ‘zoo’ object created by the package will have an index with this time zone and will be supposed to be mean solar time.

I know that this is a confusing use of time zones, but I haven't found a better solution yet. Maybe I will change to chron or data.table::ITime in the future.

fleimgruber commented 9 years ago

Thanks for the clarification. Thinking in terms of a solution, one could convert the mean solar time to true UTC time based on the time zone that needs to be deducted from the given longitude, correct?

oscarperpinan commented 9 years ago

Right. The function local2solaR implements the inverse conversion.