-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_globals.py
202 lines (178 loc) · 6.36 KB
/
user_globals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
#Created on Wed Mar 20 13:56:43 2024
#@author: shanewhite
"""
########################################################################################
#
# Module: user_globals.py
#
# Description:
# Globals definitions for application world_energy_data.py.
#
########################################################################################
# Import Python modules.
from enum import Enum
import matplotlib.pyplot as plt
# Define custom class of an energy system.
class Global_Carbon:
def __init__(
self,
name,
data,
final_emission_category_shares,
final_emission_shares,
co2_conc,
final_country_shares,
):
self.name = name
self.data = data
self.final_emission_category_shares = final_emission_category_shares
self.final_emission_shares = final_emission_shares
self.co2_conc = co2_conc
self.final_country_shares = final_country_shares
# Define custom class of an energy system.
class Energy_System:
def __init__(
self,
name, # Country name.
incl_ei_flag, # True if country appears in EI data.
incl_iea_flag, # True if country appears in IEA data.
ffco2,
ffprod_PJ,
primary_PJ,
primary_final_category_shares,
primary_final_fuel_shares,
elecprod_TWh,
elecprod_PWh,
elecprod_final_category_shares,
elecprod_final_fuel_shares,
consumption_PJ,
consumption_final_shares,
):
self.name = name
self.incl_ei_flag = incl_ei_flag
self.incl_iea_flag = incl_iea_flag
self.ffco2 = ffco2
self.ffprod_PJ = ffprod_PJ
self.primary_PJ = primary_PJ
self.primary_final_category_shares = primary_final_category_shares
self.primary_final_fuel_shares = primary_final_fuel_shares
self.elecprod_TWh = elecprod_TWh
self.elecprod_PWh = elecprod_PWh
self.elecprod_final_category_shares = elecprod_final_category_shares
self.elecprod_final_fuel_shares = elecprod_final_fuel_shares
self.consumption_PJ = consumption_PJ
self.consumption_final_shares = consumption_final_shares
# Final share dataframes are required by treemap function.
# Better to separate than to place within another dataframe.
# Define conversion coefficients (multiply for conversion).
class Constant(Enum):
DISPLAY_CHARTS = False # Whether charts are output to display.
CHART_START_YR = 2000 # Start year for all charts except change charts
CHANGE_CHART_START_YR = 2010
C_TO_CO2 = 44 / 12
k_TO_M = 1e-3
G_TO_M = 1e3
TJ_TO_PJ = 1e-3
EJ_TO_PJ = 1e3
PJ_TO_EJ = 1 / 1e3
GJ_TO_PJ = 1e-6
GJ_TO_EJ = 1e-9
TWH_TO_PWH = 1e-3
TONNES_TO_GJ = 41.868 # EI Conversion Factors sheet.
CO2_SHARE_RANK_THRESHOLD = 0.5 # Percent. Defines country as large CO2 emitter.
COAL_SHARE_RANK_THRESHOLD = 5 # Percent. Defines large coal producer.
OIL_SHARE_RANK_THRESHOLD = 2 # Percent. Defines large oil producer.
GAS_SHARE_RANK_THRESHOLD = 1.5 # Percent. Defines large gas producer.
# Processing of IEA data takes a noticeably long time.
# To shorten execution time during testing, set TFC_START_YEAR to 1999
# and TFC_END_YEAR to 2000.
TFC_START_YEAR = 2000
TFC_END_YEAR = 2022 # Most recent year of IEA data is 2022 as of Nov 2024.
# TFC_START_YEAR = 1999
# TFC_END_YEAR = 2000
# Threshold below which column chart displayed as solid line instead for visibility.
COL_TO_LINE = 0.005
# FONT SIZES:
# Options: 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'
SUPTITLE_FONT_SIZE = "large"
TITLE_FONT_SIZE = "xx-large"
TITLE_ADDITION_FONT_SIZE = "medium"
SUBPLOT_TITLE_FONT_SIZE = "large"
SUBPLOT_3ROW_TITLE_FONT_SIZE = "medium"
FOOTER_TEXT_FONT_SIZE = "small"
# FONT WEIGHTS:
# Options -
# 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman',
# 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'
SUPTITLE_FONT_WEIGHT = "normal"
TITLE_FONT_WEIGHT = "bold"
TITLE_ADDITION_FONT_WEIGHT = "normal"
SUBPLOT_TITLE_FONT_WEIGHT = "semibold"
FOOTER_TEXT_FONT_WEIGHT = "normal"
FIG_HSIZE_1_ROW = 17
FIG_HSIZE_2_ROW = 17
FIG_HSIZE_1_TREE = 8
FIG_HSIZE_2_TREE = 15
FIG_HSIZE_3_TREE = 17
FIG_HSIZE_CHANGE_SS_COLUMN_PLOT = 12 # For single series plot.
FIG_HSIZE_CHANGE_COLUMN_PLOT = 17
FIG_VSIZE_1_ROW = 5.5
FIG_VSIZE_1_ROW_TALL = 7
FIG_VSIZE_2_ROW = 9
FIG_VSIZE_2x5 = 7
FIG_VSIZE_1_TREE = 9.2
FIG_VSIZE_2_TREE = 9.2
FIG_VSIZE_3_TREE = 6.4
FIG_VSIZE_CHANGE_COLUMN_PLOT = 7
FIG_VSIZE_CHANGE_COLUMN_2_PLOT = 10
LINE_WIDTH_SUBPLOT = 2.2
LINE_WIDTH_0_SUBPLOT = 2.2
LINE_WIDTH_10_SUBPLOT = 1.8
LINE_MARKER_SIZE = 5
LINE_WIDTH_PLOT_1x1 = 4
COLUMN_11_SUBPLOT_TITLE_XPOS = 0.04
COLUMN_11_SUBPLOT_TITLE_YPOS = 0.87
# Define colors for charts.
# Color library: https://matplotlib.org/stable/gallery/color/named_colors.html
class Color(Enum):
CO2_CONC = "cornflowerblue"
CO2_EMISSION = "slategrey"
FOSSIL_FUELS = "grey"
CEMENT = "cadetblue"
LUC = "olivedrab"
COAL = "black"
OIL = "brown"
GAS = "darkorange"
FLARING = "hotpink"
NUCLEAR = "darkviolet"
HYDRO = "dodgerblue"
WIND = "blue"
SOLAR = "crimson"
BIOFUELS_AND_WASTE = "saddlebrown"
OTHER = "peru"
HEAT = "rebeccapurple"
RENEWABLES = "green"
WIND_AND_SOLAR = "limegreen"
ELECTRICITY = "teal"
UNPUBLISHED = "steelblue"
# All prebuilt chart styles: https://python-charts.com/matplotlib/styles/#list
# Python chart gallery: https://python-graph-gallery.com/
# Matplotlib universal settings:
# https://matplotlib.org/stable/api/matplotlib_configuration_api.html#matplotlib.rcParams
rc = {
"xtick.direction": "out",
"xtick.color": "grey",
"xtick.labelcolor": "black",
"ytick.direction": "out",
"ytick.color": "grey",
"ytick.labelcolor": "black",
}
plt.style.use(("bmh", rc))
# Set global font parameters.
# If you add a font to the OS, be sure to delete all matplotlib's font cache files in
# ~/.matplotlib.
plt.rcParams["font.family"] = "sans-serif"
plt.rcParams["font.sans-serif"] = ["SF Pro Display"]