some visuals for โ€˜mainโ€™ model

WIP

Do not use.

Rec. approach comments: not what I consider a good one, but working & moving quickly given simple models.

Working : concentrations โœ… (note: emissions calcd with diff units C/CO2. Also 5-year dt vs 1-year)

TODO forcing -> temperature via deep ocean ebm [right now, temperature and forcing tie exactly. note: 3.45 vs. 5 is log base 2 versus natural log.]

investigate: does margo have a (small) off-by(5 years) error in t_arr (i.e. labeling), or do I?

T rec is (V!) close, but check components. Small error due to dt=5? (Looks like no, from setting =1 consistent)

Code
# adapted from ClimateMARGO.jl/examples/default_configuration.jl Henri Drake, MIT license
using ClimateMARGO
using JSON

using ClimateMARGO.Models
using ClimateMARGO.Utils
using ClimateMARGO.Diagnostics

initial_year = 2020.0 # [yr]
final_year = 2200.0 # [yr]
dt = 5.0 # [yr]
t_arr = t(initial_year, final_year, dt);

present_year = initial_year
dom = Domain(dt, initial_year, initial_year, final_year);


c0 = 460.0 # [ppm]
r = 0.5; # [1] fraction of emissions remaining after biosphere and ocean uptake (Solomon 2009)

q0 = 7.5
q0mult = 1.0
t_peak = 2100.0
t_zero = 2150.0
q = ramp_emissions(t_arr, q0, q0mult, 2300.0, 2300.0); # DN flat 7.5 forver

q_effective = effective_emissions(r, q, 0.0, 0.0) # No mitigation, no carbon removal
c_baseline = c(c0, q_effective, dt)

# These CO$_{2e}$ concentrations drive an anomalous greenhouse effect, which is represented by the radiative forcing
# ```math
# F_{M,R,G} = a \ln\left(\frac{c_{M,R}(t)}{c_{0}}\right) - G(t)F_{\infty} \, ,
# ```
# where $a$ is an empirically determined coefficient, $G(t)$ represents the effects of geoengineering, and $F_{\infty} = 8.5$ W/m$^2$ is a scaling factor for the effects of geoengineering by Solar Radiation Modification (SRM).

a = (6.9 / 2.0) / log(2.0); # F4xCO2/2 / log(2) [W m^-2]
Finf = 8.5;

#

F0 = 1.1 # was 3
F_baseline = F(a, c0, Finf, c_baseline, 0.0)

ojs_define(c_baseline=c_baseline)
ojs_define(F_baseline=F_baseline)

F_{M,R,G} = a () - G(t)F_{} , ,

Code
c_baseline
Code
F_baseline
Code
viewof emissions_rate_in = Inputs.range([0,20], {value: 7.5*main.ppm_to_GtC({ppm_to_GtC_in})/**//*ucar 10.5 GtC*/, step:0.001, label: 'emissions rate Gt Carbon'})

viewof ppm_to_GtC_in = Inputs.select([2.3,2.13], {value: 2.13, label: 'ppmv to GtC'})

viewof ฮบ_in = Inputs.range([0,1], {value:0.73,step:0.01, label:'heat exchange coeff'}) // /*heat exchange coeff*/

viewof B_in = Inputs.range([0,2],{value:1.13,step:0.01, 'label': 'feedback param'}) /*feedback param*/
viewof Cd_in = Inputs.range([0,200],{value:106,step:1, 'label': 'Deep ocean heat capacity'}) //"Deep ocean heat capacity" [J m^-2 K^-1] (from default_configuration.jl)


climate_formulae = ['drawdown','temperature','CO2_concentration','concentration_factor','temperature_delta','T_fast','T_slow','ฯ„d','area','darea','T']

embed(
  calcuvizspec({
    models: [main],
    input_cursors: [{emissions_rate_in, ppm_to_GtC_in, ฮบ_in, B_in, Cd_in}],
    mark: 'text',
    encodings: {
      x: {name: 'year_in', type:'nominal', domain: [2015,2016,2017,2020,2025,2030,2060,2090,2100,2200,2205]},
      y: {name: 'climate_sensitivity_in', type: 'nominal', domain: [3.45/*2,3,3.45,4*/]},
      text: {name: 'value', type: 'quantitative', format:',.4f'},
      row: {name: 'formula', type:'nominal', domain: climate_formulae},
      color: {name: 'formula', type:'nominal', domain: climate_formulae, legend: false},
    },
    width: 500, height:50
}))
Code
embed(
  calcuvizspec({
    models: [main],
    input_cursors: [{emissions_rate_in, ppm_to_GtC_in, ฮบ_in, B_in, Cd_in}],
    mark: 'line',
    encodings: {
      x: {name: 'year_in', type:'quantitative', domain: _.range(2015,2205.1,1)},
      color: {name: 'climate_sensitivity_in', type: 'nominal', domain: [2,3,3.45,4], independent:true}, //
      y: {name: 'value', type: 'quantitative', zero: false, independent:true},
      row: {name: 'formula', type:'nominal', domain: ['CO2_concentration','temperature','temperature_delta']},
      //color: {name: 'formula', type:'nominal', domain: climate_formulae, legend: true},
    },
    width: 400, height:200
}))

Diff emissions rates:

Code
viewof f = Inputs.select(['temperature_delta','CO2_concentration'])

embed(
  calcuvizspec({
    models: [main],
    input_cursors: [{emissions_rate_in, ppm_to_GtC_in}],
    mark: 'line',
    encodings: {
      x: {name: 'year_in', type:'quantitative', domain: _.range(2015,2100,3), grid:false},
      column: {name: 'climate_sensitivity_in', type: 'nominal', domain: [2,3,4], independent:'shared'}, //
      y: {name: f, type: 'quantitative', zero: false, independent:false, grid:false},
      color: {name: 'emissions_rate_in', type:'quantitative', domain: _.range(10,3-0.1,-1), scale:{'scheme':'reds'}},
      //color: {name: 'formula', type:'nominal', domain: climate_formulae, legend: true},
    },
    spec_post_process: s => {
      s.encoding.color.title = 'emissions_rate_in (GtC)';
      s.encoding.column.title = 'climate_sensitivity_in (ฮ”T per ppmv doubling)';
      s.encoding.x.axis = {"grid": false, "tickCount":1, "format": "k"};
      return s },
    width: 90, height:140
}))

Appendix

Code
import { calcuvizspec } from "@declann/little-calcu-helpers"
embed = require('vega-embed');

viewof entrypoint = Inputs.select(['models/climate-simple/climate-simple-margo.cul.js'], {label:'entrypoint'})

entrypoint_no_cul_js = entrypoint.slice(0,-7)

main = 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)
|