diff --git a/CHANGELOG.md b/CHANGELOG.md index fa24e5da3b..c68602a951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - ### fixed -- +- **scripts** Fixed a bug in NPI/NDC calculations leading to missing AD policies when run with 67k ## [4.6.11] - 2023-09-05 diff --git a/scripts/npi_ndc/start_npi_ndc.R b/scripts/npi_ndc/start_npi_ndc.R index 237650a8df..38cbabf597 100644 --- a/scripts/npi_ndc/start_npi_ndc.R +++ b/scripts/npi_ndc/start_npi_ndc.R @@ -258,7 +258,11 @@ calc_policy <- function(policy, stock, pol_type="aff", pol_mapping=pol_mapping, #set stock to zero or Inf for countries without policies # (representing no constraint for min and max constraints) if(pol_type=="ad"){ - stock[!(sub("\\..*$","",getCells(stock)) %in% policy_countries),,] <- 0 + if(dim(stock)[1] == 59199) { + stock[!(sub("\\..*$","",getCells(stock)) %in% policy_countries),,] <- 0 + } else { + stock[!(getItems(stock, "iso", full = TRUE) %in% policy_countries),,] <- 0 + } #calculate flows flow <- calc_flows(stock) #account only for positive flows, i.e. deforestation