Skip to content

Commit

Permalink
Add new capabilities to assess low/high bounds for fugitive emissions
Browse files Browse the repository at this point in the history
Cherry picks and integrates changes from commit 5c292e9 on fugitive-emissions-2022 branch.
  • Loading branch information
jtlangevin committed Jan 18, 2024
1 parent 74e192e commit bd33c42
Show file tree
Hide file tree
Showing 4 changed files with 925 additions and 358 deletions.
80 changes: 62 additions & 18 deletions ecm_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5423,6 +5423,14 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
opts.fugitive_emissions[0] in ['1', '3'] and (
opts.alt_regions != "State" and
mskeys[3] == "natural gas"):
# Prepare leakage rate sensitivity variable based on
# input options
if opts.fugitive_emissions[1] == '1':
lkg_rate_scenario = "Low"
elif opts.fugitive_emissions[1] == '2':
lkg_rate_scenario = "Mid"
else:
lkg_rate_scenario = "High"
# Prepare fractions needed to map state-resolved
# fugitive methane data to current region
try:
Expand All @@ -5437,10 +5445,12 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
# Apply mapping fractions to develop methane leakage rate
try:
lkg_rate = sum([self.handyvars.fug_emissions[
"methane"]["total_leakage_rate"][state] *
"methane"]["total_leakage_rate"][
lkg_rate_scenario][state] *
reg_weight[state] for state in
self.handyvars.fug_emissions[
"methane"]["total_leakage_rate"].keys()])
"methane"]["total_leakage_rate"][
lkg_rate_scenario].keys()])
except (KeyError):
raise ValueError(
"Inconsistent state keys "
Expand All @@ -5461,7 +5471,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
mskeys[3] == "natural gas":
# Directly pull methane leakage rate for current state
lkg_rate = self.handyvars.fug_emissions[
"methane"]["total_leakage_rate"][mskeys[1]]
"methane"]["total_leakage_rate"][
lkg_rate_scenario][mskeys[1]]
# Handle case where measure is switching away from
# a baseline case with methane leakage to a non-gas tech.
# without such leakage
Expand Down Expand Up @@ -8811,16 +8822,35 @@ def partition_microsegment(
if f_refr_assess:
# Baseline tech. unit-level refrigerant emissions
if f_refr["baseline"][0] is not None:
# Find key to use in pulling global warming potential
# value for the typical baseline tech. refrigerant; typical
# refrigerants may be stored as a dict keyed in by year
if type(f_refr["baseline"][0]["typ_refrigerant"]) == dict:
r_key_b = f_refr["baseline"][0]["typ_refrigerant"][[
y for y in f_refr["baseline"][0][
"typ_refrigerant"].keys() if
int(yr) >= int(y)][-1]]
else:
r_key_b = f_refr["baseline"][0]["typ_refrigerant"]
# Case where user assumes typical refrigerants do not phase
# out
if opts.fugitive_emissions[1] == '1':
# Find key to use in pulling global warming potential
# value for the typical baseline tech. refrigerant
if (type(f_refr["baseline"][0][
"typ_refrigerant"]) == dict):
r_key_b = f_refr["baseline"][0][
"typ_refrigerant"][[
y for y in f_refr["baseline"][0][
"typ_refrigerant"].keys()][0]]
else:
r_key_b = f_refr["baseline"][0]["typ_refrigerant"]
# Case where user assumes typical refrigerants have phase-
# out years
elif opts.fugitive_emissions[1] in ['2', '3']:
# Find key to use in pulling global warming potential
# value for the typical baseline tech. refrigerant;
# typical refrigerants may be stored as a dict keyed in
# by year
if (type(f_refr["baseline"][0][
"typ_refrigerant"]) == dict):
r_key_b = f_refr["baseline"][0][
"typ_refrigerant"][
[y for y in f_refr["baseline"][0][
"typ_refrigerant"].keys() if
int(yr) >= int(y)][-1]]
else:
r_key_b = f_refr["baseline"][0]["typ_refrigerant"]
# Use key above to pull baseline tech. refrigerant GWP
try:
base_gwp_yr = self.handyvars.fug_emissions[
Expand All @@ -8836,7 +8866,7 @@ def partition_microsegment(
# Measure tech. unit-level refrigerant emissions
if f_refr["efficient"][0] is not None:
# Case where user assumes measure uses low GWP refrigerant
if opts.fugitive_emissions[1] == '2':
if opts.fugitive_emissions[1] == '3':
# Low GWP refrigerant may be specified as a measure
# attribute; first try to pull from this attribute
try:
Expand Down Expand Up @@ -8880,7 +8910,21 @@ def partition_microsegment(
else:
r_key_e = f_refr["efficient"][0][
"low_gwp_refrigerant"]
# Case where user assumes measure uses typical refrigerant
# Case where user assumes typical refrigerants do
# not phase out
elif opts.fugitive_emissions[1] == '1':
# Find key to use in pulling global warming potential
# value for the typical baseline tech. refrigerant
if (type(f_refr["efficient"][0][
"typ_refrigerant"]) == dict):
r_key_e = f_refr["efficient"][0][
"typ_refrigerant"][[
y for y in f_refr["efficient"][0][
"typ_refrigerant"].keys()][0]]
else:
r_key_e = f_refr["efficient"][0]["typ_refrigerant"]
# Case where user assumes typical refrigerants have phase-
# out years
else:
# Typical refrigerants may be stored as a dict keyed
# in by year
Expand All @@ -8889,11 +8933,11 @@ def partition_microsegment(
r_key_e = f_refr["efficient"][0][
"typ_refrigerant"][
[y for y in f_refr["efficient"][0][
"typ_refrigerant"].keys() if
int(yr) >= int(y)][-1]]
"typ_refrigerant"].keys() if
int(yr) >= int(y)][-1]]
else:
r_key_e = \
f_refr["efficient"][0]["low_gwp_refrigerant"]
f_refr["efficient"][0]["typ_refrigerant"]
# Use key above to pull measure refrigerant GWP
try:
meas_gwp_yr = self.handyvars.fug_emissions[
Expand Down
29 changes: 21 additions & 8 deletions ecm_prep_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def ecm_args(args: list) -> argparse.NameSpace: # noqa: F821


def fill_user_inputs(opts: argparse.NameSpace) -> argparse.NameSpace: # noqa: F821
"""Request additional user inputs through command line prompts and store them
"""Request additional user inputs through command line prompts, store them
Args:
opts (argparse.NameSpace): object in which to store user responses
Expand Down Expand Up @@ -179,7 +179,7 @@ def fill_user_inputs(opts: argparse.NameSpace) -> argparse.NameSpace: # noqa: F
# whether to use typical refrigerants (including representation of expected
# phase-out years) or user-defined low-GWP refrigerants, as applicable
if opts and opts.fugitive_emissions is True:
input_var = [0, None]
input_var = [0, None, None]
# Determine which fugitive emissions setting to use
while input_var[0] not in ['1', '2', '3']:
input_var[0] = input(
Expand All @@ -194,13 +194,26 @@ def fill_user_inputs(opts: argparse.NameSpace) -> argparse.NameSpace: # noqa: F
# In cases where refrigerant emissions are being assessed,
# determine assumptions about typical vs. low-GWP refrigerants
if input_var[0] != '1':
while input_var[1] not in ['1', '2']:
while input_var[1] not in ['1', '2', '3']:
input_var[1] = input(
"\nEnter 1 to assume measures use typical refrigerants, "
"including representation of their phase-out years,\nor 2 "
"to assume measures use low-GWP refrigerants: ")
if input_var[1] not in ['1', '2']:
print('Please try again. Enter either 1 or 2. '
"\nEnter 1 to assume measures use typical refrigerants "
"\nwithout representation of their phase-out years,\nor 2 "
"to include representation of their phase-out years,\nor "
"3 to assume measures use low-GWP refrigerants\n "
"immediately: ")
if input_var[1] not in ['1', '2', '3']:
print('Please try again. Enter either 1, 2, or 3. '
'Use ctrl-c to exit.')
# In cases where methane emissions are being assessed,
# determine assumptions about methane leakage rates
if input_var[0] != '2':
while input_var[2] not in ['1', '2', '3']:
input_var[2] = input(
"\nEnter 1 to assume lower bound methane leakage rates "
"\nor 2 to assume middle bound methane leakage rates, "
"\nor 3 to upper bound methane leakage rates\n ")
if input_var[2] not in ['1', '2', '3']:
print('Please try again. Enter either 1, 2, or 3. '
'Use ctrl-c to exit.')
opts.fugitive_emissions = input_var

Expand Down
Loading

0 comments on commit bd33c42

Please sign in to comment.