_targets.R

library(targets)
library(tarchetypes) # for tar_knitr_deps_expr()
library(here) # construct file paths relative to project root
library(fs) # file system operations

tar_option_set(
  packages = c("tidyverse", "readxl", "data.table", "spCEH", "units", "ggforce", "qs"),
  format = "qs"
)
# Functions used by the targets.
source(here::here("R", "ukem.R"))

# set year to use as reference for relative scaling
year_ref <- 2019
# set sector classification scheme to use for output
sector_classification <- "SNAP"
# set years to produce output for
startYear <- 2010
endYear <- 2019

# List of targets.have manually changed the endYear in the targets below - this cant be right?
list(
  # First targets apply to all pollutants:
  # lookup files
  tar_target(lookup_GNFR, "data/lookups/GNFR_to_SNAP.csv", format = "file"),
  tar_target(lookup_NFR,  "data/lookups/NFR19_to_SNAP.csv", format = "file"),
  tar_target(lookup_SIC,  "data/lookups/SIC_to_SNAP.csv", format = "file"),
  tar_target(lookup_CRF,  "data/lookups/CRF_to_SNAP.csv", format = "file"),

  # read the point source data from annual files to a single data table
  tar_target(r, getRasterTemplate(domain = "UK_NAME", proj = projlonlat)),

  # read the point source data from annual files to a single data table
  tar_target(dt_pts, getPointSourceData(startYear = 2010, endYear = 2019, lookup_SIC = lookup_SIC)),

  # read the national total data from BEIS queries to a single data table
  tar_target(dt_raw_uk, getEmissionTimeSeriesFromBEIS(
    startYear = 1990, endYear = 2019,
    query_id_ghg = 151517, query_id_airpoll = 151579,
    sector_classification = sector_classification, lookup_NFR = lookup_NFR)),

  # read the Irish national total data from UNFCCC file to a single data table. SJT chnaged to UNFCC 20/01/22
  tar_target(dt_raw_ire, getEmissionTimeSeriesFromUNFCCC(
    startYear = 1990, endYear = 2019,
    sector_classification = sector_classification, lookup_CRF = lookup_CRF)),

  # calculate times series of emissions relative to reference year
  tar_target(dt_ts_uk, getAlpha_byYear(dt_raw_uk, year_ref = year_ref)),
  # plot times series of emissions relative to reference year
  tar_target(p_alpha_year_uk, plotAlpha_byYear(dt_ts_uk)),
  # calculate times series of emissions relative to reference year
  tar_target(dt_ts_ie, getAlpha_byYear(dt_raw_ire, year_ref = year_ref)),
  # plot times series of emissions relative to reference year
  tar_target(p_alpha_year_ie, plotAlpha_byYear(dt_ts_ie)),
  # ch4
  tar_target(v_fname_ch4, get_maps_UKIE(year_ref = year_ref, startYear = startYear, endYear = endYear,
    pollutant = "ch4", r = r, dt_pts = dt_pts, dt_ts_uk = dt_ts_uk,
    dt_ts_ie = dt_ts_ie, unitSIprefix = "none", lookup_GNFR = lookup_GNFR)),
  # co2
  tar_target(v_fname_co2, get_maps_UKIE(year_ref = year_ref, startYear = startYear, endYear = endYear,
    pollutant = "co2", r = r, dt_pts = dt_pts, dt_ts_uk = dt_ts_uk,
    dt_ts_ie = dt_ts_ie, unitSIprefix = "none", lookup_GNFR = lookup_GNFR)),
  # n2o
  tar_target(v_fname_n2o, get_maps_UKIE(year_ref = year_ref, startYear = startYear, endYear = endYear,
    pollutant = "n2o", r = r, dt_pts = dt_pts, dt_ts_uk = dt_ts_uk,
    dt_ts_ie = dt_ts_ie, unitSIprefix = "none", lookup_GNFR = lookup_GNFR))
)
NERC-CEH/ukem documentation built on Feb. 18, 2022, 1:31 a.m.