Example #1
0
def combine_upstream_and_gen_df(gen_df, upstream_df):
    """
    Combine the generation and upstream dataframes into a single dataframe.
    The emissions represented here are the annutal emissions for all power
    plants. This dataframe would be suitable for further analysis.

    Parameters
    ----------
    gen_df : dataframe
        The generator dataframe, generated by get_gen_plus_netl or
        get_generation_process_df. Note that get_generation_process_df returns
        two dataframes. The intention would be to send the second returned
        dataframe (plant-level emissions) to this routine.
    upstream_df : dataframe
        The upstream dataframe, generated by get_upstream_process_df
    """

    import electricitylci.combinator as combine
    import electricitylci.import_impacts as import_impacts

    print("Combining upstream and generation inventories")
    combined_df = combine.concat_clean_upstream_and_plant(gen_df, upstream_df)
    canadian_gen = import_impacts.generate_canadian_mixes(combined_df)
    combined_df = pd.concat([combined_df, canadian_gen], ignore_index=True)
    return combined_df, canadian_gen
Example #2
0
def get_gen_plus_netl():
    """
    This will combine the netl life cycle data for solar, solar thermal, 
    geothermal, wind, and hydro and will include impacts from construction, etc.
    that would be omitted from the regular sources of emissions. 
    It then generates power plant emissions. The two different dataframes are
    combined to provide a single dataframe representing annual emissions or
    life cycle emissions apportioned over the appropriate number of years for
    all reporting power plants.

    Returns
    -------
    dataframe
    """
    import electricitylci.generation as gen
    from electricitylci.combinator import (
        concat_map_upstream_databases,
        concat_clean_upstream_and_plant,
    )
    import electricitylci.geothermal as geo
    import electricitylci.solar_upstream as solar
    import electricitylci.wind_upstream as wind
    import electricitylci.hydro_upstream as hydro
    import electricitylci.solar_thermal_upstream as solartherm

    eia_gen_year = config.model_specs.eia_gen_year
    print(
        "Generating inventories for geothermal, solar, wind, hydro, and solar thermal..."
    )
    geo_df = geo.generate_upstream_geo(eia_gen_year)
    solar_df = solar.generate_upstream_solar(eia_gen_year)
    wind_df = wind.generate_upstream_wind(eia_gen_year)
    hydro_df = hydro.generate_hydro_emissions()
    solartherm_df = solartherm.generate_upstream_solarthermal(eia_gen_year)
    netl_gen = concat_map_upstream_databases(
        eia_gen_year,
        geo_df,
        solar_df,
        wind_df,
        solartherm_df,
    )
    netl_gen["DataCollection"] = 5
    netl_gen["GeographicalCorrelation"] = 1
    netl_gen["TechnologicalCorrelation"] = 1
    netl_gen["ReliabilityScore"] = 1
    netl_gen = pd.concat([netl_gen, hydro_df[netl_gen.columns]],
                         ignore_index=True,
                         sort=False)
    print("Getting reported emissions for generators...")
    gen_df = gen.create_generation_process_df()
    combined_gen = concat_clean_upstream_and_plant(gen_df, netl_gen)
    return combined_gen
Example #3
0
def get_generation_process_df(regions=None, **kwargs):
    """
    Create a dataframe of emissions from power generation by fuel type in each
    region. kwargs would include the upstream emissions dataframe (upstream_df) if
    upstream emissions are being included.

    Parameters
    ----------
    regions : str, optional
        Regions to include in the analysis (the default is None, which uses the value
        read from a settings YAML file). Other options include "eGRID", "NERC", "BA",
        "US", "FERC", and "EIA"

    Returns
    -------
    DataFrame
        Each row represents information about a single emission from a fuel category
        in a single region. Columns are:

       'Subregion', 'FuelCategory', 'FlowName', 'FlowUUID', 'Compartment',
       'Year', 'Source', 'Unit', 'ElementaryFlowPrimeContext',
       'TechnologicalCorrelation', 'TemporalCorrelation', 'DataCollection',
       'Emission_factor', 'Reliability_Score', 'GeographicalCorrelation',
       'GeomMean', 'GeomSD', 'Maximum', 'Minimum'
    """
    from electricitylci.generation import create_generation_process_df
    from electricitylci.combinator import concat_clean_upstream_and_plant
    if config.model_specs.include_renewable_generation is True:
        generation_process_df = get_gen_plus_netl()
    else:
        generation_process_df = create_generation_process_df()
    if config.model_specs.include_netl_water is True:
        import electricitylci.plant_water_use as water
        water_df = water.generate_plant_water_use(
            config.model_specs.eia_gen_year)
        generation_process_df = concat_clean_upstream_and_plant(
            generation_process_df, water_df)

    if config.model_specs.include_upstream_processes is True:
        try:
            upstream_df = kwargs['upstream_df']
            upstream_dict = kwargs['upstream_dict']
        except KeyError:
            print(
                "A kwarg named 'upstream_dict' must be included if include_upstream_processes"
                "is True")
#        upstream_dict = write_upstream_process_database_to_dict(
#            upstream_df
#        )
#        upstream_dict = write_upstream_dicts_to_jsonld(upstream_dict)
        combined_df, canadian_gen = combine_upstream_and_gen_df(
            generation_process_df, upstream_df)
        gen_plus_fuels = add_fuels_to_gen(generation_process_df, upstream_df,
                                          canadian_gen, upstream_dict)
    else:
        import electricitylci.import_impacts as import_impacts
        canadian_gen_df = import_impacts.generate_canadian_mixes(
            generation_process_df)
        generation_process_df = pd.concat(
            [generation_process_df, canadian_gen_df], ignore_index=True)
        gen_plus_fuels = generation_process_df
        #This change has been made to accomodate the new method of generating
        #consumption mixes for FERC regions. They now pull BAs to provide
        #a more accurate inventory. The tradeoff here is that it's no longer possible
        #to make a FERC region generation mix and also provide the consumption mix.
        #Or it could be possible but would requir running through aggregate twice.


#        generation_process_df = aggregate_gen(
#            gen_plus_fuels, subregion=regions
#        )
    if regions is None:
        regions = config.model_specs.regional_aggregation
    if regions in ["BA", "FERC", "US"]:
        generation_process_df = aggregate_gen(gen_plus_fuels, subregion="BA")
    else:
        generation_process_df = aggregate_gen(gen_plus_fuels,
                                              subregion=regions)
    return generation_process_df