Skip to content

Commit

Permalink
add new uncertainty switch; addresses USEPA#248
Browse files Browse the repository at this point in the history
  • Loading branch information
dt-woods committed Aug 12, 2024
1 parent b1a158d commit f3dc105
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 87 deletions.
19 changes: 13 additions & 6 deletions electricitylci/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@
- Separate replace egrid function
- Fix zero division error in aggregate data
- Implement Hawkins-Young uncertainty
- Add uncertainty switch
Created:
2019-06-04
Last edited:
2024-08-09
2024-08-12
"""
__all__ = [
"add_data_collection_score",
Expand Down Expand Up @@ -119,7 +120,11 @@ def _calc_sigma(p_series):
Assumes a 90% confidence level (see :param:`alpha`).
"""
alpha = 0.9
(is_error, sigma) = hawkins_young_sigma(p_series.values, alpha)
if model_specs.calculate_uncertainty:
(is_error, sigma) = hawkins_young_sigma(p_series.values, alpha)
else:
return None

if is_error:
return None
else:
Expand Down Expand Up @@ -1523,7 +1528,7 @@ def turn_data_to_dict(data, upstream_dict):
data["flowProperty"] = ""
data["baseUncertainty"] = ""
data["provider"] = ""
data["FlowType"]="ELEMENTARY_FLOW"
data["FlowType"] = "ELEMENTARY_FLOW"

# Effectively rename 'Unit' to 'unit', 'uncertainty Max/Min' to 'Max/Min'
data["unit"] = data["Unit"]
Expand All @@ -1542,7 +1547,7 @@ def turn_data_to_dict(data, upstream_dict):
# Define products based on compartment label
product_filter=(
(data["Compartment"].str.lower().str.contains("technosphere"))
|(data["Compartment"].str.lower().str.contains("valuable"))
| (data["Compartment"].str.lower().str.contains("valuable"))
)
data.loc[product_filter, "FlowType"] = "PRODUCT_FLOW"

Expand Down Expand Up @@ -1572,7 +1577,7 @@ def turn_data_to_dict(data, upstream_dict):
data["uncertainty"] = ""
for index, row in data.iterrows():
data.at[index, "uncertainty"] = uncertainty_table_creation(
data.loc[index:index, :] # TODO: check this syntax
data.loc[index:index, :]
)
data.at[index, "flow"] = flow_table_creation(
data.loc[index:index, :]
Expand Down Expand Up @@ -1666,13 +1671,15 @@ def olcaschema_genprocess(database, upstream_dict={}, subregion="BA"):
"GeomMean",
"GeomSD",
]
non_agg_cols = [x for x in non_agg_cols if x in database.columns]

# Create a data frame with one massive column of exchanges
database_groupby = database.groupby(by=base_cols)
process_df = pd.DataFrame(
database_groupby[non_agg_cols].apply(
turn_data_to_dict,
(upstream_dict))
(upstream_dict)
)
)
process_df.columns = ["exchanges"]
process_df.reset_index(inplace=True)
Expand Down
8 changes: 7 additions & 1 deletion electricitylci/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ class ModelSpecs:
post_process_generation_emission_factors : bool
Whether to do post processing.
gen_mix_from_model_generation_data : bool, optional
Influences how generation mix process is read when not replacing
eGRID with EIA. Not available in model config.
Defaults to false.
calculate_uncertainty : bool
Whether or not to compute the uncertainty of emission flows.
namestr : str
Absolute path to JSON-LD zip output file.
File name includes the model name and current time stamp and is
Expand Down Expand Up @@ -185,7 +189,9 @@ def __init__(self, model_specs, model_name):
os.path.join(data_dir, self.fuel_name_file))
self.post_process_generation_emission_factors = model_specs[
"post_process_generation_emission_factors"]
self.gen_mix_from_model_generation_data=False
self.gen_mix_from_model_generation_data = False
self.calculate_uncertainty = model_specs.get(
"calculate_uncertainty", True)
self.namestr = (
f"{output_dir}/{model_name}_jsonld_"
f"{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.zip"
Expand Down
37 changes: 22 additions & 15 deletions electricitylci/modelconfig/ELCI_1_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,55 @@ regional_aggregation: 'BA'
# the generation mix.
egrid_year: 2016
eia_gen_year: 2016
replace_egrid: True
replace_egrid: true

# NETL has developed profiles for renewable generation to capture construction
# impacts (e.g., solar PV menufacturing).
include_renewable_generation: True
# impacts (e.g., solar PV manufacturing).
include_renewable_generation: true

# NETL has developed profiles for power plant water use.
include_netl_water: True
include_netl_water: true

# Upstream data from NETL can be included in the outputs.
include_upstream_processes: True
include_upstream_processes: true

inventories_of_interest:
eGRID: 2016
TRI: 2016
NEI: 2016
RCRAInfo: 2015

# Provide uncertainty estimates for emissions.
calculate_uncertainty: true


# GENERATOR FILTERS
# These parameters determine if any power plants are filtered out.
include_only_egrid_facilities_with_positive_generation: True
filter_on_efficiency: True
include_only_egrid_facilities_with_positive_generation: true
filter_on_efficiency: true
egrid_facility_efficiency_filters:
lower_efficiency: 10
upper_efficiency: 100

# ELCI creates life cycle processes for each fuel type. If you only want to
# include power plants with a minimum amount of generation from a single fuel,
# make sure this parameter is set to true.
filter_on_min_plant_percent_generation_from_primary_fuel: True
filter_on_min_plant_percent_generation_from_primary_fuel: true
min_plant_percent_generation_from_primary_fuel_category: 90

# If the parameter above is set to true, one may still want to keep the plants
# that do not meet the threshhold. This setting will mark those power plants as
# that do not meet the threshold. This setting will mark those power plants as
# MIXED and generate life cycle processes for them. Note that the definition
# of mixed is purposefully ambiguous and will mean different things depending
# on the region of aggregation.
keep_mixed_plant_category: True
keep_mixed_plant_category: true

# NEEDS A GOOD DESCRIPTION OF THIS PARAMETER
filter_non_egrid_emission_on_NAICS: True
# To ensure consistency with eGRID, the model applies a filter to remove
# industrial cogeneration facilities from the EIA Form 923 data based on
# their NAICS code (i.e., code 22: Electricity Utilities and Independent
# Power Producers) and by EIA sector numbers 1 and 2. This filter is
# designed to reproduce the same power plants that are listed in eGRID.
filter_non_egrid_emission_on_NAICS: true


# TRANSMISSION AND ELECTRICITY TRADING
Expand All @@ -78,16 +85,16 @@ efficiency_of_distribution_grid: 0.95
# without a surplus trading pool) that is based on eGRID regions or a method
# from NETL that uses an input-output approach using exchange data between
# balancing authorities from EIA.
EPA_eGRID_trading: False
EPA_eGRID_trading: false

# Select between net trading (true) or gross trading (false) between NERC and
# eGRID regions for consumption mix calculations.
net_trading: False
net_trading: false

NETL_IO_trading_year: 2016

# OTHER PARAMETERS

fedelemflowlist_version: 1.0.2
post_process_generation_emission_factors: False
post_process_generation_emission_factors: false
fuel_name_file: fuelname_1.csv
27 changes: 15 additions & 12 deletions electricitylci/modelconfig/ELCI_2020_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ regional_aggregation: 'BA'
# the generation mix.
egrid_year: 2020
eia_gen_year: 2020
replace_egrid: True
replace_egrid: true

# NETL has developed profiles for renewable generation to capture construction
# impacts (e.g., solar PV manufacturing). Set to true to include these impacts.
include_renewable_generation: True
include_renewable_generation: true

# NETL has developed profiles for power plant water use.
# Set to true to include these impacts.
include_netl_water: True
include_netl_water: true

# Upstream data from NETL can be included in the outputs.
include_upstream_processes: True
include_upstream_processes: true

# Inventory vintages taken from StEWI.
# https://github.com/USEPA/standardizedinventories
Expand All @@ -42,34 +42,37 @@ inventories_of_interest:
NEI: 2020
RCRAInfo: 2019

# Provide uncertainty estimates for emissions.
calculate_uncertainty: true


# GENERATOR FILTERS
# These parameters determine if any power plants are filtered out
include_only_egrid_facilities_with_positive_generation: True
filter_on_efficiency: True
include_only_egrid_facilities_with_positive_generation: true
filter_on_efficiency: true
egrid_facility_efficiency_filters:
lower_efficiency: 10
upper_efficiency: 100

# ELCI creates life cycle processes for each fuel type. If you only want to
# include power plants with a minimum amount of generation from a single fuel,
# make sure this parameter is set to true.
filter_on_min_plant_percent_generation_from_primary_fuel: True
filter_on_min_plant_percent_generation_from_primary_fuel: true
min_plant_percent_generation_from_primary_fuel_category: 90

# If the parameter above is set to true, one may still want to keep the plants
# that do not meet the threshold. This setting will mark those power plants as
# MIXED and generate life cycle processes for them. Note that the definition
# of mixed is purposefully ambiguous and will mean different things depending
# on the region of aggregation.
keep_mixed_plant_category: True
keep_mixed_plant_category: true

# To ensure consistency with eGRID, the model applies a filter to remove
# industrial cogeneration facilities from the EIA Form 923 data based on
# their NAICS code (i.e., code 22: Electricity Utilities and Independent
# Power Producers) and by EIA sector numbers 1 and 2. This filter is
# designed to reproduce the same power plants that are listed in eGRID.
filter_non_egrid_emission_on_NAICS: True
filter_non_egrid_emission_on_NAICS: true


# TRANSMISSION AND ELECTRICITY TRADING
Expand All @@ -85,18 +88,18 @@ efficiency_of_distribution_grid: 0.95
# without a surplus trading pool) that is based on eGRID regions or a method
# from NETL that uses an input-output approach using exchange data between
# balancing authorities from EIA. If false, net trading is used.
EPA_eGRID_trading: False
EPA_eGRID_trading: false

# For net trading, select between two options for for consumption mix
# calculations: net trading (true) or gross trading (false) between NERC
# and eGRID regions.
net_trading: False
net_trading: false

# Trading year for EIA data used for net trading.
NETL_IO_trading_year: 2020

# OTHER PARAMETERS

fedelemflowlist_version: 1.0.3
post_process_generation_emission_factors: False
post_process_generation_emission_factors: false
fuel_name_file: fuelname_1.csv
27 changes: 15 additions & 12 deletions electricitylci/modelconfig/ELCI_2021_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ regional_aggregation: 'BA'
# the generation mix.
egrid_year: 2021
eia_gen_year: 2021
replace_egrid: True
replace_egrid: true

# NETL has developed profiles for renewable generation to capture construction
# impacts (e.g., solar PV manufacturing). Set to true to include these impacts.
include_renewable_generation: True
include_renewable_generation: true

# NETL has developed profiles for power plant water use.
# Set to true to include these impacts.
include_netl_water: True
include_netl_water: true

# Upstream data from NETL can be included in the outputs.
include_upstream_processes: True
include_upstream_processes: true

# Inventory vintages taken from StEWI.
# https://github.com/USEPA/standardizedinventories
Expand All @@ -42,34 +42,37 @@ inventories_of_interest:
NEI: 2020
RCRAInfo: 2019

# Provide uncertainty estimates for emissions.
calculate_uncertainty: true


# GENERATOR FILTERS
# These parameters determine if any power plants are filtered out
include_only_egrid_facilities_with_positive_generation: True
filter_on_efficiency: True
include_only_egrid_facilities_with_positive_generation: true
filter_on_efficiency: true
egrid_facility_efficiency_filters:
lower_efficiency: 10
upper_efficiency: 100

# ELCI creates life cycle processes for each fuel type. If you only want to
# include power plants with a minimum amount of generation from a single fuel,
# make sure this parameter is set to true.
filter_on_min_plant_percent_generation_from_primary_fuel: True
filter_on_min_plant_percent_generation_from_primary_fuel: true
min_plant_percent_generation_from_primary_fuel_category: 90

# If the parameter above is set to true, one may still want to keep the plants
# that do not meet the threshold. This setting will mark those power plants as
# MIXED and generate life cycle processes for them. Note that the definition
# of mixed is purposefully ambiguous and will mean different things depending
# on the region of aggregation.
keep_mixed_plant_category: True
keep_mixed_plant_category: true

# To ensure consistency with eGRID, the model applies a filter to remove
# industrial cogeneration facilities from the EIA Form 923 data based on
# their NAICS code (i.e., code 22: Electricity Utilities and Independent
# Power Producers) and by EIA sector numbers 1 and 2. This filter is
# designed to reproduce the same power plants that are listed in eGRID.
filter_non_egrid_emission_on_NAICS: True
filter_non_egrid_emission_on_NAICS: true


# TRANSMISSION AND ELECTRICITY TRADING
Expand All @@ -85,18 +88,18 @@ efficiency_of_distribution_grid: 0.95
# without a surplus trading pool) that is based on eGRID regions or a method
# from NETL that uses an input-output approach using exchange data between
# balancing authorities from EIA. If false, net trading is used.
EPA_eGRID_trading: False
EPA_eGRID_trading: false

# For net trading, select between two options for for consumption mix
# calculations: net trading (true) or gross trading (false) between NERC
# and eGRID regions.
net_trading: False
net_trading: false

# Trading year for EIA data used for net trading.
NETL_IO_trading_year: 2021

# OTHER PARAMETERS

fedelemflowlist_version: 1.0.3
post_process_generation_emission_factors: False
post_process_generation_emission_factors: false
fuel_name_file: fuelname_1.csv
Loading

0 comments on commit f3dc105

Please sign in to comment.