src/ei_mcoe/ei_mcoe.py
def prep_nems(pudl_out):
    """Grab NEMS and groupby plant-fuel.

    Note: There are ~1500 records which have a 0% capacity factor, thus 0 net
    generation, and thus have a calculated fixed cost per MWh of inf.
    """
    nems_df = pd.merge(
        get_nems()
        .groupby(by=['plant_id_eia', 'generator_id',
                     'report_date', 'report_year'])
        [['capacity_factor', 'capacity_mw',
          'fixed_om_kw_87', 'variable_om_mwh_87']]
        .mean().reset_index(),
        pudl_out.gens_eia860().drop(columns=['capacity_mw']),
        on=['plant_id_eia', 'generator_id', 'report_date'],
        how='left',
        validate='1:1'
    )

    # Calculate required fields and adjust cost for inflation.
    nems_df = calc_inflation('nems', 1987, nems_df, 'fixed_om_kw_87')
    nems_df = calc_inflation('nems', 1987, nems_df, 'variable_om_mwh_87')
    nems_df = (
        nems_df[nems_df.plant_id_pudl.notnull()]
        .assign(
            net_generation_mwh_nems=lambda x:
                x.capacity_factor * 8760 * x.capacity_mw,
            fixed_om_19_nems=lambda x:
                x.fixed_om_kw_19_nems * 1000 * x.capacity_mw,
            fixed_om_mwh_19_nems=lambda x:
                x.fixed_om_19_nems / x.net_generation_mwh_nems,
            variable_om_19_nems=lambda x:
                x.variable_om_mwh_19_nems * x.net_generation_mwh_nems,
            # variable_om_mwh_19_nems=lambda x: (x.variable_om_mwh_19_nems),
            fix_var_om_mwh_19_nems=lambda x:
                x.variable_om_mwh_19_nems + x.fixed_om_kw_19_nems,
        )
    )

    nems_agg = (nems_df
                .groupby(by=input_dict['merge_cols_nems'])
                .agg({'variable_om_19_nems': 'sum',
                      'fixed_om_19_nems': 'sum',
                      'capacity_mw': 'sum',
                      'net_generation_mwh_nems': 'sum',
                      }))
    nems_wtav = weighted_average(
        nems_df,
        {'fixed_om_mwh_19_nems': 'net_generation_mwh_nems',
         'variable_om_mwh_19_nems': 'net_generation_mwh_nems',
         'fix_var_om_mwh_19_nems': 'net_generation_mwh_nems',
         # 'fixed_v_total_ratio': 'capacity_mw'
         },
        input_dict['merge_cols_nems'])

    nems_cost_df = (
        pd.merge(nems_agg, nems_wtav,
                 on=input_dict['merge_cols_nems'],
                 how='outer')
        .assign(fixed_v_total_ratio=lambda x: x.fixed_om_19_nems /
                (x.fixed_om_19_nems + x.variable_om_19_nems),
                var_v_total_ratio=lambda x: x.variable_om_19_nems /
                (x.fixed_om_19_nems + x.variable_om_19_nems),
                fix_var_om_19_nems=lambda x:
                    x.fixed_om_19_nems + x.variable_om_19_nems
                )
    )

    return nems_cost_df
Grab NEMS and groupby plant-fuel.

    Note: There are ~1500 records which have a 0% capacity factor, thus 0 net
    generation, and thus have a calculated fixed cost per MWh of inf.
    
Grab NEMS and groupby plant-fuel.
Note: There are ~1500 records which have a 0% capacity factor, thus 0 net
generation, and thus have a calculated fixed cost per MWh of inf.
Grab NEMS and groupby plant - fuel . Note : There are ~1500 records which have a 0% capacity factor thus 0 net generation and thus have a calculated fixed cost per MWh of inf .
def prep_nems(pudl_out):
    nems_df = pd.merge(
        get_nems()
        .groupby(by=['plant_id_eia', 'generator_id',
                     'report_date', 'report_year'])
        [['capacity_factor', 'capacity_mw',
          'fixed_om_kw_87', 'variable_om_mwh_87']]
        .mean().reset_index(),
        pudl_out.gens_eia860().drop(columns=['capacity_mw']),
        on=['plant_id_eia', 'generator_id', 'report_date'],
        how='left',
        validate='1:1'
    )
    nems_df = calc_inflation('nems', 1987, nems_df, 'fixed_om_kw_87')
    nems_df = calc_inflation('nems', 1987, nems_df, 'variable_om_mwh_87')
    nems_df = (
        nems_df[nems_df.plant_id_pudl.notnull()]
        .assign(
            net_generation_mwh_nems=lambda x:
                x.capacity_factor * 8760 * x.capacity_mw,
            fixed_om_19_nems=lambda x:
                x.fixed_om_kw_19_nems * 1000 * x.capacity_mw,
            fixed_om_mwh_19_nems=lambda x:
                x.fixed_om_19_nems / x.net_generation_mwh_nems,
            variable_om_19_nems=lambda x:
                x.variable_om_mwh_19_nems * x.net_generation_mwh_nems,
            fix_var_om_mwh_19_nems=lambda x:
                x.variable_om_mwh_19_nems + x.fixed_om_kw_19_nems,
        )
    )
    nems_agg = (nems_df
                .groupby(by=input_dict['merge_cols_nems'])
                .agg({'variable_om_19_nems': 'sum',
                      'fixed_om_19_nems': 'sum',
                      'capacity_mw': 'sum',
                      'net_generation_mwh_nems': 'sum',
                      }))
    nems_wtav = weighted_average(
        nems_df,
        {'fixed_om_mwh_19_nems': 'net_generation_mwh_nems',
         'variable_om_mwh_19_nems': 'net_generation_mwh_nems',
         'fix_var_om_mwh_19_nems': 'net_generation_mwh_nems',
         },
        input_dict['merge_cols_nems'])
    nems_cost_df = (
        pd.merge(nems_agg, nems_wtav,
                 on=input_dict['merge_cols_nems'],
                 how='outer')
        .assign(fixed_v_total_ratio=lambda x: x.fixed_om_19_nems /
                (x.fixed_om_19_nems + x.variable_om_19_nems),
                var_v_total_ratio=lambda x: x.variable_om_19_nems /
                (x.fixed_om_19_nems + x.variable_om_19_nems),
                fix_var_om_19_nems=lambda x:
                    x.fixed_om_19_nems + x.variable_om_19_nems
                )
    )
    return nems_cost_df
def prep_nems ( pudl_out ) : nems_df = pd . merge ( get_nems ( ) . groupby ( by = [ 'plant_id_eia' , 'generator_id' , 'report_date' , 'report_year' ] ) [ [ 'capacity_factor' , 'capacity_mw' , 'fixed_om_kw_87' , 'variable_om_mwh_87' ] ] . mean ( ) . reset_index ( ) , pudl_out . gens_eia860 ( ) . drop ( columns = [ 'capacity_mw' ] ) , on = [ 'plant_id_eia' , 'generator_id' , 'report_date' ] , how = 'left' , validate = '1:1' ) nems_df = calc_inflation ( 'nems' , 1987 , nems_df , 'fixed_om_kw_87' ) nems_df = calc_inflation ( 'nems' , 1987 , nems_df , 'variable_om_mwh_87' ) nems_df = ( nems_df [ nems_df . plant_id_pudl . notnull ( ) ] . assign ( net_generation_mwh_nems = lambda x : x . capacity_factor * 8760 * x . capacity_mw , fixed_om_19_nems = lambda x : x . fixed_om_kw_19_nems * 1000 * x . capacity_mw , fixed_om_mwh_19_nems = lambda x : x . fixed_om_19_nems / x . net_generation_mwh_nems , variable_om_19_nems = lambda x : x . variable_om_mwh_19_nems * x . net_generation_mwh_nems , fix_var_om_mwh_19_nems = lambda x : x . variable_om_mwh_19_nems + x . fixed_om_kw_19_nems , ) ) nems_agg = ( nems_df . groupby ( by = input_dict [ 'merge_cols_nems' ] ) . agg ( { 'variable_om_19_nems' : 'sum' , 'fixed_om_19_nems' : 'sum' , 'capacity_mw' : 'sum' , 'net_generation_mwh_nems' : 'sum' , } ) ) nems_wtav = weighted_average ( nems_df , { 'fixed_om_mwh_19_nems' : 'net_generation_mwh_nems' , 'variable_om_mwh_19_nems' : 'net_generation_mwh_nems' , 'fix_var_om_mwh_19_nems' : 'net_generation_mwh_nems' , } , input_dict [ 'merge_cols_nems' ] ) nems_cost_df = ( pd . merge ( nems_agg , nems_wtav , on = input_dict [ 'merge_cols_nems' ] , how = 'outer' ) . assign ( fixed_v_total_ratio = lambda x : x . fixed_om_19_nems / ( x . fixed_om_19_nems + x . variable_om_19_nems ) , var_v_total_ratio = lambda x : x . variable_om_19_nems / ( x . fixed_om_19_nems + x . variable_om_19_nems ) , fix_var_om_19_nems = lambda x : x . fixed_om_19_nems + x . variable_om_19_nems ) ) return nems_cost_df
Grab NEMS and groupby plant-fuel.
Grab NEMS and groupby plant - fuel .
"""Grab NEMS and groupby plant-fuel.

    Note: There are ~1500 records which have a 0% capacity factor, thus 0 net
    generation, and thus have a calculated fixed cost per MWh of inf.
    """ # Calculate required fields and adjust cost for inflation. # variable_om_mwh_19_nems=lambda x: (x.variable_om_mwh_19_nems), # 'fixed_v_total_ratio': 'capacity_mw'
pudl_out