bc3LC / gcamreport

Package to process GCAM results and standardize the format
https://bc3lc.github.io/gcamreport/
MIT License
2 stars 2 forks source link

Price|Carbon calculation does not work if no CO2_ETS available #8

Closed christophbertram closed 1 month ago

christophbertram commented 1 month ago

When running the exe/configuration_policy.xml scenario from gcam 7 vanilla (https://github.com/JGCRI/gcam-core/blob/gcam-v7.0/exe/configuration_policy.xml), and then trying to run

generate_report(db_path=dbpath,db_name=dbname,prj_name=prjname,scenarios=scen,launch_ui=FALSE,
desired_variables = c('Price|Carbon'))

I get the following error message:

Scenario 4p5 does not exist in this project.  Creating.
Loading data, performing checks, and saving output...
[1] "price_var"
[1] "fe_sector"
[1] "fe_transportation"
[1] "fe_sector_clean"
[1] "region_weight"
[1] "regions.global"
[1] "co2_ets_bysec"
[1] "co2_clean"
[1] "co2_price_share_bysec"
Joining with `by = join_by(scenario, region, var, year)`
[1] "co2_price_fragmented"
Error in `mutate()`:
ℹ In argument: `across(6:length(colnames(.)), ~ifelse(is.na(.), 0, .))`.
Caused by error in `across()`:
! Can't select columns past the end.
ℹ Location 6 doesn't exist.
ℹ There are only 5 columns.
Backtrace:
     ▆
  1. ├─gcamreport::generate_report(...)
  2. │ └─gcamreport::load_variable(variables.global[i, ])
  3. │   └─gcamreport::load_variable(...)
  4. │     └─get(var$fun)()
  5. │       └─... %>% select(all_of(gcamreport::long_columns))
  6. ├─dplyr::select(., all_of(gcamreport::long_columns))
  7. ├─tidyr::complete(...)
  8. ├─dplyr::filter(., complete.cases(.))
  9. ├─dplyr::left_join(...)
 10. ├─dplyr::select(...)
 11. ├─dplyr::mutate(., value = CO2 + CO2_ETS * share_CO2_ETS)
 12. ├─dplyr::left_join(...)
 13. ├─dplyr::mutate(...)
 14. ├─dplyr:::mutate.data.frame(., across(6:length(colnames(.)), ~ifelse(is.na(.), 0, .)))
 15. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
 16. │   ├─base::withCallingHandlers(...)
 17. │   └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
 18. │     └─dplyr:::expand_across(dot)
 19. │       └─dplyr:::across_setup(...)
 20. │         └─tidyselect::eval_select(cols, data = data, error_call = error_call)
 21. │           └─tidyselect:::eval_select_impl(...)
 22. │             ├─tidyselect:::with_subscript_errors(...)
 23. │             │ └─base::withCallingHandlers(...)
 24. │             └─tidyselect:::vars_select_eval(...)
 25. │               └─tidyselect:::loc_validate(pos, vars, call = error_call)
 26. │                 └─vctrs::vec_as_location(pos, n = length(vars), call = call)
 27. └─vctrs (local) `<fn>`()
 28.   └─vctrs:::stop_subscript_oob(...)
 29.     └─vctrs:::stop_subscript(...)
 30.       └─rlang::abort(...)
Execution halted

I think this has to do with CO2_ETS not being defined in vanilla GCAM. Probably you at BC3 are best positioned to come up with a formulation that both serves your purposes for scenario runs with European ETS markets, and is compatible with vanilla GCAM.

klau506 commented 1 month ago

Dear @christophbertram,

Thank you for reporting this bug and detailing how to reproduce it! We have now fixed the issue! 🚀 We might add in the following days a documentation page detailing how the CO2 price is computed and how you can add your own CO2 markets, so stay tuned!

Best, Clàudia