Last updated: 2022-10-24

Purpose

The purpose of this code is to convert the Cropland Data Layer (CDL) into estimated pesticide loading in units of kg/ha or honey bee LD50s. Starting from the master reclass tables, the reclasstables function filters to state-year combinations specified by the user and writes these individual reclass tables to a .csv file. Then the user can utilize the state-year reclass table to reclassify the appropriate CDL raster using the CDL_reclass function.

In this script we generate reclass tables and rasters for:

  1. Total insecticide loading (LD50, contact exposure)
  2. Total insecticide loading (LD50, oral exposure)
  3. Glyphosate application (kg/ha)
  4. Mefenoxam application (kg/ha)
  5. Imidacloprid application (kg/ha)
  6. Coverage of pesticide estimates - surveyed, unsurveyed, and non-crop land

Libraries

# install beecoSp from github
# this only needs to be done once!
remotes::install_github('land-4-bees/beecoSp', upgrade='always') 
library(tidyverse); library(beecoSp); library(cdlTools); library(raster)

Example: Reclass tables

# specify date(s) of version to match full pesticide reclass tables
date <- '20220325' # date for aggregate estimates (bee toxic load)
cmp_date <- '20220325' # date for the compound-specific table 

# insecticides (bee toxic load)
test <- reclasstables(filepath = paste0("../output_big/beetox_I_cdl_reclass.", date, ".csv"),
              state = c("PA","IL","OH"),
              year = c(2012,2013,2014),
              write_reclass = T,
              outfolder = "../output/reclass_keys/insecticides-test")

# glyphosate
test_gly <- reclasstables(filepath = paste0("../output_big/beetox_cmpd_cdl_reclass_", cmp_date, "/GLYPHOSATE.csv"),
              state = c("PA","IL","OH"),
              year = c(2012,2013,2014),
              write_reclass = T,
              outfolder = "../output/reclass_keys/glyphosate-test")

# mefenoxam
test_mef <- reclasstables(filepath = paste0("../output_big/beetox_cmpd_cdl_reclass_", cmp_date, "/MEFENOXAM.csv"),
              state = c("PA","IL","OH"),
              year = c(2012,2013,2014),
              write_reclass = T,
              outfolder = "../output/reclass_keys/mefenoxam-test")

# imidacloprid
test_imi <- reclasstables(filepath = paste0("../output_big/beetox_cmpd_cdl_reclass_", cmp_date, "/IMIDACLOPRID.csv"),
              state = c("PA","IL","OH"),
              year = c(2012,2013,2014),
              write_reclass = T,
              outfolder = "../output/reclass_keys/imidacloprid-test")

Example: Reclassify CDL

# Note that CropScapeR and cdlTools packages can be used to easily load/save CDL rasters by state and year
# From our testing, cdlTools is faster

# create directory for cdl file(s), if necessary
cdl_dir <- '../data_big/cdl/CDL_2012_42'

if (!dir.exists(cdl_dir)) {
   dir.create(cdl_dir)
}

# download CDL raster
cdl <- getCDL(x=42, year=2012, location=cdl_dir)

# specify path to CDL raster file
cdl_path <- paste0(cdl_dir, "/CDL_2012_42.tif")

# contact toxicity for insecticides
CDL_reclass(rasterpath = cdl_path,
            reclasstable = test$PA_2012,
            from = "value",
            to = "ld50_ct_ha_bil",
            writerast = TRUE,
            outpath = "../output_big/rasters/test",
            meanreclass = FALSE)

# oral toxicity for insecticides
CDL_reclass(rasterpath = cdl_path,
            reclasstable = test$PA_2012,
            from = "value",
            to = "ld50_or_ha_bil",
            writerast = TRUE,
            outpath = "../output_big/rasters/test",
            meanreclass = FALSE)

# survey coverage
CDL_reclass(rasterpath = cdl_path,
            reclasstable = test$PA_2012,
            from = "value",
            to = "coverage",
            writerast = TRUE,
            outpath = "../output_big/rasters/test",
            meanreclass = FALSE)

# glyphosate
CDL_reclass(rasterpath = cdl_path,
            reclasstable = test_gly$PA_2012,
            from = "value",
            to = "kg_ha",
            writerast = TRUE,
            outpath = "../output_big/rasters/test/gly",
            meanreclass = FALSE)

# mefenoxam
CDL_reclass(rasterpath = cdl_path,
            reclasstable = test_mef$PA_2012,
            from = "value",
            to = "kg_ha",
            writerast = TRUE,
            outpath = "../output_big/rasters/test/mef",
            meanreclass = FALSE)

# imidacloprid
CDL_reclass(rasterpath = cdl_path,
            reclasstable = test_imi$PA_2012,
            from = "value",
            to = "kg_ha",
            writerast = TRUE,
            outpath = "../output_big/rasters/test/imi",
            meanreclass = FALSE)

Session information

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] digest_0.6.29   R6_2.5.1        jsonlite_1.7.3  magrittr_2.0.1 
 [5] evaluate_0.14   stringi_1.7.6   rlang_1.0.2     cli_3.3.0      
 [9] rstudioapi_0.13 jquerylib_0.1.4 bslib_0.3.1     rmarkdown_2.11 
[13] tools_4.1.2     stringr_1.4.0   xfun_0.29       yaml_2.2.2     
[17] fastmap_1.1.0   compiler_4.1.2  htmltools_0.5.2 knitr_1.37     
[21] sass_0.4.0     

This R Markdown site was created with workflowr