---
title: "KAYA model - multiple views"
order: 1
author:
- name: "Declan Naughton 🧮👨💻🧉"
url: "https://calcwithdec.dev/about.html"
description: "some visuals for KAYA model"
format:
html:
resources:
- '../../models/kaya/*.js'
- '../../models/kaya/*.js.map'
---
# KAYA identity
The KAYA identity breaks carbon emissions into drivers:
- population
- GDP per capita
- energy intensity (energy needed to generate GDP)
- carbon intensity of energy sources (carbon needed to generate energy)
Below you can project carbon emissions based on assumptions about the the changes to each driver.
Another KAYA identity projector on which this is loosely based is [here](https://climatemodels.uchicago.edu/kaya/kaya.doc.html) (David Archer, University of Chicago).
More information on [Wikipedia](https://en.wikipedia.org/wiki/Kaya_identity) and [Emissions Drivers](https://ourworldindata.org/emissions-drivers) page by Our World in Data.
I have more plans with this model, including plugging actual data, tracking/reconciliations to plan (common/normal useful modelling exercises).
# visuals
```{ojs}
//| panel: sidebar
//| echo: false
md`**inputs** ⚙️`
md`**population projection:**`
viewof population_2023_in = Inputs.range([0,25e9], {value: 7.9e9, step:5e8,label: "population 2023" })
viewof population_2050_in = Inputs.range([0,25e9], {value: 9.8e9, step:5e8,label: "population 2050" })
viewof population_2100_in = Inputs.range([0,25e9], {value: 11.2e9, step:5e8,label: "population 2100" })
md`<br/>**2023 values:**`
viewof per_capita_gdp_2023_in = Inputs.range([500,50000], {value: 15200, step:200,label: "per capita gdp" })
viewof energy_intensity_2023_in = Inputs.range([0,5], {value: 1.42, step:0.01,label: "energy intensity" })
viewof carbon_intensity_2023_in = Inputs.range([0,2], {value: 0.22, step:0.01,label: "carbon intensity" })
md`<br/>**rates of change pa:**`
viewof per_capita_gdp_rate_in = Inputs.range([-.2,0.2], {value: 0.01, step:0.005,label: "per capita gdp" })
viewof energy_intensity_rate_in = Inputs.range([-.2,0.2], {value: -0.01, step:0.005,label: "energy intensity" })
viewof carbon_intensity_rate_in = Inputs.range([-.2,0.2], {value: -0.01, step:0.005,label: "carbon intensity" })
```
```{ojs}
//| echo: true
//| code-summary: "Visual Spec"
//| panel: fill
embed(
calcuvizspec({
models: [kaya],
input_cursors: [{population_2023_in,population_2050_in,population_2100_in,per_capita_gdp_2023_in,energy_intensity_2023_in,carbon_intensity_2023_in,per_capita_gdp_rate_in,energy_intensity_rate_in,carbon_intensity_rate_in}],
mark: 'text',
encodings: {
y: {name: 'year_in', grid:false, type:'quantitative', domain: [2023,2024,..._.range(2030,2101,20), 2100], zero:false, sort:'descending'},
text: {name: 'value', type: 'quantitative', format: '.4k'},
x: {name: 'formula', type:'nominal', domain: ["carbon_emissions", "population_factor", "per_capita_gdp_factor", "energy_intensity_factor", "carbon_intensity_factor", "year"]},
color: {name: 'formula', type:'nominal', legend:false},
},
width: 400, height:400
}))
embed(
calcuvizspec({
models: [kaya],
input_cursors: [{population_2023_in,population_2050_in,population_2100_in,per_capita_gdp_2023_in,energy_intensity_2023_in,carbon_intensity_2023_in,per_capita_gdp_rate_in,energy_intensity_rate_in,carbon_intensity_rate_in}],
mark: 'bar',
encodings: {
x: {name: 'year_in', grid:false, type:'quantitative', domain: _.range(2023,2100), zero:false},
y: {name: 'value', type: 'quantitative', independent:true, grid:false},
row: {name: 'formula', type:'nominal', domain: ["carbon_emissions", "population_factor", "per_capita_gdp_factor", "energy_intensity_factor", "carbon_intensity_factor"]},
color: {name: 'formula', type:'nominal', legend:false},
},
width: 400, height:50
}))
```
# Appendix
::: {.callout-tip}
You can find the calculang model source code by opening Developer Tools (Ctrl+Shift+I) and navigating to the `.cul.js` file (Ctrl+P and search `.cul.js`).
:::
```{ojs}
import { calcuvizspec } from "@declann/little-calcu-helpers"
embed = require('vega-embed');
viewof entrypoint = Inputs.select(['models/kaya/kaya.cul.js'], {label:'entrypoint'})
entrypoint_no_cul_js = entrypoint.slice(0,-7)
kaya = require(`../../${entrypoint_no_cul_js}.js`);
introspection_fetch = await fetch(`../../${entrypoint_no_cul_js}.introspection.json`)
introspection = introspection_fetch.json({typed:true})
inputs = Object.values(introspection.cul_functions).filter(d => d.reason == 'input definition').map(d => d.name).sort()
formulae = Object.values(introspection.cul_functions).filter(d => d.reason == 'definition').map(d => d.name)
// formulae excluding pure inputs
formulae_not_inputs = Object.values(introspection.cul_functions).filter(d => d.reason == 'definition' && inputs.indexOf(d.name+'_in') == -1).map(d => d.name)
```
::: {.callout-tip}
For calculang devtools adjust *entrypoint* in [devtools](/pages/some-devtools.qmd).
:::