Skip to content

Commit

Permalink
Update interpretation of country data
Browse files Browse the repository at this point in the history
  • Loading branch information
wkmor1 committed Sep 26, 2024
1 parent 9631a38 commit 7c73672
Show file tree
Hide file tree
Showing 9 changed files with 1,502 additions and 1,428 deletions.
64 changes: 62 additions & 2 deletions R/finbif_occurrence.R
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ occurrence <- function(fb_records_obj) {

fb_occurrence_df <- compute_red_list_status(fb_occurrence_df)

fb_occurrence_df <- compute_country(fb_occurrence_df)

fb_occurrence_df <- compute_region(fb_occurrence_df)

fb_occurrence_df <- compute_codes(fb_occurrence_df)
Expand Down Expand Up @@ -919,7 +921,8 @@ compute_vars_from_id <- function(fb_occurrence_df) {
subcollections = TRUE,
supercollections = TRUE,
nmin = NA,
locale = locale
locale = locale,
cache = attr(fb_occurrence_df, "cache", TRUE)[[2L]]
)

} else {
Expand Down Expand Up @@ -1278,7 +1281,8 @@ compute_codes <- function(fb_occurrence_df) {
codes <- finbif_collections(
select = c("collection_code", "institution_code"),
supercollections = TRUE,
nmin = NA
nmin = NA,
cache = attr(fb_occurrence_df, "cache", TRUE)[[2L]]
)

id <- fb_occurrence_df[[id_var]]
Expand Down Expand Up @@ -1355,6 +1359,62 @@ compute_red_list_status <- function(fb_occurrence_df) {

#' @noRd

compute_country <- function(fb_occurrence_df) {

dwc <- attr(fb_occurrence_df, "dwc", TRUE)

col_names <- attr(fb_occurrence_df, "column_names", TRUE)

add <- attr(fb_occurrence_df, "include_new_cols", TRUE)

vtype <- col_type_string(dwc)

var_names <- sysdata(list(which = "var_names"))

id_var <- var_names[["gathering.interpretations.country", vtype]]

verbatim_var <- var_names[["gathering.country", vtype]]

vars <- c("computed_var_country_code", "computed_var_country")

for (i in seq_along(vars)) {

var_i <- vars[[i]]

var <- var_names[[var_i, vtype]]

if (add && var %in% col_names) {

countries <- finbif_metadata(
"country", cache = attr(fb_occurrence_df, "cache", TRUE)[[2L]]
)

id <- fb_occurrence_df[[id_var]]

id <- remove_domain(id)

fb_occurrence_df[[var]] <- countries[id, i]

if (i == 2L) {

fb_occurrence_df[[var]] <- ifelse(
is.na(fb_occurrence_df[[var]]),
fb_occurrence_df[[verbatim_var]],
fb_occurrence_df[[var]]
)

}

}

}

fb_occurrence_df

}

#' @noRd

compute_region <- function(fb_occurrence_df) {

dwc <- attr(fb_occurrence_df, "dwc", TRUE)
Expand Down
8 changes: 8 additions & 0 deletions R/finbif_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ infer_computed_vars <- function(fb_records_obj) {
collection_code = list(
vars = c("collection_code", "collectionCode"),
v_names = "document.collectionId"
),
country = list(
vars = "country",
v_names = c("gathering.interpretations.country", "gathering.country")
),
country_code = list(
vars = c("country_code", "countryCode"),
v_names = c("gathering.interpretations.country", "gathering.country")
)
)

Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
3 changes: 2 additions & 1 deletion data-raw/variables.csv
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ gathering.interpretations.biogeographicalProvince,bio_province_id,bioStateProvin
computed_var_from_id_bio_province,bio_province,bioStateProvince,FALSE,FALSE,character,character,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE
gathering.interpretations.biogeographicalProvinces,bio_province_ids,bioStateProvinceIDs,FALSE,FALSE,character,uri,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE
gathering.interpretations.country,country_id,countryID,FALSE,FALSE,character,uri,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE
computed_var_from_id_country,country,country,FALSE,FALSE,character,character,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE
computed_var_country,country,country,FALSE,FALSE,character,character,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE
computed_var_country_code,country_code,countryCode,FALSE,FALSE,character,character,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE
gathering.interpretations.finnishMunicipalities,municipality_ids,countyIDs,FALSE,FALSE,character,uri,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE
gathering.interpretations.finnishMunicipality,municipality_id,countyID,FALSE,FALSE,character,uri,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE
gathering.interpretations.municipalityDisplayname,municipality_interpreted,countyInterpreted,FALSE,FALSE,character,character,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE
Expand Down
980 changes: 491 additions & 489 deletions tests/fixtures/finbif_metadata.yml

Large diffs are not rendered by default.

1,804 changes: 904 additions & 900 deletions tests/fixtures/finbif_occurrence.yml

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions tests/testthat/_snaps/finbif_metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@
ML.37 BG Bulgaria
ML.38 BF Burkina Faso
ML.39 BI Burundi
ML.96 CV Cabo Verde
ML.93 KH Cambodia
ML.94 CM Cameroon
ML.95 CA Canada
ML.96 CV Cape Verde
ML.40 KY Cayman Islands
ML.99 CF Central African Republic
ML.221 TD Chad
Expand All @@ -308,7 +308,7 @@
ML.111 HR Croatia
ML.112 CU Cuba
ML.114 CY Cyprus
ML.222 CZ Czech Republic
ML.222 CZ Czechia
ML.248 <NA> Czechoslovakia
ML.158 CI Côte d'Ivoire
ML.215 DK Denmark
Expand Down Expand Up @@ -383,7 +383,6 @@
ML.122 LT Lithuania
ML.123 LU Luxembourg
ML.125 MO Macao
ML.127 MK Macedonia
ML.126 MG Madagascar
ML.128 MW Malawi
ML.130 MY Malaysia
Expand Down Expand Up @@ -417,6 +416,7 @@
ML.154 NG Nigeria
ML.155 NU Niue
ML.156 NF Norfolk Island
ML.127 MK North Macedonia
ML.168 MP Northern Mariana Islands
ML.157 NO Norway
ML.159 OM Oman
Expand Down Expand Up @@ -502,7 +502,6 @@
ML.249 <NA> Yugoslavia
ML.191 ZM Zambia
ML.246 ZW Zimbabwe
ML.1307 SS the Republic of South Sudan

---

Expand Down Expand Up @@ -541,22 +540,22 @@
ML.271 InL Inari Lapland
ML.264 Kn Kainuu
ML.268 KiL Kittilä Lapland
ML.267 <NA> Koillismaa
ML.258 LK Ladoga Karelia
ML.260 PH North Häme
ML.262 PK North Karelia
ML.261 PS North Savo
ML.265 OP Oulu Ostrobothnia
ML.266 PeP Outer Ostrobothnia
ML.267 Ks Regio kuusamoënsis
ML.255 St Satakunta
ML.269 SoL Sompio Lapland
ML.256 EH South Häme
ML.254 EK South Karelia
ML.259 EP South Ostrobothnia
ML.257 ES South Savo
ML.253 U Uusimaa
ML.252 V Varsinais-Suomi
ML.251 A Åland
ML.265 OP <NA>
ML.266 <NA> <NA>
ML.269 <NA> <NA>

---

Expand Down
Loading

0 comments on commit 7c73672

Please sign in to comment.