Calculate Potential Evapotranspiration (PET)

日本語版はこちら (Japanese version)

This chapter calculates potential evapotranspiration (PET) using the Thornthwaite method (Thornthwaite 1948) with the SPEI package (Beguería and Vicente-Serrano 2023).

Load libraries

Load data

data_dir <- Sys.getenv("PROJECT_DATA_DIR")
# data_dir <- "data" # if PROJECT_DATA_DIR is not set
sf_climate <- readRDS(file.path(
  data_dir,
  "climate_mesh_data_joined/climate_mesh_data.rds"
))

Create a data frame for PET calculation

latitudes <- sf_climate$latitude
df_temp <- sf_climate[, grep("mean_temperature", names(sf_climate))]
df_temp <- st_drop_geometry(df_temp)
df_temp <- df_temp[, 1:12]

keep <- complete.cases(df_temp)
removed_rows <- which(!keep)

df_temp_clean <- df_temp[keep, ]
sf_climate_clean <- sf_climate[keep, ]
row.names(df_temp_clean) <- sf_climate_clean$mesh_code_3rd

Calculate PET

n <- nrow(df_temp_clean)
pet_month <- matrix(NA, n, 12)
for (i in seq_len(n)) {
  pet_month[i, ] <- SPEI::thornthwaite(
    Tave = as.numeric(df_temp_clean[i, ]),
    lat = latitudes[i],
    verbose = FALSE
  )
}

Shape PET data

df_pet <- as.data.frame(pet_month)
names(df_pet) <- paste0("PET", 1:12)
df_pet$PET_year <- rowSums(df_pet)

Join PET to climate data

df_pet$mesh_code_3rd <- row.names(df_temp_clean)
sf_merged <- merge(
  sf_climate,
  df_pet,
  by = "mesh_code_3rd",
  all.x = TRUE,
  sort = FALSE
)
df_merged <- st_drop_geometry(sf_merged)

Save data

save_dir <- file.path(data_dir, "climate_mesh_data_joined")
saveRDS(sf_merged, file.path(save_dir, "climate_mesh_data_with_pet.rds"))
write.csv(
  df_merged,
  file.path(save_dir, "climate_mesh_data_with_pet.csv"),
  row.names = FALSE
)

References

Beguería, Santiago, and Sergio M. Vicente-Serrano. 2023. SPEI: Calculation of the Standardized Precipitation-Evapotranspiration Index. https://doi.org/10.32614/CRAN.package.SPEI.
Thornthwaite, C. W. 1948. “An Approach Toward a Rational Classification of Climate.” Geographical Review 38 (1): 55–94. https://doi.org/10.2307/210739.