davidcarslaw / openair

Tools for air quality data analysis
https://davidcarslaw.github.io/openair/
GNU General Public License v2.0
303 stars 113 forks source link

A bug in trajPlot with argument "group"? #43

Closed lyggd closed 8 years ago

lyggd commented 8 years ago

I try to make colored my Hysplit tracks with different O3 concentraiton today and find a very interesting phenomena. My code is

traj_JLG$intervals<- cut(traj_JLG$O3, breaks = c(0, 0.05, 0.07,1.0), labels = c("0 to 0.05","0.05 to 0.07", ">0.07"))

trajPlot(selectByDate(traj_JLG, start = "01/01/2013", end = "30/12/2014"), group = "intervals" ,col = c("green", "blue", "red"), lwd =2,key.title='O3 Concentration Bin', key.pos = "top",key.col = 3, border = NA,lon = "lon", lat = "lat", map = TRUE ,map.fill = F,grid.col = F, map.res = "state", projection="albers", xlim=c(-126,-105), ylim=c(28,42)) But there are no background map for November, December, January and February (figure below). rplot07

But as long as I delete group = "intervals", the background map will come back. Is there anyone know why ? Thank you very much for your help. Best Regards, Yi

davidcarslaw commented 8 years ago

Thanks. I just tried plotting a few maps like this in the USA but can't reproduce your problem. If you save the trajectory data and email it to me that would be good. Save it as an RData file, something like save(traj_JLG, file = "traj_JLG.RData"). Thanks.

lyggd commented 8 years ago

Hi David, All the data have been send to your email david.carslaw@york.ac.uk. I appreciate your help very much. Best Regards,

davidcarslaw commented 8 years ago

This should be fixed now.

lyggd commented 8 years ago

Hi David, Thank you very much for your help. I re-run the code but it show erro :+1: Error in match(x, table, nomatch = 0L) : object 'dateTypes' not found

3 match(x, table, nomatch = 0L) 2 group %in% dateTypes at myFunction_NARR.r#878 1 trajPlot(selectByDate(traj_JLG, start = "01/01/2013", end = "30/12/2014"), group = "intervals", col = c("green", "blue", "red"), lwd = 2, key.title = "O3 Concentration Bin", key.pos = "top", key.col = 3, border = NA, lon = "lon", lat = "lat", map = TRUE, map.fill = F, ...

Could you give some hint to fix this problem ? Thank you very much. Yi

davidcarslaw commented 8 years ago

Sounds like openair is not loaded properly - or you have a copy of an openair function in the Global environment, type ls() to see what is there. I have tested the back trajectories and they work fine on the test data. I would try again in a fresh R session and then try:

traj <- importTraj()
trajCluster(traj, method = "Angle", n.cluster =6)

which should give the proportions...

lyggd commented 8 years ago

Hi David, The problem was finally solved ! One last question I hope related to trajCluster is it can not do the seasonal plots. My code is
traj <- importTraj(site = "london", year = 2010)

kc1 <- importAURN("kc1", year =2010)

traj <- merge(traj, kc1, by = "date")

clust <- trajCluster(traj, method = "Angle",type = "season", n.cluster = 8, map.cols = openColours("Paired", 10)) And it dose not work for me.

davidcarslaw commented 8 years ago

Thanks - away today but will fix shortly...

David On 8 Feb 2016 11:52 pm, "lyggd" notifications@github.com wrote:

Hi David, The problem was finally solved ! One last question I hope related to trajCluster is it can not do the seasonal plots. My code is

traj <- importTraj(site = "london", year = 2010) kc1 <- importAURN("kc1", year =2010) traj <- merge(traj, kc1, by = "date") clust <- trajCluster(traj, method = "Angle",type = "season", n.cluster = 8, map.cols = openColours("Paired", 10)) And it dose not work for me.

— Reply to this email directly or view it on GitHub https://github.com/davidcarslaw/openair/issues/43#issuecomment-181629962 .

davidcarslaw commented 8 years ago

Hopefully should be fixed now. When you have several panels e.g. with type = "season" it will give the % contribution overall, rather than by panel.

lyggd commented 8 years ago

Hello David, Thank you very much. I appreciate your help very much. The code I listed did work now. But my personal code still not work. Error in as.POSIXct.POSIXlt(what, tz = tzone) : invalid 'tz' value I am wondering if there is still a timezone bug the openair function. My personal code is

library("openair")
library("plyr")
library("lattice")
library('maps')
library('mapdata')
library('Cairo')
library('openxlsx')
library("mapproj")
library('cluster')
rm(list=ls())
traj <- importTraj(site = "JLG Supersite2", year = 2013:2014, 
                       local ='M:/HYSPLIT/output/TrajProc/' )
traj$day <- as.Date(traj$date)
JLGTraj_24 <- subset(traj, hour.inc >= -24)
clust <- trajCluster(traj_JLG, method = "albers", n.cluster= 4, col = "Set2",type = 'season',
                     map.res = "state",main= "Cluster Map",
                     map.fill = F, grid.col = F, projection="albers",
                     xlim=c(-126,-105), ylim=c(28,42))

You already have my RData in 2013 and 2014, would you check this problem for me ? Thank you very much. Happy Chinese New Year ! Yi

davidcarslaw commented 8 years ago

The error is almost certainly because your date format is incorrect. What does str(traj_JLG) return?

lyggd commented 8 years ago

Problem solved. I appreciate your help so much. Just a following question: I find the number on the trajectory sometime is hard to read. Is there anyway to set the percentage number for each trajector ? Thanks image

davidcarslaw commented 8 years ago

I too thought this would be useful, so rather than percentages for all periods, they can be expressed by panel. I have just committed a change where there is a new option by.type, which when TRUE will calculate the percentages by panel.

lyggd commented 8 years ago

Sorry for bring the confusion. I just want to set the position of "percentage number" for each trajector ? For example, in winter panel, two number overlaid and make them hard to read. Thank you very much. Yi