Skip to content

Commit

Permalink
Actually push new sector handling functionality into tool source code.
Browse files Browse the repository at this point in the history
See #157 for long-term fix.

Signed-off-by: MichaelTiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
  • Loading branch information
MichaelTiemannOSC committed Feb 15, 2023
1 parent aac042d commit f2e7623
Show file tree
Hide file tree
Showing 9 changed files with 1,352 additions and 1,337 deletions.
22 changes: 18 additions & 4 deletions ITR/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,36 @@ class ColumnsConfig:


class SectorsConfig:
POWER_UTILITY = "Electricity Utilities"
GAS_UTILITY = "Gas Utilities"
UTILITY = "Utilities"
STEEL = "Steel"
ELECTRICITY = "Electricity Utilities"
ALUMINUM = "Aluminum"
OIL_AND_GAS = "Oil & Gas"
AUTOMOBILE = "Autos"
TRUCKING = "Trucking"
CEMENT = "Cement"
BUILDINGS = "Buildings"
TEXTILES = "Textiles"
CHEMICALS = "Chemicals"
INFORMATION_TECHNOLOGY = "Information Technology"
INDUSTRIALS = "Industrials"
FINANCIALS = "Financials"
HEALTH_CARE = "Health Care"
AUTOMOBILE = "Autos"
OIL_AND_GAS = "Oil & Gas"

@classmethod
def get_configured_sectors(cls) -> List[str]:
"""
Get a list of sectors configured in the tool.
:return: A list of sectors string values
"""
return [SectorsConfig.STEEL, SectorsConfig.ELECTRICITY, SectorsConfig.AUTOMOBILE, SectorsConfig.OIL_AND_GAS]
return [SectorsConfig.POWER_UTILITY, SectorsConfig.GAS_UTILITY, SectorsConfig.UTILITY,
SectorsConfig.STEEL, SectorsConfig.ALUMINUM,
SectorsConfig.OIL_AND_GAS,
SectorsConfig.AUTOMOBILE, SectorsConfig.TRUCKING,
SectorsConfig.CEMENT, SectorsConfig.BUILDINGS,
SectorsConfig.TEXTILES, SectorsConfig.CHEMICALS,
]


class VariablesConfig:
Expand Down
4 changes: 2 additions & 2 deletions ITR/data/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@


# Excel spreadsheets don't have units elaborated, so we translate sectors to units
sector_to_production_metric = {'Electricity Utilities': 'GJ', 'Steel': 'Fe_ton', 'Oil & Gas': 'boe', 'Autos': 'passenger km'}
sector_to_intensity_metric = {'Electricity Utilities': 't CO2/MWh', 'Steel': 't CO2/Fe_ton', 'Oil & Gas': 'kg CO2/boe', 'Autos': 'g CO2/(passenger km)'}
sector_to_production_metric = {'Electricity Utilities': 'GJ', 'Steel': 'Fe_ton', 'Oil & Gas': 'boe', 'Autos': 'pkm'}
sector_to_intensity_metric = {'Electricity Utilities': 't CO2/MWh', 'Steel': 't CO2/Fe_ton', 'Oil & Gas': 'kg CO2/boe', 'Autos': 'g CO2/pkm'}

# TODO: Force validation for excel benchmarks

Expand Down
28 changes: 20 additions & 8 deletions ITR/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,27 @@ def _fixup_year_value_list(self, ListType, u_list, metric, inferred_metric):
return r_list

def _sector_to_production_units(self, sector, region="Global"):
sector_unit_dict = {
'Electricity Utilities': { 'North America':'MWh', 'Global': 'GJ' },
'Gas Utilities': { 'Global': 'PJ' },
'Utilities': { 'Global': 'PJ' },
'Steel': { 'Global': 't Steel' },
'Aluminum': { 'Global': 't Aluminum' },
'Oil & Gas': { 'Global': 'mmboe' },
'Autos': { 'Global': 'pkm' },
'Trucking': { 'Global': 'tkm' },
'Cement': { 'Global': 't Cement' },
'Buildings': { 'Global': 'billion m**2' }, # Should it be 'built m**2' ?
'Textiles': { 'Global': 'billion USD' },
'Chemicals': { 'Global': 'billion USD' },
}
units = None
if sector == 'Electricity Utilities':
units = 'MWh' if region == 'North America' else 'GJ'
elif sector == 'Steel':
units = 'Fe_ton'
elif sector == 'Oil & Gas':
units = 'mmboe'
elif sector == 'Autos':
units = '(passenger km)'
if sector_unit_dict.get(sector):
region_unit_dict = sector_unit_dict[sector]
if region_unit_dict.get(region):
units = region_unit_dict[region]
else:
units = region_unit_dict['Global']
else:
raise ValueError(f"No source of production metrics for {self.company_name}")
return units
Expand Down
15 changes: 8 additions & 7 deletions examples/ITR_UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@


# Emission intensities
benchmark_EI_OECM_file = "benchmark_EI_OECM.json"
benchmark_EI_OECM_PC_file = "benchmark_EI_OECM_PC.json"
benchmark_EI_OECM_S3_file = "benchmark_EI_OECM_S3.json"
benchmark_EI_OECM_file = "benchmark_EI_OECM.json" # Deprecated!
benchmark_EI_TPI_15_file = "benchmark_EI_TPI_1_5_degrees.json"
benchmark_EI_TPI_file = "benchmark_EI_TPI_2_degrees.json"
benchmark_EI_TPI_below_2_file = "benchmark_EI_TPI_below_2_degrees.json"
Expand All @@ -114,16 +114,17 @@

# load default intensity benchmarks
def recalculate_individual_itr(scenario):
if scenario == 'OECM':
benchmark_file = benchmark_EI_OECM_file
elif scenario == 'OECM_PC':
if scenario == 'OECM_PC':
benchmark_file = benchmark_EI_OECM_PC_file
elif scenario == 'OECM_S3':
benchmark_file = benchmark_EI_OECM_S3_file
elif scenario == 'TPI_2_degrees':
benchmark_file = benchmark_EI_TPI_file
elif scenario == 'TPI_15_degrees':
benchmark_file = benchmark_EI_TPI_15_file
elif scenario == 'OECM':
benchmark_file = benchmark_EI_OECM_file
logger.info('OECM scenario is for backward compatibility only. Use OECM_PC instead.')
else:
benchmark_file = benchmark_EI_TPI_below_2_file
# load intensity benchmarks
Expand All @@ -136,7 +137,7 @@ def recalculate_individual_itr(scenario):
return df


initial_portfolio = recalculate_individual_itr('OECM')
initial_portfolio = recalculate_individual_itr('OECM_PC')
amended_portfolio_global = initial_portfolio.copy()
filt_df = initial_portfolio.copy()

Expand Down Expand Up @@ -279,14 +280,14 @@ def dequantify_plotly(px_func, df, **kwargs):
),
dcc.Dropdown(id="scenario-dropdown",
options=[ # 16.05.2022: make this dynamic
{'label': 'OECM 1.5 degrees', 'value': 'OECM'},
{'label': 'OECM (Prod-Centric) 1.5 degC', 'value': 'OECM_PC'},
{'label': 'OECM (Scope 3) 1.5 degC', 'value': 'OECM_S3'},
{'label': 'OECM (Deprecated) 1.5 degrees', 'value': 'OECM'},
{'label': 'TPI 1.5 degrees', 'value': 'TPI_15_degrees'},
{'label': 'TPI 2 degrees', 'value': 'TPI_2_degrees'},
{'label': 'TPI below 2 degrees', 'value': 'TPI_below_2_degrees'}
],
value='OECM',
value='OECM_PC',
clearable=False,
placeholder="Select emission scenario"),
html.Div(id='hidden-div', style={'display': 'none'}),
Expand Down
Binary file added examples/data/20220927 ITR Tool Sample Data.xlsx
Binary file not shown.
Binary file added examples/data/20220927 ITR Tool Test Data.xlsx
Binary file not shown.

0 comments on commit f2e7623

Please sign in to comment.