6 Apply processing to all PPIs

We have so far explained the processing ‘pipeline’ for the PPIs for Herwijnen and Den Helder radars, but have only applied this to a single moment in time, a single volume scan. Now we will apply the processing to all other available PPIs by simply copying over the annotations in case we ever need to repeat the analysis for other scans.

We have so far done the following:

  1. Pre-processed the radar data, by removing clutter and applying the range-bias correction (Kranstauber et al. 2020).
  2. Annotated the PPIs with land use class proportions, distance to inhabited areas and human population.
  3. Annotated the PPIs with corresponding count locations for the Sovon data.
  4. Connected the Sovon count data with life-history characteristics for the species contained within and calculated bird biomass.

6.1 Processing environment

6.2 Load the reference PPIs

Two PPIs have been processed all the way and those will be our ‘reference’ PPIs from which we copy the data over to the other PPIs which have not had the same treatment.

ppi_hrw <- readRDS("data/processed/corrected-ppis-lu-sovon/corrected_ppi_hrw_lu_sovon.RDS")
ppi_dhl <- readRDS("data/processed/corrected-ppis-lu-sovon/corrected_ppi_dhl_lu_sovon.RDS")

6.3 Add biomass and cross-sections to reference PPIs

We have previously calculated the total_biomass already for all the count areas/routes, but now we will annotate the reference PPIs with these values as well. We correct for the size of an area the count is conducted in by ‘spreading’ the total biomass over the number of pixels annotated with a certain count area/route.

wb <- readRDS("data/processed/sovon/wb_biomass.RDS")
ptt <- readRDS("data/processed/sovon/ptt_biomass.RDS")

ppi_hrw$data@data %<>%
  left_join(dplyr::select(wb, area_nr, total_biomass, weighted_mean_weight, total_crs, weighted_mean_crs, total_birds), by = c("wb_area_nr" = "area_nr")) %>%
  rename(wb_total_biomass = total_biomass,
         wb_total_crs = total_crs,
         wb_weighted_mean_weight = weighted_mean_weight,
         wb_weighted_mean_crs = weighted_mean_crs,
         wb_total_birds = total_birds) %>%
  group_by(wb_area_nr) %>%
  mutate(wb_total_biomass = wb_total_biomass / n(),
         wb_total_crs = wb_total_crs / n(),
         wb_total_birds = wb_total_birds / n()) %>%  
  ungroup() %>%
  left_join(dplyr::select(ptt, route, total_biomass, weighted_mean_weight, total_crs, weighted_mean_crs, total_birds), by = c("ptt_route" = "route")) %>%
  rename(ptt_total_biomass = total_biomass,
         ptt_total_crs = total_crs,
         ptt_weighted_mean_weight = weighted_mean_weight,
         ptt_weighted_mean_crs = weighted_mean_crs,
         ptt_total_birds = total_birds) %>%
  group_by(ptt_route) %>%
  mutate(ptt_total_biomass = ptt_total_biomass / n(),
         ptt_total_crs = ptt_total_crs / n(),
         ptt_total_birds = ptt_total_birds / n()) %>% 
  ungroup() %>%
  rowwise() %>%
  mutate(total_biomass = sum(wb_total_biomass, ptt_total_biomass, na.rm = TRUE),
         total_crs = sum(wb_total_crs, ptt_total_crs, na.rm = TRUE),
         weighted_mean_weight = mean(c(wb_weighted_mean_weight, ptt_weighted_mean_weight), na.rm = TRUE),
         weighted_mean_crs = mean(c(wb_weighted_mean_crs, ptt_weighted_mean_crs), na.rm = TRUE),
         total_birds = round(sum(wb_total_birds, ptt_total_birds, na.rm = TRUE))) %>%
  ungroup()
## Loading required package: sp
ppi_dhl$data@data %<>%
  left_join(dplyr::select(wb, area_nr, total_biomass, weighted_mean_weight, total_crs, weighted_mean_crs, total_birds), by = c("wb_area_nr" = "area_nr")) %>%
  rename(wb_total_biomass = total_biomass,
         wb_total_crs = total_crs,
         wb_weighted_mean_weight = weighted_mean_weight,
         wb_weighted_mean_crs = weighted_mean_crs,
         wb_total_birds = total_birds) %>%
  group_by(wb_area_nr) %>%
  mutate(wb_total_biomass = wb_total_biomass / n(),
         wb_total_crs = wb_total_crs / n(),
         wb_total_birds = wb_total_birds / n()) %>%
  ungroup() %>%
  left_join(dplyr::select(ptt, route, total_biomass, weighted_mean_weight, total_crs, weighted_mean_crs, total_birds), by = c("ptt_route" = "route")) %>%
  rename(ptt_total_biomass = total_biomass,
         ptt_total_crs = total_crs,
         ptt_weighted_mean_weight = weighted_mean_weight,
         ptt_weighted_mean_crs = weighted_mean_crs,
         ptt_total_birds = total_birds) %>%
  group_by(ptt_route) %>%
  mutate(ptt_total_biomass = ptt_total_biomass / n(),
         ptt_total_crs = ptt_total_crs / n(),
         ptt_total_birds = ptt_total_birds / n()) %>%
  ungroup() %>%
  rowwise() %>%
  mutate(total_biomass = sum(wb_total_biomass, ptt_total_biomass, na.rm = TRUE),
         total_crs = sum(wb_total_crs, ptt_total_crs, na.rm = TRUE),
         weighted_mean_weight = mean(c(wb_weighted_mean_weight, ptt_weighted_mean_weight), na.rm = TRUE),
         weighted_mean_crs = mean(c(wb_weighted_mean_crs, ptt_weighted_mean_crs), na.rm = TRUE),
         total_birds = round(sum(wb_total_birds, ptt_total_birds, na.rm = TRUE))) %>%
  ungroup()

6.4 Copy annotations from reference PPIs to other PPIs

We select the variables related to land use, distance to inhabited areas and population density, waterbird counts and PTT counts and add these to the PPIs that contain just the variables resulting from the range-bias correction (Kranstauber et al. 2020).

columns <- c("urban", "agricultural", "semiopen", "forests", "wetlands", "waterbodies", "land",
             "dist_urban", "human_pop", "wb_area_id", "wb_area_nr", "ptt_route",
             "wb_area_id", "wb_area_nr", "wb_area_ha", "ptt_route", "wb_total_biomass", "ptt_total_biomass", "total_biomass", 
             "wb_weighted_mean_weight", "ptt_weighted_mean_weight", "weighted_mean_weight", 
             "wb_total_crs", "ptt_total_crs", "total_crs", "wb_weighted_mean_crs", "ptt_weighted_mean_crs", "weighted_mean_crs",
             "wb_total_birds", "ptt_total_birds", "total_birds")

hrw <- ppi_hrw$data@data %>%
  dplyr::select(all_of(columns))

dhl <- ppi_dhl$data@data %>%
  dplyr::select(all_of(columns))

hrw_all <- ppi_hrw$data@data %>%
  filter(row_number() == 0)

dhl_all <- ppi_dhl$data@data %>%
  filter(row_number() == 0)

hrw_ppis <- Sys.glob(file.path("data/processed/corrected-ppis", "*NL62*"))
dhl_ppis <- Sys.glob(file.path("data/processed/corrected-ppis", "*NL61*"))

for (ppi_path in hrw_ppis) {
  ppi <- readRDS(ppi_path)
  ppi$data@data <- bind_cols(ppi$data@data, hrw)
  saveRDS(ppi, file = paste("data/processed/final-ppis/", basename(ppi_path), sep = ""))
}

for (ppi_path in dhl_ppis) {
  ppi <- readRDS(ppi_path)
  ppi$data@data <- bind_cols(ppi$data@data, dhl)
  saveRDS(ppi, file = paste("data/processed/final-ppis/", basename(ppi_path), sep = ""))
}

hrw_ppis <- Sys.glob(file.path("data/processed/baseline-ppis", "NLHRW*"))
dhl_ppis <- Sys.glob(file.path("data/processed/baseline-ppis", "NLDHL*"))

for (ppi_path in hrw_ppis) {
  ppi <- readRDS(ppi_path)
  ppi$data@data <- bind_cols(ppi$data@data, hrw)
  saveRDS(ppi, file = paste("data/processed/final-ppis-baseline/", basename(ppi_path), sep = ""))
}

for (ppi_path in dhl_ppis) {
  ppi <- readRDS(ppi_path)
  ppi$data@data <- bind_cols(ppi$data@data, dhl)
  saveRDS(ppi, file = paste("data/processed/final-ppis-baseline/", basename(ppi_path), sep = ""))
}