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

At product level, all functions now output profile_ranking #613

Merged
merged 2 commits into from
Nov 16, 2023

Conversation

maurolepore
Copy link
Contributor

@maurolepore maurolepore commented Nov 14, 2023

Closes #549
Closes #581

This PR adds the column profile_ranking to all outputs at product level. At company level I believe it makes no sense, since the values of profile_ranking are more granular (@AnneSchoenauer please confirm).


TODO

  • Link related issue/PR.
  • Describe the goal of the PR. Avoid details that are clear in the diff.
  • Mark the PR as draft.
  • Review your own PR in "Files changed".
  • Ensure the PR branch is updated.
  • Ensure the checks pass.
  • Change the status from draft to ready.
  • Polish the PR title and description.
  • Assign a reviewer.

EXCEPTIONS

reprex

devtools::load_all()
#> ℹ Loading tiltIndicator

companies <- example_companies()
products <- example_products()
inputs <- example_inputs()
scenarios <- example_scenarios()

emissions_profile(companies, products) |> unnest_product()
#> # A tibble: 6 × 7
#>   companies_id grouped_by       risk_category profile_ranking clustered
#>   <chr>        <chr>            <chr>                   <dbl> <chr>    
#> 1 a            all              high                        1 a        
#> 2 a            isic_4digit      high                        1 a        
#> 3 a            tilt_sector      high                        1 a        
#> 4 a            unit             high                        1 a        
#> 5 a            unit_isic_4digit high                        1 a        
#> 6 a            unit_tilt_sector high                        1 a        
#> # ℹ 2 more variables: activity_uuid_product_uuid <chr>, co2_footprint <chr>

emissions_profile_upstream(companies, inputs) |> unnest_product()
#> # A tibble: 6 × 8
#>   companies_id grouped_by                risk_category profile_ranking clustered
#>   <chr>        <chr>                     <chr>                   <dbl> <chr>    
#> 1 a            all                       high                        1 a        
#> 2 a            input_isic_4digit         high                        1 a        
#> 3 a            input_tilt_sector         high                        1 a        
#> 4 a            input_unit                high                        1 a        
#> 5 a            input_unit_input_isic_4d… high                        1 a        
#> 6 a            input_unit_input_tilt_se… high                        1 a        
#> # ℹ 3 more variables: activity_uuid_product_uuid <chr>,
#> #   input_activity_uuid_product_uuid <chr>, input_co2_footprint <chr>

sector_profile(companies, scenarios) |> unnest_product()
#> # A tibble: 1 × 11
#>   companies_id grouped_by risk_category profile_ranking clustered
#>   <chr>        <chr>      <chr>         <chr>           <chr>    
#> 1 a            ipr_a_2050 high          1               a        
#> # ℹ 6 more variables: activity_uuid_product_uuid <chr>, tilt_sector <chr>,
#> #   scenario <chr>, year <chr>, type <chr>, tilt_subsector <chr>

sector_profile_upstream(companies, scenarios, inputs) |> unnest_product()
#> # A tibble: 1 × 13
#>   companies_id grouped_by risk_category profile_ranking clustered
#>   <chr>        <chr>      <chr>         <chr>           <chr>    
#> 1 a            ipr_a_2050 high          1               a        
#> # ℹ 8 more variables: activity_uuid_product_uuid <chr>, tilt_sector <chr>,
#> #   scenario <chr>, year <chr>, type <chr>,
#> #   input_activity_uuid_product_uuid <chr>, input_tilt_sector <chr>,
#> #   input_tilt_subsector <chr>

Created on 2023-11-14 with reprex v2.0.2

@maurolepore maurolepore marked this pull request as ready for review November 14, 2023 20:00
@maurolepore maurolepore changed the title Add 'profile_ranking' at product level All outputs at product level now include the column profile_ranking Nov 14, 2023
@maurolepore maurolepore changed the title All outputs at product level now include the column profile_ranking All functions at product level now output profile_ranking Nov 14, 2023
@maurolepore maurolepore changed the title All functions at product level now output profile_ranking At product level, all functions now output profile_ranking Nov 15, 2023
@AnneSchoenauer
Copy link

Dear @maurolepore,

First I think to add the profile_ranking in those csv files are fine. Please note that you don't need to do it for the company dataset as you said.

Some questions:

  • you only now chose one clustered "a" however of course at a later stage there will be many clustered right? And they will then of course have a different profile_ranking than 1. This was just the example that you chose right?
  • In the emission_profile_upstream I noticed that the benchmark 'all' is not called 'input_all' - this would be more precise and consistent with the others
  • In the sector profiles there are also more groups right? I am missing scenario ipr_2030, scenario weo_2030 and weo_2050. Please note that it can be that the data that Kalash will give you that the variable is still called "reductions" as the profile_ranking is the same as the reductions column in my understanding.

@maurolepore
Copy link
Contributor Author

maurolepore commented Nov 16, 2023

Thanks @AnneSchoenauer for your feedback.

Yes, the reprex above was extremely minimal to clearly show the new colum profile_ranking.

To see how it varies across rows we need a more complex reprex. Here I use our toy datasets. I think it answers your questions 1 and 3.

RE the inconsistency across the values of grouped_by for emissions profile (i.e. benchmarks) -- note that grouped_by simply stores the names of the columns we we group by (i.e. benchmarks). If the columns don't use the annoying prefix "input_" then there is no inconsistency.

My suggestion is to remove the "input_" prefix. If anyone wonders where the columns come from (products or inputs), they can simply see the name of the dataset, e.g. products$isic_4digit versus inputs$isic_4digit. I estimate the "input_" prefix already costed at least 1 week of developer time (adding it, removing it, adding it again, discussing it, working around it, debugging it).

library(tiltToyData)
library(readr, warn.conflicts = FALSE)
options(readr.show_col_types = FALSE, width = 500)

# PR tiltIndicator #613
devtools::load_all()
#> ℹ Loading tiltIndicator

companies <- read_csv(toy_emissions_profile_any_companies())
products <- read_csv(toy_emissions_profile_products())
emissions_profile(companies, products) |> unnest_product()
#> # A tibble: 49 × 7
#>    companies_id                             grouped_by       risk_category profile_ranking clustered activity_uuid_product_uuid                                                co2_footprint
#>    <chr>                                    <chr>            <chr>                   <dbl> <chr>     <chr>                                                                             <dbl>
#>  1 fleischerei-stiefsohn_00000005219477-001 all              high                    1     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa         176. 
#>  2 fleischerei-stiefsohn_00000005219477-001 isic_4digit      high                    1     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa         176. 
#>  3 fleischerei-stiefsohn_00000005219477-001 tilt_sector      high                    1     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa         176. 
#>  4 fleischerei-stiefsohn_00000005219477-001 unit             high                    1     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa         176. 
#>  5 fleischerei-stiefsohn_00000005219477-001 unit_isic_4digit high                    1     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa         176. 
#>  6 fleischerei-stiefsohn_00000005219477-001 unit_tilt_sector high                    1     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa         176. 
#>  7 fleischerei-stiefsohn_00000005219477-001 all              high                    0.8   oven      be06d25c-73dc-55fb-965b-0f300453e380_98b48ff2-2200-4b08-9dec-9c7c0e3585bc          58.1
#>  8 fleischerei-stiefsohn_00000005219477-001 isic_4digit      medium                  0.5   oven      be06d25c-73dc-55fb-965b-0f300453e380_98b48ff2-2200-4b08-9dec-9c7c0e3585bc          58.1
#>  9 fleischerei-stiefsohn_00000005219477-001 tilt_sector      medium                  0.667 oven      be06d25c-73dc-55fb-965b-0f300453e380_98b48ff2-2200-4b08-9dec-9c7c0e3585bc          58.1
#> 10 fleischerei-stiefsohn_00000005219477-001 unit             medium                  0.5   oven      be06d25c-73dc-55fb-965b-0f300453e380_98b48ff2-2200-4b08-9dec-9c7c0e3585bc          58.1
#> # ℹ 39 more rows

companies <- read_csv(toy_emissions_profile_any_companies())
products <- read_csv(toy_emissions_profile_products())
inputs <- read_csv(toy_emissions_profile_upstream_products())
emissions_profile_upstream(companies, inputs) |> unnest_product()
#> # A tibble: 319 × 8
#>    companies_id                             grouped_by        risk_category profile_ranking clustered activity_uuid_product_uuid                                                input_activity_uuid_product_uuid                                     input_co2_footprint
#>    <chr>                                    <chr>             <chr>                   <dbl> <chr>     <chr>                                                                     <chr>                                                                              <dbl>
#>  1 fleischerei-stiefsohn_00000005219477-001 all               high                   0.909  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5             7.07e+0
#>  2 fleischerei-stiefsohn_00000005219477-001 all               high                   1      stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 1aeb18b9-8355-560f-82aa-543c771c4d61_a0e53510-b90b-43ba-80cc-7600f5d             3.99e+1
#>  3 fleischerei-stiefsohn_00000005219477-001 all               medium                 0.636  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 22704506-7707-5ae7-990d-ebf01ac04fb5_50c41012-3b00-429d-ace3-40d0                5.12e-1
#>  4 fleischerei-stiefsohn_00000005219477-001 all               high                   0.758  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 92078219-1ed3-5215-9f70-931cdefad520_5c21b18e-e32d-4c76-8d16-2238632             1.24e+0
#>  5 fleischerei-stiefsohn_00000005219477-001 all               high                   0.970  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 9d483329-b09a-5513-b1bc-722cb211e928_bd4dca-497e-bdd9-fcd343012087               2.12e+1
#>  6 fleischerei-stiefsohn_00000005219477-001 all               low                    0.0909 stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 8709b463-732e-592e-9b88-999ed17af48f_6b6b3a15-e0-baea-cda98afc61c2               1.24e-9
#>  7 fleischerei-stiefsohn_00000005219477-001 all               low                    0.121  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa d44e7db1-4dda-51ed2929a8f1a2_32e60fbc-4778-470c-9653-feb859a3418f                7   e-9
#>  8 fleischerei-stiefsohn_00000005219477-001 all               high                   0.697  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 7c7718bb-2372-5d04-a7ac-1ae5b12b05e3_61396bcb-bf35-411a-a6a6-85e8                1.04e+0
#>  9 fleischerei-stiefsohn_00000005219477-001 input_isic_4digit high                   0.857  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5             7.07e+0
#> 10 fleischerei-stiefsohn_00000005219477-001 input_isic_4digit high                   1      stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa 1aeb18b9-8355-560f-82aa-543c771c4d61_a0e53510-b90b-43ba-80cc-7600f5d             3.99e+1
#> # ℹ 309 more rows

companies <- read_csv(toy_sector_profile_companies())
scenarios <- read_csv(toy_sector_profile_any_scenarios())
sector_profile(companies, scenarios) |> unnest_product()
#> # A tibble: 196 × 11
#>    companies_id                             grouped_by                                   risk_category profile_ranking clustered activity_uuid_product_uuid                                   tilt_sector scenario                             year type  tilt_subsector
#>    <chr>                                    <chr>                                        <chr>                   <dbl> <chr>     <chr>                                                        <chr>       <chr>                               <dbl> <chr> <chr>         
#>  1 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_2030                            high                   0.23   steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        1.5c rps                             2030 ipr   <NA>          
#>  2 fleischerei-stiefsohn_00000005219477-001 ipr_1.5c rps_2050                            high                   0.96   steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        1.5c rps                             2050 ipr   <NA>          
#>  3 fleischerei-stiefsohn_00000005219477-001 weo_stated policies scenario_2020            low                    0      steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        stated policies scenario             2020 weo   <NA>          
#>  4 fleischerei-stiefsohn_00000005219477-001 weo_announced pledges scenario_2020          low                    0      steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        announced pledges scenario           2020 weo   <NA>          
#>  5 fleischerei-stiefsohn_00000005219477-001 weo_net zero emissions by 2050 scenario_2020 low                    0      steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        net zero emissions by 2050 scenario  2020 weo   <NA>          
#>  6 fleischerei-stiefsohn_00000005219477-001 weo_stated policies scenario_2030            low                   -0.0752 steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        stated policies scenario             2030 weo   <NA>          
#>  7 fleischerei-stiefsohn_00000005219477-001 weo_announced pledges scenario_2030          low                    0.0781 steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        announced pledges scenario           2030 weo   <NA>          
#>  8 fleischerei-stiefsohn_00000005219477-001 weo_net zero emissions by 2050 scenario_2030 high                   0.233  steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        net zero emissions by 2050 scenario  2030 weo   <NA>          
#>  9 fleischerei-stiefsohn_00000005219477-001 weo_stated policies scenario_2040            low                   -0.0270 steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        stated policies scenario             2040 weo   <NA>          
#> 10 fleischerei-stiefsohn_00000005219477-001 weo_announced pledges scenario_2040          medium                 0.336  steel     0faa7ecb-fef2-5117-8993-387c1236-001e-49b5-aa3d-810c0214f9ce <NA>        announced pledges scenario           2040 weo   <NA>          
#> # ℹ 186 more rows

companies <- read_csv(toy_sector_profile_upstream_companies())
scenarios <- read_csv(toy_sector_profile_any_scenarios())
inputs <- read_csv(toy_sector_profile_upstream_products())
sector_profile_upstream(companies, scenarios, inputs) |> unnest_product()
#> # A tibble: 704 × 13
#>    companies_id                             grouped_by                                   risk_category profile_ranking clustered activity_uuid_product_uuid                                                tilt_sector scenario                             year type  input_activity_uuid_product_uuid                                          input_tilt_sector     input_tilt_subsector
#>    <chr>                                    <chr>                                        <chr>                   <dbl> <chr>     <chr>                                                                     <chr>       <chr>                               <dbl> <chr> <chr>                                                                     <chr>                 <chr>               
#>  1 fleischerei-stiefsohn_00000005219477-001 weo_stated policies scenario_2020            low                     0     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      stated policies scenario             2020 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  2 fleischerei-stiefsohn_00000005219477-001 weo_stated policies scenario_2030            low                    -0.192 stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      stated policies scenario             2030 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  3 fleischerei-stiefsohn_00000005219477-001 weo_stated policies scenario_2040            low                    -0.517 stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      stated policies scenario             2040 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  4 fleischerei-stiefsohn_00000005219477-001 weo_stated policies scenario_2050            low                    -0.689 stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      stated policies scenario             2050 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  5 fleischerei-stiefsohn_00000005219477-001 weo_announced pledges scenario_2020          low                     0     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      announced pledges scenario           2020 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  6 fleischerei-stiefsohn_00000005219477-001 weo_announced pledges scenario_2030          high                    0.301 stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      announced pledges scenario           2030 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  7 fleischerei-stiefsohn_00000005219477-001 weo_announced pledges scenario_2040          high                    1.83  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      announced pledges scenario           2040 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  8 fleischerei-stiefsohn_00000005219477-001 weo_announced pledges scenario_2050          high                    3.17  stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      announced pledges scenario           2050 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#>  9 fleischerei-stiefsohn_00000005219477-001 weo_net zero emissions by 2050 scenario_2020 low                     0     stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      net zero emissions by 2050 scenario  2020 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#> 10 fleischerei-stiefsohn_00000005219477-001 weo_net zero emissions by 2050 scenario_2030 high                    0.909 stove     0a242b09-772a-5edf-8e82-9cb4ba52a258_ae39ee61-d4d0-4cce-93b4-0745344da5fa energy      net zero emissions by 2050 scenario  2030 weo   5de8c337-dea9-5c1f-9d90-002de27188be_8911bd8c-a96f-4440-9f8e-a7dacf5e79de non-metallic minerals raw minerals        
#> # ℹ 694 more rows

Created on 2023-11-16 with reprex v2.0.2

@maurolepore maurolepore merged commit f64989e into main Nov 16, 2023
@maurolepore maurolepore deleted the 581_emissions_profile-outputs-profile_ranking branch November 16, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants