Skip to content

Commit 5d5b9c4

Browse files
authored
Merge pull request #131 from Rafnuss/dev
v3.4.0
2 parents b1b731f + 0643122 commit 5d5b9c4

27 files changed

+93
-56
lines changed

.github/workflows/lint.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches: [main, master]
66
pull_request:
7-
branches: [main, master]
87

98
name: lint.yaml
109

@@ -24,7 +23,7 @@ jobs:
2423

2524
- uses: r-lib/actions/setup-r-dependencies@v2
2625
with:
27-
extra-packages: any::lintr, local::.
26+
extra-packages: any::lintr, any::cyclocomp, local::.
2827
needs: lint
2928

3029
- name: Lint

CITATION.cff

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ message: 'To cite package "GeoPressureR" in publications use:'
88
type: software
99
license: GPL-3.0-or-later
1010
title: 'GeoPressureR: Global Positioning by Atmospheric Pressure'
11-
version: 3.3.4
11+
version: 3.4.0
1212
doi: 10.5281/zenodo.7754457
1313
abstract: R package to determine the position and trajectory of a bird based on light-weight
1414
data-logger measuring at lease atmospheric pressure.
@@ -143,7 +143,7 @@ references:
143143
authors:
144144
- family-names: Csárdi
145145
given-names: Gábor
146-
email: csardi.gabor@gmail.com
146+
email: gabor@posit.co
147147
year: '2025'
148148
doi: 10.32614/CRAN.package.cli
149149
- type: software
@@ -354,7 +354,7 @@ references:
354354
title: Matrix
355355
abstract: 'Matrix: Sparse and Dense Matrix Classes and Methods'
356356
notes: Imports
357-
url: https://R-forge.R-project.org/tracker/?atid=294&group_id=61
357+
url: https://Matrix.R-forge.R-project.org
358358
repository: https://CRAN.R-project.org/package=Matrix
359359
authors:
360360
- family-names: Bates

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: GeoPressureR
22
Title: Global Positioning by Atmospheric Pressure
3-
Version: 3.3.4
3+
Version: 3.4.0
44
Authors@R: c(
55
person("Raphaël", "Nussbaumer", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-8185-1020")),

R/geopressure_map_preprocess.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ geopressure_map_preprocess <- function(tag, compute_known = FALSE) {
188188

189189
assertthat::assert_that(all(!is.na(pgi_reg$value)))
190190

191-
return(pgi_reg)
191+
pgi_reg
192192
})
193193

194194
# Combine into a single data.frame

R/geopressuretemplate_graph.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ geopressuretemplate_graph <- function(
8585
"i" = "Error while defining the movement model.{.var graph} is return.",
8686
">" = "Debug line by line by opening {.code edit(geopressuretemplate_graph)}"
8787
))
88-
return(graph)
88+
graph
8989
}
9090
)
9191

@@ -137,7 +137,7 @@ geopressuretemplate_graph <- function(
137137
"x" = "Error while computing the outputs. {.var graph} is returned.",
138138
">" = "Debug line by line by opening {.code edit(geopressuretemplate_graph)}"
139139
))
140-
return(graph)
140+
graph
141141
}
142142
)
143143

R/graph_add_wind.R

+21
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,31 @@ graph_add_wind <- function(
7070
))
7171
}
7272

73+
# Filter node
7374
graph$s <- graph$s[id]
7475
graph$t <- graph$t[id]
7576
graph$gs <- graph$gs[id]
7677
graph$ws <- graph$ws[id]
78+
79+
# Prune the graph
80+
# First, reconstruction the stap list graph for graph_create_prune to work
81+
gr <- split(
82+
data.frame(s = graph$s, t = graph$t, gs = graph$gs, ws = graph$ws),
83+
arrayInd(graph$s, graph$sz)[, 3]
84+
)
85+
gr <- graph_create_prune(gr)
86+
# Convert it back to a full list
87+
tmp <- as.list(do.call("rbind", gr))
88+
# Overwrite all edges vectors
89+
graph$s <- tmp$s
90+
graph$t <- tmp$t
91+
graph$gs <- tmp$gs
92+
graph$ws <- tmp$ws
93+
94+
# After pruning some retrieval nodes might not be present anymore.
95+
graph$retrieval <- graph$retrieval[graph$retrieval %in% graph$t]
96+
97+
# Update param
7798
graph$param$graph_add_wind$thr_as <- thr_as
7899
attr(file, "srcref") <- NULL
79100
attr(file, "srcfile") <- NULL

R/graph_assert.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ graph_status <- function(graph) {
5151
if (length(graph$s) > 0) {
5252
status <- append(status, "full")
5353
}
54-
return(status)
54+
status
5555
}

R/graph_create.R

+8-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ graph_create <- function(tag,
175175
thr_prob <- ls[id_prob_percentile + 1]
176176

177177
# return matrix if the values are above the threshold
178-
return(l >= thr_prob)
178+
l >= thr_prob
179179
})
180180

181181
# Check that there are still values
@@ -361,6 +361,8 @@ graph_create <- function(tag,
361361
graph$stap <- tag$stap
362362
graph$equipment <- which(nds[[1]] == TRUE)
363363
graph$retrieval <- as.integer(which(nds[[sz[3]]] == TRUE) + (sz[3] - 1) * nll)
364+
# After pruning some retrieval nodes might not be present anymore.
365+
graph$retrieval <- graph$retrieval[graph$retrieval %in% graph$t]
364366
graph$mask_water <- tag$map_pressure$mask_water
365367

366368
# Create the param from tag
@@ -371,6 +373,11 @@ graph_create <- function(tag,
371373
likelihood = likelihood
372374
)
373375

376+
# Check graph validity
377+
assertthat::assert_that(all(graph$s[!(graph$s %in% graph$equipment)] %in% graph$t))
378+
assertthat::assert_that(all(graph$equipment %in% graph$s))
379+
assertthat::assert_that(all(graph$retrieval %in% graph$t))
380+
374381
return(graph)
375382
}
376383

R/graph_most_likely.R

+16-11
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,26 @@ graph_most_likely <- function(graph, quiet = FALSE) {
5858
# number of nodes in the 3d grid
5959
n <- prod(graph$sz)
6060

61-
# Compute the matrix TO
61+
# Compute the matrix TO (transition * observation)
6262
if (!quiet) {
6363
cli::cli_progress_step("Compute movement model")
6464
}
6565
trans_obs <- graph_transition(graph) * graph$obs[graph$t]
6666

67-
# Initiate the matrix providing for each node of the graph, the source id (index of the node)
68-
# with the most likely path to get there.
67+
# Initiate the sparse 1D matrix providing for each node of the graph, the source id (index of the
68+
# node in the 3D grid) with the cumulative max probability to get there.
69+
# Start with prob=1 at the equipment site (log = 0)
6970
path_s <- Matrix::sparseMatrix(
7071
rep(1, length(graph$equipment)),
7172
graph$equipment,
72-
x = 1, dims = c(1, n)
73+
x = 0, dims = c(1, n)
7374
)
74-
# Initiate the same matrix providing the total probability of the current path so far
75+
# Initiate the same matrix providing the cumulative total probability of the current path so far
76+
# Not sure why x is differently specify, should be the same value for both path_s and path_max
7577
path_max <- Matrix::sparseMatrix(
7678
rep(1, length(graph$equipment)),
7779
graph$equipment,
78-
x = graph$obs[graph$equipment], dims = c(1, n)
80+
x = log(graph$obs[graph$equipment]), dims = c(1, n)
7981
)
8082

8183
# Create a data.frame of all edges information
@@ -85,13 +87,14 @@ graph_most_likely <- function(graph, quiet = FALSE) {
8587
node <- data.frame(
8688
s = graph$s,
8789
t = graph$t,
88-
to = trans_obs,
90+
to = log(trans_obs),
8991
stap = arrayInd(graph$s, graph$sz)[, 3]
9092
)
9193

92-
# Split this data.fram by stationary period (of the source)
94+
# Split this data.frame by stationary period (of the source)
9395
node_stap <- split(node, node$stap)
9496

97+
# Compute number of nodes per stap
9598
n_edge <- sapply(node_stap, nrow)
9699

97100
if (!quiet) {
@@ -109,12 +112,14 @@ graph_most_likely <- function(graph, quiet = FALSE) {
109112
}
110113

111114
for (i_s in seq_len(length(node_stap))) {
115+
# Select all nodes of the current stap
112116
node_i_s <- node_stap[[i_s]]
113117

114-
# compute the probability of all possible transition
115-
node_i_s$p <- path_max[node_i_s$s] * node_i_s$to
118+
# Compute the (cum) log probability of all possible transitions
119+
node_i_s$p <- path_max[node_i_s$s] + node_i_s$to
116120

117-
# Find the value of the maximum possible transition for each target node
121+
# Find the value of the maximum possible transition for each target node and store it into
122+
# path_max
118123
max_v <- sapply(split(node_i_s$p, node_i_s$t), max)
119124
max_t <- as.numeric(names(max_v))
120125
path_max[max_t] <- max_v

R/graph_transition.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ graph_transition <- function(graph) {
4343
))
4444
}
4545

46-
return(transition)
46+
transition
4747
}

R/light2mat.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ light2mat <- function(light, twl_offset = 0) {
5858

5959
if (length(candidates) > 0) {
6060
closest_idx <- candidates[which.min(abs(light_date_num[candidates] - t))]
61-
return(light_value[closest_idx])
61+
light_value[closest_idx]
6262
} else {
63-
return(NA)
63+
NA
6464
}
6565
}
6666

R/map_create.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ dim.map <- function(x) {
139139
# Compute value
140140
z$data <- mapply(\(p, l) {
141141
if (is.null(p) && is.null(l)) {
142-
return(NULL)
142+
NULL
143143
} else if (is.null(p)) {
144-
return(l)
144+
l
145145
} else if (is.null(l)) {
146-
return(p)
146+
p
147147
} else {
148-
return(p * l)
148+
p * l
149149
}
150150
}, x$data, y$data, SIMPLIFY = FALSE)
151151

@@ -157,5 +157,5 @@ dim.map <- function(x) {
157157

158158
z$type <- glue::glue("{x$type} x {y$type}")
159159

160-
return(z)
160+
z
161161
}

R/map_expand.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ map_expand <- function(extent, scale) {
7777
lon = lon,
7878
dim = dim
7979
)
80-
return(grid)
80+
grid
8181
}

R/path2edge.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,5 @@ path2edge <- function(path, tag_graph) {
129129

130130
attr(edge, "type") <- attr(path, "type")
131131

132-
return(edge)
132+
edge
133133
}

R/plot.map.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ plot.map <- function(x,
8585
# Set to NA all value below this threshold
8686
m[m < thr_prob] <- NA
8787
}
88-
return(m)
88+
m
8989
})
9090

9191
# Convert GeoPressureR map to terra rast object

R/pressurepath_create.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ pressurepath_create <- function(tag,
235235
# convert here as a NA
236236
out <- as.data.frame(lapply(resp_data, function(col) {
237237
if (length(col) == 0) {
238-
return(NA)
238+
NA
239239
} else {
240-
return(col)
240+
col
241241
}
242242
}))
243243

R/print.bird.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ print.bird <- function(x, ...) {
2424
"*" = "Wing span: {round(bird$wing_span,1)} (m).",
2525
"*" = "Wing aspect: {round(bird$wing_aspect,1)} (-)."
2626
))
27-
return(invisible(bird))
27+
invisible(bird)
2828
}

R/print.graph.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ print.graph <- function(x, ...) {
8282
cli::cli_bullets(c("x" = "No movement model defined. Use {.fun graph_set_movement}"))
8383
}
8484

85-
return(invisible(graph))
85+
invisible(graph)
8686
}

R/print.map.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ print.map <- function(x, ...) {
4343
cli::cli_h3("Stationary periods {.field stap} (n={.val {nrow(map$stap)}})")
4444
cli::cli_text("Run {.code map$stap} to display full table")
4545

46-
return(invisible(x))
46+
invisible(x)
4747
}

R/print.param.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ print.param <- function(x, ...) {
9696
bullets(param$geopressuretemplate, "pressurepath")
9797
}
9898

99-
return(invisible(param))
99+
invisible(param)
100100
}
101101

102102
bullets <- function(param, x) {

R/print.tag.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,5 @@ print.tag <- function(x, ...) {
137137
}
138138
}
139139
}
140-
return(invisible(tag))
140+
invisible(tag)
141141
}

R/speed2prob.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ speed2prob <- function(speed, movement) {
7979

8080
prob[speed_0] <- prob[speed_0] * movement$zero_speed_ratio
8181

82-
return(prob)
82+
prob
8383
}
8484

8585

@@ -136,5 +136,5 @@ speed2power <- function(as, bird) {
136136
# Total Mechanical Power (eq 1 of Box 3.4)
137137
p_mech <- p_ind + p_par + p_pro
138138

139-
return(p_mech)
139+
p_mech
140140
}

R/tag_assert.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,5 @@ tag_status <- function(tag) {
151151
status <- append(status, "map_light")
152152
}
153153

154-
return(status)
154+
status
155155
}

R/tag_create.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1016,5 +1016,5 @@ tag_create_crop <- function(tag,
10161016
}
10171017
}
10181018
}
1019-
return(tag)
1019+
tag
10201020
}

R/tag_label_stap.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pretty_dt <- function(tim) {
185185
}
186186

187187
# Trim and return
188-
return(trimws(duration_str))
188+
trimws(duration_str)
189189
}
190190

191191
#' Find the stationary period corresponding to a date
@@ -213,5 +213,5 @@ find_stap <- function(stap, date) {
213213

214214
assertthat::assert_that(all(!is.na(stap_id)))
215215

216-
return(stap_id)
216+
stap_id
217217
}

0 commit comments

Comments
 (0)