Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make year range limit easier to adjust in sum_gfw #273

Closed
fBedecarrats opened this issue May 26, 2024 · 1 comment · Fixed by #279
Closed

Make year range limit easier to adjust in sum_gfw #273

fBedecarrats opened this issue May 26, 2024 · 1 comment · Fixed by #279

Comments

@fBedecarrats
Copy link
Contributor

Currenly .sum_gfw() is defined as follows in R/calc_treecover_area.R:

.sum_gfw <- function(data, what = "coverage_area") {
  # calculate loss area by year
  df <- data.frame(years = 2000:2022, var = 0)
  names(df)[2] <- what
  my_sum <- by(data[[what]], data[["lossyear"]], sum, na.rm = TRUE)
  sum_years <- as.numeric(names(my_sum))
  sum_years <- sum_years + 2000

  index <- match(sum_years, df[["years"]])
  df[[what]][index] <- as.numeric(my_sum)

  df
}

The line df <- data.frame(years = 2000:2022, var = 0) implies that 2000:2022 must be updated at each get_gfw_lossyear() to include the latest available year for the resource. This is not very intuitive and possibly error prone. I wonder if it would not be convenient to extract the year range directly from the gfw_lossyear resource being used.

@goergen95
Copy link
Member

Thanks! We now detect the maximum year from the layer name of the gfw_lossyear object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants