Coder Social home page Coder Social logo

carpentr's Introduction

Carbon pricing for the energy transition (prototype)

This repository contains R code and a shiny app for understanding the impacts of carbon pricing for revenue generation and spending. It is a work in progress. The tools uses EITI production and revenue data to estimate carbon revenue associated with oil and gas production in a given country and year. It then combines this with World Bank world development indicator data to generate a set of user-specific indicators suggesting how revenue from carbon pricing could be spent.

This work has been produced as part of the EITI Datathon 2022.

Installation

Clone this repository, navigate to the carpentr directory, then run:

devtools::install()
library(carpentr)

Front end development

A shiny app is located in inst/shiny/carpentr, and can be edited from within there. To run the app, run:

shiny::runApp('inst/shiny/carpentr')

To deploy on shinyapps.io (assuming you have permissions), run:

devtools::install_github('opendataservices/carpentr@main')
rsconnect::deployApp('inst/shiny/carpentr',account = 'opendataservices')

Back end development

R functions are located in the R directory, and can be run and tested within the R markdown file inst/rmd/backend_development.Rmd

To edit an existing function, edit the R script, then run devtools::install() to build the package. If you have changed the documentation, also run devtools::document() to update the documentation.

To add a new function, create a new R script in the R directory, using one of the existing functions as a template. Be sure edit the roxygen comments so that the documentation is correct and any imports are included.

carpentr's People

Contributors

lgs85 avatar odscrachel avatar

Watchers

Rob Redpath avatar Jack Lord avatar Bibiana Cristòfol avatar  avatar  avatar  avatar Neelima J avatar

carpentr's Issues

oilgas_to_co2: research and enhance

The oilgas_to_co2() function converts EITI production data to an estimate of CO2 emissions. This works for illustrative purposes, but at present uses dummy conversion factors which will be inaccurate. We need to source and reference conversion factors for:

  • KG CO2 per unit oil production
  • KG CO2 per unit gas production
  • Energy content of crude oil per m3 (if CO2 conversion in joules)
  • Energy content of gas per m3 (if CO2 conversion in joules)

We also need to consider what we mean by 'production', and to make sure the production indicators in the EITI marry with any conversion factors we source,

read_eiti_production: research and enhance

The read_eiti_production() function pulls in summary data from the EITI API, filters and selects oil and gas production indicators, and outputs a dataframe. This works for the couple of countries I've tested on, but needs further research, including:

  • Do we need to pull in more/different indicators?
  • Are the units always the same?
  • Any other data quality issues?

Come up with an approach for filtering indicators based on questionnaire answers

The basis of the shiny app will be to provide users with a tailored set of indicators on possible spending using carbon pricing revenue, based on the answers that users provide to a short questionnaire. We need to come up with an approach that ranks and selects a top set of indicators based on this user questionnaire data. As a starting point, here is how I was thinking about it:

Imagine that the questionnaire had three questions, we had three indicators, and we wanted to display the top 1 indicator to the user (in reality we'll have ~50 indicators and will display the top 5 or so, this is a toy example). Our toy questions are given a score of 1-9 based on how much they agree with the following statements:

Q1. I am worried about the impacts of carbon pricing on my family
Q2. I am worried about the impacts of carbon pricing on my community
Q3. I am worried about the impacts of carbon pricing on my country's economy

A user answers these questions and provides the following scores:

Question Score
Q1 2
Q2 5
Q3 9

Our three candidate indicators are (NB these are just for illustrative purposes):

Ind1. $5bn could be invested in the national economy
Ind2. A $500 tax rebate could be given to to every family in the country
Ind3. $500m dollars could be invested in creating jobs in local communities affected by the energy transition

What we could then do is put an expected score for each indicator against each question. We expect somebody worried about the national economy to provide a high score for Q1, and so on. Note that we'd have to come up with these expected scores ourselves. If we do so we get:

Question Score Expected_Ind1 Expected_Ind2 Expected_Ind3
Q1 2 3 9 5
Q2 5 6 6 9
Q3 9 9 3 5

We can then get a correlation for each indicator between what the expected answers to each question were and what the user gave. Using a simple Pearson correlation (this is silly with 3 points, but still) we get values of $r$ = 0.99,-0.1 and -0.99 for indicators 1, 2 and 3 respectively. This suggests, logically, that the user is a good fit for indicator 1 and a poor fit for indicators 2 and 3, so they are presented with indicator 1 in the app.

Lots of subjectivity and issues here, but hopefully a starting point for some work. @neelima-j I've added you as you'd expressed interest in this.

Consider realistic carbon pricing scenarios to use

In the front end of the dashboard, we should consider generating outputs based on a range of carbon pricing scenarios. At present the app allows the user to select between a 'high', 'medium' and 'low' carbon pricing scenarios, with some values associated with me. We should consider how many carbon pricing scenarios is appropriate, and what these prices should be.

get_revenue function: research and enhance

The get_revenue() function estimates carbon pricing revenue from a given carbon emissions value and carbon price. At present, this is overly simple, and follows the approach in table 2 of this report of multiplying the emissions by the carbon price, then multiplying by 0.9 to account for reduced emissions. We need to research and implement a conversion approach that:

  • Better accounts for the non-linear relationship between CO2 emissions and carbon revenue.
  • Considers the timeframe over which revenues can and should be projected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.