diff --git a/electricitylci/generation.py b/electricitylci/generation.py index bf34100..ff12c7b 100644 --- a/electricitylci/generation.py +++ b/electricitylci/generation.py @@ -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", @@ -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: @@ -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"] @@ -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" @@ -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, :] @@ -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) diff --git a/electricitylci/model_config.py b/electricitylci/model_config.py index 6ae6e81..0cdfdc7 100644 --- a/electricitylci/model_config.py +++ b/electricitylci/model_config.py @@ -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 @@ -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" diff --git a/electricitylci/modelconfig/ELCI_1_config.yml b/electricitylci/modelconfig/ELCI_1_config.yml index 1682153..a0cf28e 100644 --- a/electricitylci/modelconfig/ELCI_1_config.yml +++ b/electricitylci/modelconfig/ELCI_1_config.yml @@ -21,17 +21,17 @@ 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 @@ -39,11 +39,14 @@ inventories_of_interest: 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 @@ -51,18 +54,22 @@ egrid_facility_efficiency_filters: # 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 @@ -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 diff --git a/electricitylci/modelconfig/ELCI_2020_config.yml b/electricitylci/modelconfig/ELCI_2020_config.yml index 5462c7c..b49de3f 100644 --- a/electricitylci/modelconfig/ELCI_2020_config.yml +++ b/electricitylci/modelconfig/ELCI_2020_config.yml @@ -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 @@ -42,11 +42,14 @@ 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 @@ -54,7 +57,7 @@ egrid_facility_efficiency_filters: # 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 @@ -62,14 +65,14 @@ min_plant_percent_generation_from_primary_fuel_category: 90 # 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 @@ -85,12 +88,12 @@ 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 @@ -98,5 +101,5 @@ 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 diff --git a/electricitylci/modelconfig/ELCI_2021_config.yml b/electricitylci/modelconfig/ELCI_2021_config.yml index 0cbaca9..b018c9c 100644 --- a/electricitylci/modelconfig/ELCI_2021_config.yml +++ b/electricitylci/modelconfig/ELCI_2021_config.yml @@ -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 @@ -42,11 +42,14 @@ 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 @@ -54,7 +57,7 @@ egrid_facility_efficiency_filters: # 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 @@ -62,14 +65,14 @@ min_plant_percent_generation_from_primary_fuel_category: 90 # 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 @@ -85,12 +88,12 @@ 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 @@ -98,5 +101,5 @@ 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 diff --git a/electricitylci/modelconfig/ELCI_2022_config.yml b/electricitylci/modelconfig/ELCI_2022_config.yml index e00fea6..4471cad 100644 --- a/electricitylci/modelconfig/ELCI_2022_config.yml +++ b/electricitylci/modelconfig/ELCI_2022_config.yml @@ -21,18 +21,18 @@ regional_aggregation: 'BA' # the generation mix. egrid_year: 2021 eia_gen_year: 2022 -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 @@ -42,11 +42,14 @@ inventories_of_interest: NEI: 2020 RCRAInfo: 2019 +# Provide uncertainty estimates for emissions. +calculate_uncertainty: false + # 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 @@ -54,7 +57,7 @@ egrid_facility_efficiency_filters: # 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 @@ -62,14 +65,14 @@ min_plant_percent_generation_from_primary_fuel_category: 90 # 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 @@ -85,12 +88,12 @@ 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: 2022 @@ -98,5 +101,5 @@ NETL_IO_trading_year: 2022 # 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 diff --git a/electricitylci/modelconfig/ELCI_2_config.yml b/electricitylci/modelconfig/ELCI_2_config.yml index 5b184f3..5d74ca9 100644 --- a/electricitylci/modelconfig/ELCI_2_config.yml +++ b/electricitylci/modelconfig/ELCI_2_config.yml @@ -21,17 +21,17 @@ regional_aggregation: 'BA' # the generation mix. egrid_year: 2018 eia_gen_year: 2017 -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: 2018 @@ -40,10 +40,14 @@ inventories_of_interest: RCRAInfo: 2017 +# 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 @@ -51,18 +55,22 @@ egrid_facility_efficiency_filters: # 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 @@ -78,16 +86,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.3 -post_process_generation_emission_factors: False +post_process_generation_emission_factors: false fuel_name_file: fuelname_1.csv diff --git a/electricitylci/modelconfig/ELCI_3_config.yml b/electricitylci/modelconfig/ELCI_3_config.yml index 8426e7b..49c1106 100644 --- a/electricitylci/modelconfig/ELCI_3_config.yml +++ b/electricitylci/modelconfig/ELCI_3_config.yml @@ -21,17 +21,17 @@ regional_aggregation: 'eGRID' # the generation mix. egrid_year: 2016 eia_gen_year: 2016 -replace_egrid: False +replace_egrid: false # 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 @@ -39,10 +39,13 @@ inventories_of_interest: 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 +include_only_egrid_facilities_with_positive_generation: true filter_on_efficiency: True egrid_facility_efficiency_filters: lower_efficiency: 10 @@ -51,18 +54,22 @@ egrid_facility_efficiency_filters: # 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 @@ -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: True +EPA_eGRID_trading: true # 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