Skip to content

Commit 2643c48

Browse files
committed
Fix bugs on index of stap with/out include and variable
1 parent 7da20b4 commit 2643c48

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

R/edge_add_wind.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ edge_add_wind <- function(
106106

107107
# Convert consecutive stationary periods into one or several flight segments.
108108
flight <- stap2flight(graph$stap, format = "list")
109+
stap_include <- if ("include" %in% names(graph$stap)) {
110+
graph$stap$stap_id[graph$stap$include]
111+
} else {
112+
graph$stap$stap_id
113+
}
109114

110115
# Convert edge ids to array indices and group edges by source stationary period.
111116
edge_info <- edge_add_wind_prepare_edges(edge_s, edge_t, g, graph$stap)
@@ -142,11 +147,13 @@ edge_add_wind <- function(
142147
# Extract the flight information from the current stap to the next one considered in the graph.
143148
# It can be the next, or if some stap are skipped at construction, it can contains multiples
144149
# flights
145-
stap_id <- edge_stap[i_stap]
146-
fl_s <- flight[[stap_id]]
150+
# Graph layers are compressed to included staps; flight names use original stap_id.
151+
stap_layer <- as.integer(edge_stap[i_stap])
152+
stap_id <- stap_include[stap_layer]
153+
fl_s <- flight[[as.character(stap_id)]]
147154

148155
# Determine the id of edges of the graph corresponding to this/these flight(s).
149-
st_id <- list_st_id[[stap_id]]
156+
st_id <- list_st_id[[edge_stap[i_stap]]]
150157
if (length(st_id) == 0) {
151158
next
152159
}

R/graph_add_wind.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ add_wind_graph_edge <- function(
183183
}
184184
g <- map_expand(graph$param$tag_set_map$extent, graph$param$tag_set_map$scale)
185185
flight <- stap2flight(graph$stap, format = "list")
186+
stap_include <- if ("include" %in% names(graph$stap)) {
187+
graph$stap$stap_id[graph$stap$include]
188+
} else {
189+
graph$stap$stap_id
190+
}
186191
n_grid <- prod(g$dim)
187192
edge_s0 <- graph$s - 1
188193
edge_t0 <- graph$t - 1
@@ -220,9 +225,11 @@ add_wind_graph_edge <- function(
220225
n_edge_done <- 0L
221226
for (i_stap in seq_along(edge_stap)) {
222227
# Work on one source stationary period at a time so the output can be written into ws[st_id].
223-
stap_id <- edge_stap[i_stap]
224-
fl_s <- flight[[stap_id]]
225-
st_id <- list_st_id[[stap_id]]
228+
# Graph layers are compressed to included staps; flight names use original stap_id.
229+
stap_layer <- as.integer(edge_stap[i_stap])
230+
stap_id <- stap_include[stap_layer]
231+
fl_s <- flight[[as.character(stap_id)]]
232+
st_id <- list_st_id[[edge_stap[i_stap]]]
226233
if (length(st_id) == 0) {
227234
next
228235
}

R/param_create.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ param_create <- function(id, default = FALSE, ...) {
104104
graph_add_wind = list(
105105
thr_as = formals(graph_add_wind)$thr_as,
106106
file = formals(edge_add_wind)$file,
107-
variable = formals(edge_add_wind)$variable,
108107
rounding_interval = formals(edge_add_wind)$rounding_interval,
109108
interp_spatial_linear = formals(edge_add_wind)$interp_spatial_linear
110109
),

0 commit comments

Comments
 (0)