It seems that quite a lot of terrestrial sampling units in MHQ are not represented in the mhq_terr_popunits data source. Maybe I'm doing something wrong, maybe something is out of date.
> mhq_terr_datapath <- file.path(dirname(gitroot), "n2khab-sample-admin/data/mhq_terr/rapportage2025")
> mhq_terr_popunits_grts <-
read_vc("mhq_terr_popunits", root = mhq_terr_datapath) %>%
as_tibble()
>
> # mhq_samples_textdatapath <- "/substitute/with/correct/filepath"
> mhq_samples_heath_haymeadow <-
read_csv_mhq_samples(
file.path(mhq_samples_textdatapath, "mhq_terr_cyclus2_anb.csv")
)
> mhq_samples_mire_grassland <-
read_csv_mhq_samples(
file.path(mhq_samples_textdatapath, "mhq_terr_cyclus2_inbo.csv")
)
> mhq_samples_dunes <-
read_csv_mhq_samples(file.path(
mhq_samples_textdatapath,
"mhq_terr_cyclus2_duinen_inbo_2023-05-11.csv"
))
> mhq_samples_forest <-
read_csv_mhq_samples(
file.path(mhq_samples_textdatapath, "mhq_forests_cycle1.csv"),
grts_var = "grts_ranking"
)
> mhq_terr_samples_grts <-
bind_rows(
mhq_samples_heath_haymeadow,
mhq_samples_mire_grassland,
mhq_samples_dunes,
mhq_samples_forest,
) %>%
# reset some peculiarities in read_csv_mhq_samples()
rename(type = stratum, grts_ranking_draw = grts_address) %>%
arrange(type, grts_ranking_draw)
>
> # number of terrestrial MHQ sampling units
> nrow(mhq_terr_samples_grts)
[1] 1657
>
> # data in terrestrial MHQ samples but missing from mhq_terr_popunits_grts
>
> mhq_terr_samples_grts %>%
anti_join(mhq_terr_popunits_grts, join_by(type, grts_ranking_draw)) %>%
nrow()
[1] 380
>
> mhq_terr_samples_grts %>%
anti_join(mhq_terr_popunits_grts, join_by(type, grts_ranking_draw)) %>%
count(type, sort = TRUE) %>%
print(n = Inf)
# A tibble: 32 × 2
type n
<fct> <int>
1 91E0_vo 40
2 6510_hu 39
3 2330_bu 33
4 2310 31
5 2330_dw 22
6 91E0_va 21
7 91E0_vc 20
8 2170 19
9 91E0_vn 19
10 91E0_vm 16
11 6410_mo 15
12 4030 14
13 6230_hn 10
14 6510_hus 10
15 2190_overig 8
16 4010 8
17 1330_hpr 7
18 7140_meso 7
19 2130_had 5
20 2330 4
21 6230_ha 4
22 6510_hua 4
23 6510_huk 4
24 9160 4
25 2130_hd 3
26 2190_mp 3
27 9130_end 3
28 6230_hmo 2
29 7140_oli 2
30 2120 1
31 6410_ve 1
32 9130_fm 1
Definition of function read_csv_mhq_samples() (which is also set up to cater for aquatic data sources)
#' Read and tidy csv file with MHQ samples
#'
#' @param path File path.
#' @param grts_var Column name to be used as GRTS address.
#' @param single_type Optional string to set a single type that represents all
#' rows.
read_csv_mhq_samples <- function(path,
grts_var = "grts_ranking_draw",
single_type = NULL) {
(
if (is.null(single_type)) {
read_delim(
file = path,
delim = ";",
col_types = cols_only(
{{ grts_var }} := col_integer(),
habitattype = col_character()
)
) %>%
select(
stratum = habitattype,
grts_address = {{ grts_var }}
)
} else {
read_delim(
file = path,
delim = ";",
col_types = cols_only(
{{ grts_var }} := col_integer()
)
) %>%
mutate(stratum = single_type) %>%
select(
stratum,
grts_address = {{ grts_var }}
)
}
) %>%
mutate(
# shortcut a complication for forests, where > 1 type is sometimes noted
stratum = str_extract(stratum, "^\\w+(\\+$)?"),
stratum = parse_factor(stratum, levels = levels(n2khab_strata$stratum))
) %>%
arrange(stratum, grts_address)
It seems that quite a lot of terrestrial sampling units in MHQ are not represented in the
mhq_terr_popunitsdata source. Maybe I'm doing something wrong, maybe something is out of date.Definition of function
read_csv_mhq_samples()(which is also set up to cater for aquatic data sources)