openair icon indicating copy to clipboard operation
openair copied to clipboard

open air does not read meteorological output

Open vargasdanny opened this issue 2 years ago • 2 comments

Hi David, I would like to ask if openair can read the additional meteorological data from HYSPLIT. I can generate the additional columns of data in my trajectories (e.g., AIR_TEMP, RAINFALL, RELHUM, SUN_FLUX) using the HYSPLIT GUI but I do not get any of these variables in my trajectories when running it from R using openair. In fact, I only get the pressure data. Is there anything I am doing wrong, or simply the output (dataframe) was created to only read pressure data? thanks

vargasdanny avatar Mar 10 '22 06:03 vargasdanny

If you want the additional data from the HYSPLIT model with your trajectory data, then you have to instruct the HYSPLIT model to output those values.

Unfortunately the machine I am on now does not have an installation of HYSPLIT, but if my memory serves me correctly you need to set the values for these parameters in the default ini file from 0 to 1. Please note that this has nothing to do with openair, as openair only is used to run the model, not to config it by changing these parts of the ini file. Although the latter can be done easily by R if one would pursue this option.

[edited] I am sorry, I misread. The function in openair for reading the files is fixed to the set of variables. If you want to read more you have to modify the function, particularly at line 408 of https://gist.github.com/davidcarslaw/c67e33a04ff6e1be0cd7357796e4bdf5.

schonhose avatar Mar 11 '22 21:03 schonhose

Thank you so much for your reply. I solved by creating a new function for only reading the trajectories generated by the HYSPLIT GUI, which contain the additional meteorology (e.g., AIR_TEMP, RAINFALL, RELHUM, SUN_FLUX, etc). The new script read all the file paths where my trajectories are using a loop and then I modified the lines 408 from the "run_hysplit.R" function. If it helps to someone it looks something like this:

#1. Read the name of the generated trajectories as a vector raw.files <- data_frame(filename = list.files('path_to_folder_with_trajectories/', pattern = "")) #pattern can be e.g. "1500winter" but if not can be omitted

#2. Mutate raw.file.paths <- raw.files %>% mutate(filepath = paste0('path_to_folder_with_trajectories/', filename))

#3. For loop raw.data <- raw.file.paths %>% rowwise() %>% do(., read.table(file=.$filepath, header = FALSE, skip = 12)) #skip 12 worked in my case, but you must check the onset of your trajectories in the HYSPLIT file

#4. Modified from David Carslaw function read_hysplit.R #Drop traj <- subset(raw.data, select = -c(V2, V7, V8))

#Rename traj <- plyr::rename(traj, c(V1 = "receptor", V3 = "year", V4 = "month", V5 = "day", V6 = "hour", V9 = "hour.inc", V10 = "lat", V11 = "lon", V12 = "height", V13 = "pressure", V14 = "theta", V15 = "temp", V16= "rainfall", V17 = "mixdepth", V18 = "relhumid", V19 = "spchumid", V20 = "h20mixra", V21 = "terr_msl", V22 = "sunflux"))

#Clean two digit years traj$year <- ifelse(traj$year < 50, traj$year + 2000, traj$year + 1900)

#Transform pieces of date to date traj$date2 <- with(traj, ISOdatetime(year, month, day, hour, min = 0, sec = 0, tz = "GMT"))

#Transform arrival time, minus hours from hour.inc variable traj$date <- traj$date2 - 3600 * traj$hour.inc

As a result you must have a dataframe called "traj" with all the trajectories ready to use in openair :) Hope it helps

vargasdanny avatar Mar 13 '22 20:03 vargasdanny