Skip to content

Commit

Permalink
carbon intensity great tables example
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwoodhull committed Jul 30, 2024
1 parent fa39504 commit 843a420
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/docs/typst/tables/great-tables/2023_cie_power_cons.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Zone,CO2 Intensity,Hydro,Nuclear,Wind,Solar,Geothermal,Biomass,Gas,Coal,Oil,Unknown,Hydro Discharge,Battery Discharge
Sweden,23.46128501,0.435312552,0.29174058,0.213598205,0.00905231,0,0.001934943,0.001616901,0.002284037,1.20E-04,0.044001931,3.37E-04,0
Iceland,27.64152966,0.724137376,0,0,0,0.27586402,0,0,0,1.79E-06,0,0,0
Quebec,30.56990899,0.914572876,0.009331108,0.047134419,9.71E-05,1.84E-06,0.025015002,0.003836545,1.07E-05,1.29E-05,7.95E-05,0,4.37E-08
France,52.73432801,0.105179703,0.642433753,0.104647836,0.048092258,3.52E-06,0.014088511,0.065820679,0.004738863,0.003454775,6.81E-04,0.010860181,0
Ontario,72.60078255,0.260361881,0.518587118,0.080440676,0.004531646,0,0.002384341,0.133519187,1.55E-04,2.82E-07,2.41E-05,0,0
Finland,87.22831754,0.246151138,0.408646271,0.186382412,0.007824817,0,0.066174243,0.022113252,0.052003005,1.00E-04,0.010583202,1.92E-05,0
Tasmania,92.1890272,0.663216796,0,0.192216671,0.057843914,0,0,0.005585102,0.080626115,0,0,0,1.33E-04
New Zealand,94.50564468,0.627582681,5.62E-06,0.073994174,2.49E-05,0.181548723,0,0.061119138,0.035516963,2.77E-05,0.020244562,0,0
Belgium,139.5605448,0.013668479,0.419910244,0.197723307,0.098437281,7.21E-07,0.032965683,0.186617324,0.014573294,0.001045043,0.020571735,0.014476877,0
West Denmark,143.1380408,0.181489083,0.041429642,0.467775664,0.080510333,7.10E-06,0.07464462,0.059221754,0.081830912,0.004474977,0.005634762,0.003076031,0
East Denmark,147.6286591,0.131248475,0.104716335,0.406830141,0.065438189,0,0.143553717,0.042023638,0.071743624,0.011683996,0.022128678,9.22E-04,0
Spain,154.0142537,0.09969906,0.227273313,0.237562165,0.150134943,2.39E-07,0.021247062,0.217965679,0.015788692,0.001904201,0.003163999,0.025265191,0
South Australia,185.7627912,0.010199114,0,0.449961993,0.24542457,0,0,0.218230503,0.069856191,9.57E-04,0,0,0.005213381
Great Britain,199.8104792,0.045834272,0.181239034,0.301926186,0.059607545,4.57E-08,0.050829232,0.332149815,0.012325292,3.44E-04,0.009736427,0.005980374,0
California,257.678732,0.123989435,0.100042977,0.096419088,0.17055086,0.031164503,0.017478187,0.41970878,0.012129465,1.02E-04,0.008942203,2.83E-04,0.019191918
Netherlands,272.809179,0.030186796,0.048566848,0.315753767,0.167656374,1.34E-05,0.050021331,0.276795769,0.090373246,0.008306204,0.010581683,0.001761264,0
New York ISO,279.992946,0.22594502,0.226559596,0.039417192,7.15E-04,0,0.001091576,0.482745941,0.005538419,1.23E-04,0.017781202,3.47E-06,7.12E-06
Italy (North),307.2558542,0.244615333,0.119192177,0.029255242,0.069372174,0.003271406,0.021624102,0.370342992,0.025889108,0.001570806,0.086539443,0.028325907,1.25E-07
Texas,383.1867568,8.28E-04,0.090769558,0.251576503,0.071636563,0,5.82E-07,0.44437107,0.138211735,3.56E-06,0.002600341,0,0
Germany,396.7870709,0.059246857,0.043122592,0.290545677,0.117499352,3.77E-04,0.096291651,0.113309627,0.244769882,0.00481437,0.007452162,0.022569385,0
Western Australia,433.2945402,0,0,0.155240714,0.191426117,0,0.004275849,0.350975922,0.29709105,3.16E-04,0,0,6.64E-04
Alberta,438.9442161,0.029249945,4.04E-04,0.113897357,0.02666683,0,0.026402135,0.675430038,0.081166555,3.29E-04,0.04643415,1.55E-07,0
Victoria,506.4048193,0.062479748,0,0.205928815,0.127014842,0,1.00E-05,0.014187332,0.587999674,4.05E-06,0,2.11E-08,0.002494507
New South Wales,556.312457,0.048672531,0,0.092353062,0.195594575,0,0.001073667,0.021792087,0.639717569,5.83E-05,0,1.17E-06,6.62E-04
India (North),558.2410211,0.212228393,0.02176545,0.015378776,0.077375285,9.83E-08,5.50E-07,0.018729681,0.642839452,9.36E-07,0.011682019,0,0
Queensland,607.0348918,0.020918137,0,0.040105111,0.197967484,0,0.002442345,0.067024275,0.67051114,3.14E-04,0,1.44E-06,7.89E-04
South Africa,700.9980742,0.009413239,0.042068349,0.057471213,0.03199641,0,0,7.87E-05,0.809385111,0.025579845,0.001312838,0.022695992,0
105 changes: 105 additions & 0 deletions tests/docs/typst/tables/great-tables/carbon-intensity.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: "Untitled"
format: typst
execute:
echo: false
keep-md: true
keep-typ: true
---

```{=typst}
#set page(flipped: true, margin: 0.5cm)
#set par(justify: false)
#show table: set text(size: 10pt)
#show figure: set block(breakable: true)
```

```{python}
from great_tables import GT, md, html, system_fonts
import pandas as pd
power_cie_prepared_tbl = pd.read_csv("2023_cie_power_cons.csv")
# Create a Great Tables object
ciep_gt_tbl = GT(data=power_cie_prepared_tbl)
# Apply wider color ranges & formatting
gt_tbl = ciep_gt_tbl \
.fmt_percent(columns=['Hydro', 'Nuclear', 'Wind', 'Solar', 'Geothermal', 'Biomass', 'Gas',
'Coal', 'Oil', 'Unknown', 'Hydro Discharge', 'Battery Discharge'],
decimals=1) \
.fmt_number(columns=['CO2 Intensity'],
decimals=0) \
.data_color(
columns=['CO2 Intensity'],
palette=[
"#00A600", "#E6E600", "#E8C32E", "#D69C4E", "#Dc863B", "sienna", "sienna4", "tomato4", "brown"],
domain=[0, 900]
) \
.data_color(
columns=['Hydro', 'Nuclear', 'Wind', 'Solar','Geothermal'],
palette=["#00A600", "chartreuse3", "chartreuse4", "snow"][::-1],
domain=[0, 1]
) \
.data_color(
columns=['Hydro', 'Geothermal'],
palette=["#00A600", "chartreuse3", "chartreuse4", "snow"][::-1],
domain=[0, 1]
) \
.data_color(
columns=['Biomass'],
palette=["snow", "#EEC900", "#E8C32E", "#D69C4E"],
domain=[0, 0.3]
) \
.data_color(
columns=['Gas', 'Coal', 'Oil'],
palette=["tomato4", "sienna4", "#D69C4E", "#Dc863B", "snow"][::-1],
domain=[0, 1]
) \
.data_color(
columns=['Zone','Unknown', 'Hydro Discharge', 'Battery Discharge'],
palette=["snow", "snow", "snow", 'snow']
) \
.cols_width(
{'Zone': '106px', 'CO2 Intensity': '58px','Hydro': '58px', 'Nuclear': '58px', 'Wind': '58px', 'Solar': '58px',
'Geothermal': '58px', 'Biomass': '58px', 'Gas': '58px', 'Coal': '58px',
'Oil': '58px', 'Unknown': '58px', 'Hydro Discharge': '58px',
'Battery Discharge': '58px'}
) \
.tab_header(
title=md("2023 Mean **Carbon Intensity** (gCO2eq/kWh) and **Power Consumption** Breakdown (%)")
) \
.tab_source_note(
md(
'<br><div style="text-align: left;">'
"**Source**: api.electricitymap.org"
" | **Methodology**: https://www.electricitymaps.com/methodology."
" Some emissions factors are based on IPCC 2014 defaults, while some are based on more accurate regional factors."
" <br>All zones are publicly available on the *Carbon intensity and emission factors* tab via Google docs link<br>"
"</div>"
"<br>"
)
) \
.tab_options(
source_notes_font_size='x-small',
source_notes_padding=3,
table_font_names=system_fonts("humanist"),
data_row_padding='1px',
heading_background_color='antiquewhite',
source_notes_background_color='antiquewhite',
column_labels_background_color='antiquewhite',
table_background_color='snow',
data_row_padding_horizontal=3,
column_labels_padding_horizontal=58
) \
.cols_align(
align='center'
) \
.cols_align(
align='left',
columns=['Zone']
)
gt_tbl
```

0 comments on commit 843a420

Please sign in to comment.