src/ei_mcoe/ei_mcoe.py
def calc_tech_pct(raw_eia_df, level):
    """Show technology percent at a given aggregation level.

    This function takes in the raw EIA data file and calculates the generation
    technology percent make up of a given level of aggregation based on the
    stated capacity of that generator. For example, if fed "plant", the
    function will calculate what percent of the plant (at the fuel level) is
    made up of boilers vs combined cycle vs. the other technology options.

    Args:
        raw_df (pandas.DataFrame): A DataFrame containing EIA data from the
            pudl_out.mcoe() function that has been run through the prep_raw_
            eia() function.
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.

    Returns:
        pandas.DataFrame: A DataFrame showing the percent breakdown of each
            generation technology type per 'level' (plant or unit broken down
            by fuel). Rows for level, columns for technology type.
    """
    # Map GREET names onto tech description and find totals for level of
    # aggregation specified.
    logger.info(' -- Calculating tech percents')
    greet_df = (
        raw_eia_df.assign(greet_tech=lambda x: x.technology_description
                          .map(tech_rename_greet)
                          .fillna('Not_Specified')))
    # Calculate level totals
    total_df = (
        raw_eia_df.groupby(input_dict[level + '_index_cols'])
        [input_dict['eia_pct_cols']]
        .sum(min_count=1)
        .reset_index()
        .rename(columns={'capacity_mw': 'cap_total_mw',
                         'net_generation_mwh': 'net_gen_total_mwh'}))
    # Merge back to raw data to get sidebyside capacity values for pct calc.
    merge_df1 = (
        pd.merge(greet_df, total_df, on=input_dict[level + '_index_cols'],
                 how='left'))
    # Separate because need to put variable into assign statement. Pivots
    # table so that each row is the level specified and there are columns for
    # each technology type percent. Return with net_gen total to tranform
    # GREET numbers from mwh to annual values.
    merge_df = (
        merge_df1.assign(pct=(merge_df1['net_generation_mwh'] /
                              merge_df1['net_gen_total_mwh'])  # .round(2)
                         )
        .pivot_table('pct', (input_dict[level + '_index_cols'] +
                             ['net_gen_total_mwh', 'cap_total_mw',
                              'nerc_region']),
                     'greet_tech', np.sum)
        .fillna(0)
        .reset_index())
    return merge_df
Show technology percent at a given aggregation level.

    This function takes in the raw EIA data file and calculates the generation
    technology percent make up of a given level of aggregation based on the
    stated capacity of that generator. For example, if fed "plant", the
    function will calculate what percent of the plant (at the fuel level) is
    made up of boilers vs combined cycle vs. the other technology options.

    Args:
        raw_df (pandas.DataFrame): A DataFrame containing EIA data from the
            pudl_out.mcoe() function that has been run through the prep_raw_
            eia() function.
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.

    Returns:
        pandas.DataFrame: A DataFrame showing the percent breakdown of each
            generation technology type per 'level' (plant or unit broken down
            by fuel). Rows for level, columns for technology type.
    
Show technology percent at a given aggregation level.
This function takes in the raw EIA data file and calculates the generation
technology percent make up of a given level of aggregation based on the
stated capacity of that generator. For example, if fed "plant", the
function will calculate what percent of the plant (at the fuel level) is
made up of boilers vs combined cycle vs. the other technology options.
Show technology percent at a given aggregation level . This function takes in the raw EIA data file and calculates the generation technology percent make up of a given level of aggregation based on the stated capacity of that generator . For example if fed " plant " the function will calculate what percent of the plant ( at the fuel level ) is made up of boilers vs combined cycle vs . the other technology options .
def calc_tech_pct(raw_eia_df, level):
    logger.info(' -- Calculating tech percents')
    greet_df = (
        raw_eia_df.assign(greet_tech=lambda x: x.technology_description
                          .map(tech_rename_greet)
                          .fillna('Not_Specified')))
    total_df = (
        raw_eia_df.groupby(input_dict[level + '_index_cols'])
        [input_dict['eia_pct_cols']]
        .sum(min_count=1)
        .reset_index()
        .rename(columns={'capacity_mw': 'cap_total_mw',
                         'net_generation_mwh': 'net_gen_total_mwh'}))
    merge_df1 = (
        pd.merge(greet_df, total_df, on=input_dict[level + '_index_cols'],
                 how='left'))
    merge_df = (
        merge_df1.assign(pct=(merge_df1['net_generation_mwh'] /
                              merge_df1['net_gen_total_mwh'])  
                         )
        .pivot_table('pct', (input_dict[level + '_index_cols'] +
                             ['net_gen_total_mwh', 'cap_total_mw',
                              'nerc_region']),
                     'greet_tech', np.sum)
        .fillna(0)
        .reset_index())
    return merge_df
def calc_tech_pct ( raw_eia_df , level ) : logger . info ( ' -- Calculating tech percents' ) greet_df = ( raw_eia_df . assign ( greet_tech = lambda x : x . technology_description . map ( tech_rename_greet ) . fillna ( 'Not_Specified' ) ) ) total_df = ( raw_eia_df . groupby ( input_dict [ level + '_index_cols' ] ) [ input_dict [ 'eia_pct_cols' ] ] . sum ( min_count = 1 ) . reset_index ( ) . rename ( columns = { 'capacity_mw' : 'cap_total_mw' , 'net_generation_mwh' : 'net_gen_total_mwh' } ) ) merge_df1 = ( pd . merge ( greet_df , total_df , on = input_dict [ level + '_index_cols' ] , how = 'left' ) ) merge_df = ( merge_df1 . assign ( pct = ( merge_df1 [ 'net_generation_mwh' ] / merge_df1 [ 'net_gen_total_mwh' ] ) ) . pivot_table ( 'pct' , ( input_dict [ level + '_index_cols' ] + [ 'net_gen_total_mwh' , 'cap_total_mw' , 'nerc_region' ] ) , 'greet_tech' , np . sum ) . fillna ( 0 ) . reset_index ( ) ) return merge_df
Show technology percent at a given aggregation level.
Show technology percent at a given aggregation level .
"""Show technology percent at a given aggregation level.

    This function takes in the raw EIA data file and calculates the generation
    technology percent make up of a given level of aggregation based on the
    stated capacity of that generator. For example, if fed "plant", the
    function will calculate what percent of the plant (at the fuel level) is
    made up of boilers vs combined cycle vs. the other technology options.

    Args:
        raw_df (pandas.DataFrame): A DataFrame containing EIA data from the
            pudl_out.mcoe() function that has been run through the prep_raw_
            eia() function.
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.

    Returns:
        pandas.DataFrame: A DataFrame showing the percent breakdown of each
            generation technology type per 'level' (plant or unit broken down
            by fuel). Rows for level, columns for technology type.
    """ # Map GREET names onto tech description and find totals for level of # aggregation specified. # Calculate level totals # Merge back to raw data to get sidebyside capacity values for pct calc. # Separate because need to put variable into assign statement. Pivots # table so that each row is the level specified and there are columns for # each technology type percent. Return with net_gen total to tranform # GREET numbers from mwh to annual values. # .round(2)
A DataFrame showing the percent breakdown of each
generation technology type per 'level' (plant or unit broken down
by fuel). Rows for level, columns for technology type.
A DataFrame showing the percent breakdown of each generation technology type per ' level ' ( plant or unit broken down by fuel ) . Rows for level columns for technology type .
pandas.DataFrame
raw_eia_df
level
An string indicating the level of desired aggregation.
Either 'plant-fuel' or 'unit-fuel' are acceptable.
An string indicating the level of desired aggregation . Either ' plant - fuel ' or ' unit - fuel ' are acceptable .
raw_df
A DataFrame containing EIA data from the
pudl_out.mcoe() function that has been run through the prep_raw_
eia() function.
A DataFrame containing EIA data from the pudl_out . mcoe () function that has been run through the prep_raw_ eia () function .