switch_model/generators/core/dispatch.py
def post_solve(instance, outdir):
    """
    Exported files:

    dispatch-wide.csv - Dispatch results timepoints in "wide" format with
    timepoints as rows, generation projects as columns, and dispatch level
    as values

    dispatch.csv - Dispatch results in normalized form where each row
    describes the dispatch of a generation project in one timepoint.

    dispatch_annual_summary.csv - Similar to dispatch.csv, but summarized
    by generation technology and period.

    dispatch_zonal_annual_summary.csv - Similar to dispatch_annual_summary.csv
    but broken out by load zone.

    dispatch_annual_summary.pdf - A figure of annual summary data. Only written
    if the ggplot python library is installed.
    """
    sorted_gen = sorted_robust(instance.GENERATION_PROJECTS)
    write_table(
        instance, instance.TIMEPOINTS,
        output_file=os.path.join(outdir, "dispatch-wide.csv"),
        headings=("timestamp",) + tuple(sorted_gen),
        values=lambda m, t: (m.tp_timestamp[t],) + tuple(
            m.DispatchGen[p, t] if (p, t) in m.GEN_TPS
            else 0.0
            for p in sorted_gen
        )
    )
    del sorted_gen

    def c(func):
        return (value(func(g, t)) for g, t in instance.GEN_TPS)

    # Note we've refactored to create the Dataframe in one
    # line to reduce the overall memory consumption during
    # the most intensive part of post-solve (this function)
    dispatch_full_df = pd.DataFrame({
        "generation_project": c(lambda g, t: g),
        "gen_dbid": c(lambda g, t: instance.gen_dbid[g]),
        "gen_tech": c(lambda g, t: instance.gen_tech[g]),
        "gen_load_zone": c(lambda g, t: instance.gen_load_zone[g]),
        "gen_energy_source": c(lambda g, t: instance.gen_energy_source[g]),
        "timestamp": c(lambda g, t: instance.tp_timestamp[t]),
        "tp_weight_in_year_hrs": c(lambda g, t: instance.tp_weight_in_year[t]),
        "period": c(lambda g, t: instance.tp_period[t]),
        "is_renewable": c(lambda g, t: g in instance.VARIABLE_GENS),
        "DispatchGen_MW": c(lambda g, t: instance.DispatchGen[g, t]),
        "Curtailment_MW": c(lambda g, t:
                            value(instance.DispatchUpperLimit[g, t]) - value(instance.DispatchGen[g, t])),
        "Energy_GWh_typical_yr": c(lambda g, t:
                                   instance.DispatchGen[g, t] * instance.tp_weight_in_year[t] / 1000),
        "VariableOMCost_per_yr": c(lambda g, t:
                                   instance.DispatchGen[g, t] * instance.gen_variable_om[g] *
                                   instance.tp_weight_in_year[t]),
        "DispatchEmissions_tCO2_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissions[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0),
        "DispatchEmissions_tNOx_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissionsNOx[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0),
        "DispatchEmissions_tSO2_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissionsSO2[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0),
        "DispatchEmissions_tCH4_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissionsCH4[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0)
    })
    dispatch_full_df.set_index(["generation_project", "timestamp"], inplace=True)
    write_table(instance, output_file=os.path.join(outdir, "dispatch.csv"), df=dispatch_full_df)

    annual_summary = dispatch_full_df.groupby(['gen_tech', "gen_energy_source", "period"]).sum()
    write_table(instance, output_file=os.path.join(outdir, "dispatch_annual_summary.csv"),
                df=annual_summary,
                columns=["Energy_GWh_typical_yr", "VariableOMCost_per_yr",
                         "DispatchEmissions_tCO2_per_typical_yr", "DispatchEmissions_tNOx_per_typical_yr",
                         "DispatchEmissions_tSO2_per_typical_yr", "DispatchEmissions_tCH4_per_typical_yr"])

    zonal_annual_summary = dispatch_full_df.groupby(
        ['gen_tech', "gen_load_zone", "gen_energy_source", "period"]
    ).sum()
    write_table(
        instance,
        output_file=os.path.join(outdir, "dispatch_zonal_annual_summary.csv"),
        df=zonal_annual_summary,
        columns=["Energy_GWh_typical_yr", "VariableOMCost_per_yr",
                 "DispatchEmissions_tCO2_per_typical_yr", "DispatchEmissions_tNOx_per_typical_yr",
                 "DispatchEmissions_tSO2_per_typical_yr", "DispatchEmissions_tCH4_per_typical_yr"]
    )

    Exported files:

    dispatch-wide.csv - Dispatch results timepoints in "wide" format with
    timepoints as rows, generation projects as columns, and dispatch level
    as values

    dispatch.csv - Dispatch results in normalized form where each row
    describes the dispatch of a generation project in one timepoint.

    dispatch_annual_summary.csv - Similar to dispatch.csv, but summarized
    by generation technology and period.

    dispatch_zonal_annual_summary.csv - Similar to dispatch_annual_summary.csv
    but broken out by load zone.

    dispatch_annual_summary.pdf - A figure of annual summary data. Only written
    if the ggplot python library is installed.
    
Exported files:
dispatch-wide.csv - Dispatch results timepoints in "wide" format with
timepoints as rows, generation projects as columns, and dispatch level
as values

dispatch.csv - Dispatch results in normalized form where each row
describes the dispatch of a generation project in one timepoint.

dispatch_annual_summary.csv - Similar to dispatch.csv, but summarized
by generation technology and period.

dispatch_zonal_annual_summary.csv - Similar to dispatch_annual_summary.csv
but broken out by load zone.

dispatch_annual_summary.pdf - A figure of annual summary data. Only written
if the ggplot python library is installed.
Exported files : dispatch - wide . csv - Dispatch results timepoints in " wide " format with timepoints as rows generation projects as columns and dispatch level as values dispatch . csv - Dispatch results in normalized form where each row describes the dispatch of a generation project in one timepoint . dispatch_annual_summary . csv - Similar to dispatch . csv but summarized by generation technology and period . dispatch_zonal_annual_summary . csv - Similar to dispatch_annual_summary . csv but broken out by load zone . dispatch_annual_summary . pdf - A figure of annual summary data . Only written if the ggplot python library is installed .
def post_solve(instance, outdir):
    sorted_gen = sorted_robust(instance.GENERATION_PROJECTS)
    write_table(
        instance, instance.TIMEPOINTS,
        output_file=os.path.join(outdir, "dispatch-wide.csv"),
        headings=("timestamp",) + tuple(sorted_gen),
        values=lambda m, t: (m.tp_timestamp[t],) + tuple(
            m.DispatchGen[p, t] if (p, t) in m.GEN_TPS
            else 0.0
            for p in sorted_gen
        )
    )
    del sorted_gen
    def c(func):
        return (value(func(g, t)) for g, t in instance.GEN_TPS)
    dispatch_full_df = pd.DataFrame({
        "generation_project": c(lambda g, t: g),
        "gen_dbid": c(lambda g, t: instance.gen_dbid[g]),
        "gen_tech": c(lambda g, t: instance.gen_tech[g]),
        "gen_load_zone": c(lambda g, t: instance.gen_load_zone[g]),
        "gen_energy_source": c(lambda g, t: instance.gen_energy_source[g]),
        "timestamp": c(lambda g, t: instance.tp_timestamp[t]),
        "tp_weight_in_year_hrs": c(lambda g, t: instance.tp_weight_in_year[t]),
        "period": c(lambda g, t: instance.tp_period[t]),
        "is_renewable": c(lambda g, t: g in instance.VARIABLE_GENS),
        "DispatchGen_MW": c(lambda g, t: instance.DispatchGen[g, t]),
        "Curtailment_MW": c(lambda g, t:
                            value(instance.DispatchUpperLimit[g, t]) - value(instance.DispatchGen[g, t])),
        "Energy_GWh_typical_yr": c(lambda g, t:
                                   instance.DispatchGen[g, t] * instance.tp_weight_in_year[t] / 1000),
        "VariableOMCost_per_yr": c(lambda g, t:
                                   instance.DispatchGen[g, t] * instance.gen_variable_om[g] *
                                   instance.tp_weight_in_year[t]),
        "DispatchEmissions_tCO2_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissions[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0),
        "DispatchEmissions_tNOx_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissionsNOx[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0),
        "DispatchEmissions_tSO2_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissionsSO2[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0),
        "DispatchEmissions_tCH4_per_typical_yr": c(lambda g, t:
                                                   sum(
                                                       instance.DispatchEmissionsCH4[g, t, f] *
                                                       instance.tp_weight_in_year[t]
                                                       for f in instance.FUELS_FOR_GEN[g]
                                                   ) if instance.gen_uses_fuel[g] else 0)
    })
    dispatch_full_df.set_index(["generation_project", "timestamp"], inplace=True)
    write_table(instance, output_file=os.path.join(outdir, "dispatch.csv"), df=dispatch_full_df)
    annual_summary = dispatch_full_df.groupby(['gen_tech', "gen_energy_source", "period"]).sum()
    write_table(instance, output_file=os.path.join(outdir, "dispatch_annual_summary.csv"),
                df=annual_summary,
                columns=["Energy_GWh_typical_yr", "VariableOMCost_per_yr",
                         "DispatchEmissions_tCO2_per_typical_yr", "DispatchEmissions_tNOx_per_typical_yr",
                         "DispatchEmissions_tSO2_per_typical_yr", "DispatchEmissions_tCH4_per_typical_yr"])
    zonal_annual_summary = dispatch_full_df.groupby(
        ['gen_tech', "gen_load_zone", "gen_energy_source", "period"]
    ).sum()
    write_table(
        instance,
        output_file=os.path.join(outdir, "dispatch_zonal_annual_summary.csv"),
        df=zonal_annual_summary,
        columns=["Energy_GWh_typical_yr", "VariableOMCost_per_yr",
                 "DispatchEmissions_tCO2_per_typical_yr", "DispatchEmissions_tNOx_per_typical_yr",
                 "DispatchEmissions_tSO2_per_typical_yr", "DispatchEmissions_tCH4_per_typical_yr"]
    )
def post_solve ( instance , outdir ) : sorted_gen = sorted_robust ( instance . GENERATION_PROJECTS ) write_table ( instance , instance . TIMEPOINTS , output_file = os . path . join ( outdir , "dispatch-wide.csv" ) , headings = ( "timestamp" , ) + tuple ( sorted_gen ) , values = lambda m , t : ( m . tp_timestamp [ t ] , ) + tuple ( m . DispatchGen [ p , t ] if ( p , t ) in m . GEN_TPS else 0.0 for p in sorted_gen ) ) del sorted_gen def c ( func ) : return ( value ( func ( g , t ) ) for g , t in instance . GEN_TPS ) dispatch_full_df = pd . DataFrame ( { "generation_project" : c ( lambda g , t : g ) , "gen_dbid" : c ( lambda g , t : instance . gen_dbid [ g ] ) , "gen_tech" : c ( lambda g , t : instance . gen_tech [ g ] ) , "gen_load_zone" : c ( lambda g , t : instance . gen_load_zone [ g ] ) , "gen_energy_source" : c ( lambda g , t : instance . gen_energy_source [ g ] ) , "timestamp" : c ( lambda g , t : instance . tp_timestamp [ t ] ) , "tp_weight_in_year_hrs" : c ( lambda g , t : instance . tp_weight_in_year [ t ] ) , "period" : c ( lambda g , t : instance . tp_period [ t ] ) , "is_renewable" : c ( lambda g , t : g in instance . VARIABLE_GENS ) , "DispatchGen_MW" : c ( lambda g , t : instance . DispatchGen [ g , t ] ) , "Curtailment_MW" : c ( lambda g , t : value ( instance . DispatchUpperLimit [ g , t ] ) - value ( instance . DispatchGen [ g , t ] ) ) , "Energy_GWh_typical_yr" : c ( lambda g , t : instance . DispatchGen [ g , t ] * instance . tp_weight_in_year [ t ] / 1000 ) , "VariableOMCost_per_yr" : c ( lambda g , t : instance . DispatchGen [ g , t ] * instance . gen_variable_om [ g ] * instance . tp_weight_in_year [ t ] ) , "DispatchEmissions_tCO2_per_typical_yr" : c ( lambda g , t : sum ( instance . DispatchEmissions [ g , t , f ] * instance . tp_weight_in_year [ t ] for f in instance . FUELS_FOR_GEN [ g ] ) if instance . gen_uses_fuel [ g ] else 0 ) , "DispatchEmissions_tNOx_per_typical_yr" : c ( lambda g , t : sum ( instance . DispatchEmissionsNOx [ g , t , f ] * instance . tp_weight_in_year [ t ] for f in instance . FUELS_FOR_GEN [ g ] ) if instance . gen_uses_fuel [ g ] else 0 ) , "DispatchEmissions_tSO2_per_typical_yr" : c ( lambda g , t : sum ( instance . DispatchEmissionsSO2 [ g , t , f ] * instance . tp_weight_in_year [ t ] for f in instance . FUELS_FOR_GEN [ g ] ) if instance . gen_uses_fuel [ g ] else 0 ) , "DispatchEmissions_tCH4_per_typical_yr" : c ( lambda g , t : sum ( instance . DispatchEmissionsCH4 [ g , t , f ] * instance . tp_weight_in_year [ t ] for f in instance . FUELS_FOR_GEN [ g ] ) if instance . gen_uses_fuel [ g ] else 0 ) } ) dispatch_full_df . set_index ( [ "generation_project" , "timestamp" ] , inplace = True ) write_table ( instance , output_file = os . path . join ( outdir , "dispatch.csv" ) , df = dispatch_full_df ) annual_summary = dispatch_full_df . groupby ( [ 'gen_tech' , "gen_energy_source" , "period" ] ) . sum ( ) write_table ( instance , output_file = os . path . join ( outdir , "dispatch_annual_summary.csv" ) , df = annual_summary , columns = [ "Energy_GWh_typical_yr" , "VariableOMCost_per_yr" , "DispatchEmissions_tCO2_per_typical_yr" , "DispatchEmissions_tNOx_per_typical_yr" , "DispatchEmissions_tSO2_per_typical_yr" , "DispatchEmissions_tCH4_per_typical_yr" ] ) zonal_annual_summary = dispatch_full_df . groupby ( [ 'gen_tech' , "gen_load_zone" , "gen_energy_source" , "period" ] ) . sum ( ) write_table ( instance , output_file = os . path . join ( outdir , "dispatch_zonal_annual_summary.csv" ) , df = zonal_annual_summary , columns = [ "Energy_GWh_typical_yr" , "VariableOMCost_per_yr" , "DispatchEmissions_tCO2_per_typical_yr" , "DispatchEmissions_tNOx_per_typical_yr" , "DispatchEmissions_tSO2_per_typical_yr" , "DispatchEmissions_tCH4_per_typical_yr" ] )
Exported files:
dispatch-wide.csv - Dispatch results timepoints in "wide" format with
timepoints as rows, generation projects as columns, and dispatch level
as values
Exported files : dispatch - wide . csv - Dispatch results timepoints in " wide " format with timepoints as rows generation projects as columns and dispatch level as values
"""
    Exported files:

    dispatch-wide.csv - Dispatch results timepoints in "wide" format with
    timepoints as rows, generation projects as columns, and dispatch level
    as values

    dispatch.csv - Dispatch results in normalized form where each row
    describes the dispatch of a generation project in one timepoint.

    dispatch_annual_summary.csv - Similar to dispatch.csv, but summarized
    by generation technology and period.

    dispatch_zonal_annual_summary.csv - Similar to dispatch_annual_summary.csv
    but broken out by load zone.

    dispatch_annual_summary.pdf - A figure of annual summary data. Only written
    if the ggplot python library is installed.
    """ # Note we've refactored to create the Dataframe in one # line to reduce the overall memory consumption during # the most intensive part of post-solve (this function)
instance
outdir