src/ei_mcoe/ei_mcoe.py
def calc_pm_value(tech_df, level):
    """Calculate pm2.5 value for the given level of aggregation.

    This function calculates the amount of pm2.5 associated with each unit or
    plant by fuel type by figuring out what kinds of generator technologies are
    used in that aggregation unit and then multiplying their percent make up (
    based on net generation) by net generation (mwh/year) and the values for
    kwh/mwh (1000/1) and ton/g (0.000001/1) to convert to pm2.5 tons/year.

    Args:
        tech_df (pandas.DataFrame): The output of calc_tech_pct() - a DataFrame
            with the percents for each technology (based on capacity) shown as
            columns with rows for each level of aggregation (unit or plant).
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.
    Returns:
        pandas.DataFrame: A DataFrame with the value for pm2.5 in lb/year
            calculated based on tech type values in g/kwh from the GREET model.
    """
    logger.info(' -- Calculating pm2.5 values')
    # Make technology columns into rows; make column for fuel + tech type.
    pm_df = (
        pd.melt(tech_df, (input_dict[level + '_index_cols'] +
                          ['net_gen_total_mwh', 'nerc_region',
                           'cap_total_mw']))
        .assign(pm_id=lambda x: x.fuel_type_code_pudl + '_' + x.greet_tech)
        .rename(columns={"value": "tech_pct"})
    )
    # Must do this part separatly because does not work in assign...
    # Calculate pm2.5 value based on region and technology
    pm_df['pm_g_kwh'] = (
        pm_df.apply(lambda x: (
            cnct_rgn_tech_to_pm_value(x.nerc_region, x.pm_id)),
            axis=1))
    # Must do separately becasue its a series...(don't really understand)
    # the tech_pct from the melt above is the value from calc_tech_pct, so we
    # need to weight the net gen going to each tech type by the tech_pct
    # Go from g/kwh to tons/year
    pm_df = (
        pm_df.assign(
            pm_mass_tons=lambda x: (
                x.tech_pct * x.pm_g_kwh * x.net_gen_total_mwh * 1000 * 0.000001
            ))
        .groupby(input_dict[level + '_index_cols'])['pm_g_kwh', 'pm_mass_tons']
        .sum(min_count=1)
        .reset_index())
    return pm_df
Calculate pm2.5 value for the given level of aggregation.

    This function calculates the amount of pm2.5 associated with each unit or
    plant by fuel type by figuring out what kinds of generator technologies are
    used in that aggregation unit and then multiplying their percent make up (
    based on net generation) by net generation (mwh/year) and the values for
    kwh/mwh (1000/1) and ton/g (0.000001/1) to convert to pm2.5 tons/year.

    Args:
        tech_df (pandas.DataFrame): The output of calc_tech_pct() - a DataFrame
            with the percents for each technology (based on capacity) shown as
            columns with rows for each level of aggregation (unit or plant).
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.
    Returns:
        pandas.DataFrame: A DataFrame with the value for pm2.5 in lb/year
            calculated based on tech type values in g/kwh from the GREET model.
    
Calculate pm2.5 value for the given level of aggregation.
Calculate pm2 . 5 value for the given level of aggregation .
def calc_pm_value(tech_df, level):
    logger.info(' -- Calculating pm2.5 values')
    pm_df = (
        pd.melt(tech_df, (input_dict[level + '_index_cols'] +
                          ['net_gen_total_mwh', 'nerc_region',
                           'cap_total_mw']))
        .assign(pm_id=lambda x: x.fuel_type_code_pudl + '_' + x.greet_tech)
        .rename(columns={"value": "tech_pct"})
    )
    pm_df['pm_g_kwh'] = (
        pm_df.apply(lambda x: (
            cnct_rgn_tech_to_pm_value(x.nerc_region, x.pm_id)),
            axis=1))
    pm_df = (
        pm_df.assign(
            pm_mass_tons=lambda x: (
                x.tech_pct * x.pm_g_kwh * x.net_gen_total_mwh * 1000 * 0.000001
            ))
        .groupby(input_dict[level + '_index_cols'])['pm_g_kwh', 'pm_mass_tons']
        .sum(min_count=1)
        .reset_index())
    return pm_df
def calc_pm_value ( tech_df , level ) : logger . info ( ' -- Calculating pm2.5 values' ) pm_df = ( pd . melt ( tech_df , ( input_dict [ level + '_index_cols' ] + [ 'net_gen_total_mwh' , 'nerc_region' , 'cap_total_mw' ] ) ) . assign ( pm_id = lambda x : x . fuel_type_code_pudl + '_' + x . greet_tech ) . rename ( columns = { "value" : "tech_pct" } ) ) pm_df [ 'pm_g_kwh' ] = ( pm_df . apply ( lambda x : ( cnct_rgn_tech_to_pm_value ( x . nerc_region , x . pm_id ) ) , axis = 1 ) ) pm_df = ( pm_df . assign ( pm_mass_tons = lambda x : ( x . tech_pct * x . pm_g_kwh * x . net_gen_total_mwh * 1000 * 0.000001 ) ) . groupby ( input_dict [ level + '_index_cols' ] ) [ 'pm_g_kwh' , 'pm_mass_tons' ] . sum ( min_count = 1 ) . reset_index ( ) ) return pm_df
Calculate pm2.5 value for the given level of aggregation.
Calculate pm2 . 5 value for the given level of aggregation .
"""Calculate pm2.5 value for the given level of aggregation.

    This function calculates the amount of pm2.5 associated with each unit or
    plant by fuel type by figuring out what kinds of generator technologies are
    used in that aggregation unit and then multiplying their percent make up (
    based on net generation) by net generation (mwh/year) and the values for
    kwh/mwh (1000/1) and ton/g (0.000001/1) to convert to pm2.5 tons/year.

    Args:
        tech_df (pandas.DataFrame): The output of calc_tech_pct() - a DataFrame
            with the percents for each technology (based on capacity) shown as
            columns with rows for each level of aggregation (unit or plant).
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.
    Returns:
        pandas.DataFrame: A DataFrame with the value for pm2.5 in lb/year
            calculated based on tech type values in g/kwh from the GREET model.
    """ # Make technology columns into rows; make column for fuel + tech type. # Must do this part separatly because does not work in assign... # Calculate pm2.5 value based on region and technology # Must do separately becasue its a series...(don't really understand) # the tech_pct from the melt above is the value from calc_tech_pct, so we # need to weight the net gen going to each tech type by the tech_pct # Go from g/kwh to tons/year
A DataFrame with the value for pm2.5 in lb/year
calculated based on tech type values in g/kwh from the GREET model.
A DataFrame with the value for pm2 . 5 in lb / year calculated based on tech type values in g / kwh from the GREET model .
pandas.DataFrame
tech_df
The output of calc_tech_pct() - a DataFrame
with the percents for each technology (based on capacity) shown as
columns with rows for each level of aggregation (unit or plant).
The output of calc_tech_pct () - a DataFrame with the percents for each technology ( based on capacity ) shown as columns with rows for each level of aggregation ( unit or plant ) .
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 .