@@ -62,12 +62,12 @@ validate_BirdFlow <- function(x, error = TRUE, allow_incomplete = FALSE) {
62
62
if (error ) {
63
63
if (allow_incomplete ) {
64
64
if (any(p $ type == " error" ))
65
- message <- paste0(" Problems found by validate_BirdFlow:" ,
65
+ message <- paste0(" Problems found by validate_BirdFlow:\n\t " ,
66
66
paste(p $ problem [p $ type == " error" ],
67
- collapse = " ; " ))
67
+ collapse = " ;\n\t " ))
68
68
} else { # Don't allow incomplete:
69
69
if (nrow(p ) > 0 )
70
- message <- paste (" Problems found by validate_BirdFlow:\n\t " ,
70
+ message <- paste0 (" Problems found by validate_BirdFlow:\n\t " ,
71
71
paste(p $ problem , collapse = " ; \n\t " ))
72
72
}
73
73
}
@@ -136,6 +136,48 @@ validate_BirdFlow <- function(x, error = TRUE, allow_incomplete = FALSE) {
136
136
}
137
137
138
138
139
+
140
+
141
+ # check dates
142
+ if (! " dates" %in% names(x ) || ! is.data.frame(x $ dates )) {
143
+ p <- add_prob(" x$dates is missing, NA or not a dataframe" , " error" , p )
144
+ report_problems()
145
+ } else { # dates exists and is data.frame
146
+
147
+ if (x $ metadata $ ebird_version_year < 2022 ) {
148
+ # 2021 ebirdst models have use older dates format
149
+ required_cols <- c(" interval" , " date" , " doy" , " start" , " midpoint" , " end" )
150
+ } else {
151
+ # 2022_ ebirdst models use newer dates format
152
+ required_cols <- names(make_dates())
153
+ }
154
+ if (! all(required_cols %in% names(x $ dates ))) {
155
+ p <- add_prob(paste0(" x$dates is missing columns:" ,
156
+ paste(setdiff(required_cols , names(x $ dates )))),
157
+ " error" , p )
158
+ report_problems()
159
+ } # end if dates missing columns
160
+ rm(required_cols )
161
+
162
+
163
+ if (" distr" %in% names(x )) {
164
+ if (is.null(dim(x $ distr )) ||
165
+ ! length(dim(x $ distr )) == 2 ||
166
+ ! is.numeric(x $ distr )) {
167
+ p <- add_prob(" distr has wrong format" , " error" , p )
168
+ report_problems()
169
+ }
170
+
171
+ if (nrow(x $ dates ) != ncol(x $ distr )) {
172
+ p <- add_prob(paste0(" x$dates and x$distr do not represent the same " ,
173
+ " number of timesteps." ), " error" , p )
174
+ report_problems()
175
+ }
176
+ }
177
+ } # end dates is data.frame
178
+
179
+
180
+
139
181
# check consistancy of has_ (transitions, marginals, distr)
140
182
components <- c(" transitions" , " marginals" , " distr" )
141
183
for (i in seq_along(components )) {
@@ -144,13 +186,26 @@ validate_BirdFlow <- function(x, error = TRUE, allow_incomplete = FALSE) {
144
186
p <- add_prob(paste0(" has_" , components [i ], " is not TRUE or FALSE" ),
145
187
" error" , p )
146
188
}
189
+
147
190
if (has_distr(x )) {
148
191
if (! is.matrix(x $ distr ))
149
192
p <- add_prob(" distr is not a matrix" , " error" , p )
193
+ sums_to_one <- get_distr(x ) | >
194
+ apply(2 , sum ) | >
195
+ sapply(function (x ) isTRUE(all.equal(x , 1 )))
196
+ if (! all(sums_to_one )){
197
+ p <- add_prob(" not all distributions sum to one" ,
198
+ " error" , p )
199
+ }
150
200
}
151
201
if (has_dynamic_mask(x )) {
152
- if (! is.matrix(x $ geom $ dynamic_mask ))
202
+ if (! is.matrix(x $ geom $ dynamic_mask )){
153
203
p <- add_prob(" dynamic mask is not a matrix" , " error" , p )
204
+ } else {
205
+ if (! all(apply(get_dynamic_mask(x ), 2 , sum ) > 0 )){
206
+ p <- add_prob(" dynamic mask eliminates all cells for some timesteps" , " error" , p )
207
+ }
208
+ }
154
209
}
155
210
156
211
if (has_marginals(x )) {
@@ -203,44 +258,6 @@ validate_BirdFlow <- function(x, error = TRUE, allow_incomplete = FALSE) {
203
258
204
259
205
260
206
- # check dates
207
- if (! " dates" %in% names(x ) || ! is.data.frame(x $ dates )) {
208
- p <- add_prob(" x$dates is missing, NA or not a dataframe" , " error" , p )
209
- report_problems()
210
- } else { # dates exists and is data.frame
211
-
212
- if (x $ metadata $ ebird_version_year < 2022 ) {
213
- # 2021 ebirdst models have use older dates format
214
- required_cols <- c(" interval" , " date" , " doy" , " start" , " midpoint" , " end" )
215
- } else {
216
- # 2022_ ebirdst models use newer dates format
217
- required_cols <- names(make_dates())
218
- }
219
- if (! all(required_cols %in% names(x $ dates ))) {
220
- p <- add_prob(paste0(" x$dates is missing columns:" ,
221
- paste(setdiff(required_cols , names(x $ dates )))),
222
- " error" , p )
223
- report_problems()
224
- } # end if dates missing columns
225
- rm(required_cols )
226
-
227
-
228
- if (" distr" %in% names(x )) {
229
- if (is.null(dim(x $ distr )) ||
230
- ! length(dim(x $ distr )) == 2 ||
231
- ! is.numeric(x $ distr )) {
232
- p <- add_prob(" distr has wrong format" , " error" , p )
233
- report_problems()
234
- }
235
-
236
- if (nrow(x $ dates ) != ncol(x $ distr )) {
237
- p <- add_prob(paste0(" x$dates and x$distr do not represent the same " ,
238
- " number of timesteps." ), " error" , p )
239
- }
240
- }
241
- } # end dates is data.frame
242
-
243
-
244
261
# consistency on n_active
245
262
if (is.na(n_active(x ))) {
246
263
if (has_transitions(x ) || has_marginals(x ) || has_distr(x ) ||
0 commit comments