splitr icon indicating copy to clipboard operation
splitr copied to clipboard

Running series of trajectories w/ different starting times and durations

Open joshkraft opened this issue 5 years ago • 1 comments

I am interested in running a series of HYSPLIT trajectories over certain periods of time. These periods were selected from a larger time series, I.E. "Select all periods of time with strong winds for at least 4 hours." The dataframe resulting the aforementioned function contains:

  • date + time the episode began
  • date + time the episode ended
  • duration of episode in hours

In a perfect world, I would like to feed this data into the SplitR function and calculate back trajectories for each hour within each episode. A second best option would be to calculate one trajectory for each episode.

When I run the code, I get the following error:

Error in hysplit_trajectory(lat = lat, lon = lon, height = 15, duration = 36, : object 'run_type' not found

Another issue I can imagine running into (if I can get past the previous error) is episodes that begin on one day and end on another. This is fairly common in my dataset. I am not sure how to work around this.

For the full project, I am interested in working with a few thousand episodes. So right now I am trying to get a "proof of concept" to figure out if it can even be done with SplitR. I have attached a reprex below.

(this is my first time sharing code on Github so let me know if I am missing something.)

library(SplitR)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date

# coordinates
lat <- 41.0541
lon <- -124.151

# sample data
episodes <- data.frame(
  episode = c(1:3),
  start = c("2007-12-08 18:00:00", "2007-12-09 19:00:00", "2007-12-10 03:00:00"),
  end = c("2007-12-09 03:00:00", "2007-12-09 23:00:00", "2007-12-10 08:00:00"),
  length = c("9", "5", "6")
  )

# extract date + hour episode starts
start_date <- date(episodes$start)
start_hour <- hour(episodes$start)

# run trajectory
trajectory <- 
  hysplit_trajectory(
    lat = lat,
    lon = lon,
    height = 15,
    duration = 36,
    run_period = start_date,
    daily_hours = start_hour,
    direction = "backward",
    met_type = "gdas1",
    extended_met = FALSE) 
#> Error in hysplit_trajectory(lat = lat, lon = lon, height = 15, duration = 36, : object 'run_type' not found

trajectory_plot(trajectory)
#> Error in trajectory_plot(trajectory): object 'trajectory' not found

Created on 2018-07-02 by the reprex package (v0.2.0).

joshkraft avatar Jul 02 '18 20:07 joshkraft

It seems like we should have a helper function like traj_episodes() that accepts timing and location information, along with an episode name for the group. This aligns nicely with an idea to add more columns to the tibble output from the trajectory model.

Let me think about this some more. I’ll post a proposal about how to enhance things here.

rich-iannone avatar Aug 11 '19 00:08 rich-iannone