-
Notifications
You must be signed in to change notification settings - Fork 1
/
subset_by_time.R
65 lines (53 loc) · 2.23 KB
/
subset_by_time.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#need to find out how and where "sections" turn into "intersections"
#where is the cut off
#then display this line on the photo
#list of files in the directory
#Atlanta-Peachtree.tfw
#Atlanta-Peachtree.tif
#camera-coverage.dbf
#camera-coverage.sbn
#camera-coverage.sbx
#camera-coverage.shp
#camera-coverage.shx
#detector-data.csv
#NGSIM_Peachtree_Vehicle_Trajectories.csv
#create link to james' data folder
data_folder <- "/data/store05/phd/data/zcfajat/LA Traffic Highway Detector Data /"
#this is the data on the individual vehicles
individ_vehicles <- read.csv(paste0(data_folder, "NGSIM_Peachtree_Vehicle_Trajectories.csv"))
#so cut out a segment of time
#then subset by any cars that went through the section being studied
#select time segment
#5 mins is 300 seconds
time_segment_start = as.integer(min(individ_vehicles$Global_Time))
time_segment_end = time_segment_start + 300000
section_number = 5
lag_number = 5
#time selected now subset dataframe
individ_vehicles_sub <- individ_vehicles %>%
group_by(Vehicle_ID) %>%
arrange(Global_Time) %>%
filter(Global_Time >= time_segment_start &
Global_Time <= time_segment_end |
lag(Global_Time, n = lag_number) <= time_segment_end &
lag(Global_Time, n = lag_number) >= time_segment_start |
lead(Global_Time, n = lag_number) <= time_segment_end &
lead(Global_Time, n = lag_number) >= time_segment_start,
Section_ID == section_number |
lag(Section_ID == section_number, n = lag_number) |
lead(Section_ID == section_number, n = lag_number))
#now test out the subset to see what's in it
length(unique(individ_vehicles_sub$Vehicle_ID))
#now find out the changing points of the section
#get every first and last coordinate of a car within the segment
first_and_last <- individ_vehicles_sub %>%
mutate(first_entry = if_else((Section_ID != lag(Section_ID))
& Section_ID == 5,
1,
0),
last_exit = if_else((Section_ID != lead(Section_ID))
& Section_ID == 5,
1,
0)) %>%
filter(first_entry == 1 | last_exit == 1,
Direction = )