otoole.results package#

Submodules#

otoole.results.result_package module#

class otoole.results.result_package.ResultsPackage(data: Dict[str, DataFrame], input_data: Optional[Dict[str, DataFrame]] = None)[source]#

Bases: Mapping

A package of OSeMOSYS results

Internal data structure is a dictionary of pandas DataFrames

A crude caching function is implemented whereby calculated results are stored in the internal data structure so that each result is only calculated once.

Parameters
  • data (dict) – A dictionary of results data

  • input_data (dict, default=None) – Dictionary of input data

accumulated_new_capacity() DataFrame[source]#

AccumulatedNewCapacity

Parameters

Notes

From the formulation:

r~REGION, t~TECHNOLOGY, y~YEAR,
sum{yy in YEAR: y-yy < OperationalLife[r,t] && y-yy>=0}
    NewCapacity[r,t,yy] ~VALUE;
annual_emissions() DataFrame[source]#

Calculates the annual emissions

Annual Emission are found by multiplying the emission activity ratio (emissions per unit activity) by the rate of activity and the yearsplit

Notes

From the formulation:

sum{t in TECHNOLOGY, l in TIMESLICE, m in MODE_OF_OPERATION:
        EmissionActivityRatio[r,t,e,m,y]<>0}
    RateOfActivity[r,l,t,m,y] * EmissionActivityRatio[r,t,e,m,y]
        * YearSplit[l,y]~VALUE;
annual_fixed_operating_cost() DataFrame[source]#

Compute AnnualFixedOperatingCost result

Notes

From the formulation:

r~REGION, t~TECHNOLOGY, y~YEAR,
FixedCost[r,t,y] *
((sum{yy in YEAR: y-yy < OperationalLife[r,t] && y-yy>=0}
    NewCapacity[r,t,yy]) + ResidualCapacity[r,t,y]) ~VALUE;
annual_technology_emission_by_mode() DataFrame[source]#

AnnualTechnologyEmissionByMode

Notes

From the formulation:

r~REGION, t~TECHNOLOGY, e~EMISSION, m~MODE_OF_OPERATION, y~YEAR,
sum{l in TIMESLICE: EmissionActivityRatio[r,t,e,m,y] <> 0}
    EmissionActivityRatio[r,t,e,m,y] * RateOfActivity[r,l,t,m,y]
        * YearSplit[l,y]
annual_technology_emissions() DataFrame[source]#

Calculates results AnnualTechnologyEmission

Notes

From the formulation:

REGION, TECHNOLOGY, EMISSION, YEAR,
sum{l in TIMESLICE, m in MODE_OF_OPERATION:
    EmissionActivityRatio[r,t,e,m,y]<>0}
EmissionActivityRatio[r,t,e,m,y] * RateOfActivity[r,l,t,m,y]
    * YearSplit[l,y];
annual_variable_operating_cost() DataFrame[source]#

AnnualVariableOperatingCost

Notes

From the formulation:

r~REGION, t~TECHNOLOGY, y~YEAR,
sum{m in MODE_OF_OPERATION, l in TIMESLICE}
    RateOfActivity[r,l,t,m,y]
    * YearSplit[l,y]
    * VariableCost[r,t,m,y] ~VALUE;
capital_investment() DataFrame[source]#

CapitalInvestment

Notes

From the formulation:

r~REGION, t~TECHNOLOGY, y~YEAR,
CapitalCost[r,t,y] * NewCapacity[r,t,y] * CapitalRecoveryFactor[r,t] *
PvAnnuity[r,t] ~VALUE;
property data: Dict[str, DataFrame]#

View the results dictionary

demand() DataFrame[source]#

Demand

Notes

From the formulation:

r~REGION, l~TIMESLICE, f~FUEL, y~YEAR,
SpecifiedAnnualDemand[r,f,y] * SpecifiedDemandProfile[r,f,l,y] ~VALUE;
discounted_tech_emis_pen() DataFrame[source]#

DiscountedTechnologyEmissionsPenalty

Notes

From the formulation:

DiscountedTechnologyEmissionsPenalty[r,t,y] :=
EmissionActivityRatio[r,t,e,m,y] * RateOfActivity[r,l,t,m,y] *
YearSplit[l,y] * EmissionsPenalty[r,e,y] / DiscountFactorMid[r,y]
get_unique_values_from_index(dataframes: List, name: str) List[source]#

Utility function to extract list of unique values

Extract unique values from the same index of the passed dataframes

production_by_technology() DataFrame[source]#

ProductionByTechnology

Notes

From the formulation:

r~REGION, l~TIMESLICE, t~TECHNOLOGY, f~FUEL, y~YEAR,
sum{m in MODE_OF_OPERATION: OutputActivityRatio[r,t,f,m,y] <> 0}
    RateOfActivity[r,l,t,m,y] * OutputActivityRatio[r,t,f,m,y]
    * YearSplit[l,y] ~VALUE;
production_by_technology_annual() DataFrame[source]#

Aggregates production by technology to the annual level

rate_of_product_technology() DataFrame[source]#

Sums up mode of operation for rate of production

Notes

From the formulation:

r~REGION, l~TIMESLICE, t~TECHNOLOGY, f~FUEL, y~YEAR,
sum{m in MODE_OF_OPERATION: OutputActivityRatio[r,t,f,m,y] <> 0}
    RateOfActivity[r,l,t,m,y] * OutputActivityRatio[r,t,f,m,y]~VALUE;
rate_of_production_tech_mode() DataFrame[source]#

RateOfProductionByTechnologyByMode

Notes

From the formulation:

r~REGION, l~TIMESLICE, t~TECHNOLOGY, m~MODE_OF_OPERATION, f~FUEL, y~YEAR,
RateOfActivity[r,l,t,m,y] * OutputActivityRatio[r,t,f,m,y]~VALUE;
rate_of_use_by_technology() DataFrame[source]#

RateOfUseByTechnology

Notes

From the formulation:

r~REGION, l~TIMESLICE, t~TECHNOLOGY, f~FUEL, y~YEAR,
sum{m in MODE_OF_OPERATION: InputActivityRatio[r,t,f,m,y]<>0}
    RateOfActivity[r,l,t,m,y] * InputActivityRatio[r,t,f,m,y]~VALUE;
rate_of_use_by_technology_by_mode() DataFrame[source]#

RateOfUseByTechnologyByMode

Notes

From the formulation:

r~REGION, l~TIMESLICE, t~TECHNOLOGY, m~MODE_OF_OPERATION, f~FUEL, y~YEAR,
RateOfActivity[r,l,t,m,y] * InputActivityRatio[r,t,f,m,y]~VALUE;
property result_cache: Dict[str, DataFrame]#
property result_mapper: Dict[str, DataFrame]#
total_annual_tech_activity_mode() DataFrame[source]#

TotalAnnualTechnologyActivityByMode

Notes

From the formulation:

r~REGION, t~TECHNOLOGY, m~MODE_OF_OPERATION, y~YEAR,
sum{l in TIMESLICE}
    RateOfActivity[r,l,t,m,y] * YearSplit[l,y]~VALUE;
total_capacity_annual() DataFrame[source]#

TotalCapacityAnnual

Notes

From the formulation:

r~REGION, t~TECHNOLOGY, y~YEAR,
ResidualCapacity[r,t,y] +
(sum{yy in YEAR: y-yy < OperationalLife[r,t] && y-yy>=0}
    NewCapacity[r,t,yy])~VALUE;
total_discounted_cost() DataFrame[source]#

TotalDiscountedCost

Notes

From the formulation:

r~REGION, y~YEAR,
sum{t in TECHNOLOGY}
(
    (
        (
            (
                sum{yy in YEAR: y-yy < OperationalLife[r,t] && y-yy>=0}
                NewCapacity[r,t,yy]
            )
            + ResidualCapacity[r,t,y]
        )
        * FixedCost[r,t,y]
        + sum{l in TIMESLICE, m in MODEperTECHNOLOGY[t]}
        RateOfActivity[r,l,t,m,y] * YearSplit[l,y] * VariableCost[r,t,m,y]
    )
    / (DiscountFactorMid[r,y])
    + CapitalCost[r,t,y] * NewCapacity[r,t,y] * CapitalRecoveryFactor[r,t] * PvAnnuity[r,t] / (DiscountFactor[r,y])
    + DiscountedTechnologyEmissionsPenalty[r,t,y] - DiscountedSalvageValue[r,t,y])
    + sum{s in STORAGE}
    (
        CapitalCostStorage[r,s,y] * NewStorageCapacity[r,s,y] / (DiscountFactorStorage[r,s,y])
        - CapitalCostStorage[r,s,y] * NewStorageCapacity[r,s,y] / (DiscountFactorStorage[r,s,y]
    )
) ~VALUE;
total_tech_model_period_activity() DataFrame[source]#

TotalTechnologyModelPeriodActivity

Notes

From the formulation:

ResultsPath & "/TotalTechnologyModelPeriodActivity.csv":
r~REGION, t~TECHNOLOGY,
sum{l in TIMESLICE, m in MODE_OF_OPERATION, y in YEAR}
    RateOfActivity[r,l,t,m,y]*YearSplit[l,y]~VALUE;
total_technology_annual_activity() DataFrame[source]#

TotalTechnologyAnnualActivity

Notes

From the formulation:

ResultsPath & "/TotalTechnologyAnnualActivity.csv":
r~REGION, t~TECHNOLOGY, y~YEAR,
sum{l in TIMESLICE, m in MODE_OF_OPERATION}
    RateOfActivity[r,l,t,m,y] * YearSplit[l,y]~VALUE;
use_by_technology() DataFrame[source]#

UseByTechnology

Notes

From the formulation:

r~REGION, l~TIMESLICE, t~TECHNOLOGY, f~FUEL, y~YEAR,
sum{m in MODE_OF_OPERATION}
    RateOfActivity[r,l,t,m,y]
    * InputActivityRatio[r,t,f,m,y]
    * YearSplit[l,y]~VALUE;
otoole.results.result_package.capital_recovery_factor(regions: List, technologies: List, discount_rate_idv: DataFrame, operational_life: DataFrame) DataFrame[source]#

Calculates the capital recovery factor

Parameters
  • regions (list) –

  • technologies (list) –

  • discount_rate_idv (pd.DataFrame) –

  • operational_life (pd.DataFrame) –

Notes

From the formulation:

param CapitalRecoveryFactor{r in REGION, t in TECHNOLOGY} :=
        (1 - (1 + DiscountRateIdv[r,t])^(-1))/(1 - (1 + DiscountRateIdv[r,t])^(-(OperationalLife[r,t])));
otoole.results.result_package.discount_factor(regions: List, years: List, discount_rate: DataFrame, adj: float = 0.0) DataFrame[source]#

DiscountFactor

Parameters
  • regions (list) –

  • years (list) –

  • discount_rate (pd.DataFrame) –

  • adj (float, default=0.0) – Adjust to beginning of the year (default), mid year (0.5) or end year (1.0)

Notes

From the formulation:

param DiscountFactor{r in REGION, y in YEAR} :=
        (1 + DiscountRate[r]) ^ (y - min{yy in YEAR} min(yy) + 0.0);

param DiscountFactorMid{r in REGION, y in YEAR} :=
        (1 + DiscountRate[r]) ^ (y - min{yy in YEAR} min(yy) + 0.5);
otoole.results.result_package.discount_factor_storage(regions: List, storages: List, years: List, discount_rate_storage: DataFrame, adj: float = 0.0) DataFrame[source]#

DiscountFactorStorage

Parameters
  • regions (list) –

  • storages (list) –

  • years (list) –

  • discount_rate_storage (pd.DataFrame) –

  • adj (float, default=0.0) – Adjust to beginning of the year (default), mid year (0.5) or end year (1.0)

Notes

From the formulation:

param DiscountFactorStorage{r in REGION, s in STORAGE, y in YEAR} :=
        (1 + DiscountRateStorage[r,s]) ^ (y - min{yy in YEAR} min(yy) + 0.0);
otoole.results.result_package.pv_annuity(regions: List, technologies: List, discount_rate: DataFrame, operational_life: DataFrame) DataFrame[source]#

Calculates the present value of an annuity

Parameters
  • regions (list) –

  • technologies (list) –

  • discount_rate (pd.DataFrame) –

  • operational_life (pd.DataFrame) –

Notes

From the formulation:

param PvAnnuity{r in REGION, t in TECHNOLOGY} :=
        (1 - (1 + DiscountRate[r])^(-(OperationalLife[r,t]))) * (1 + DiscountRate[r]) / DiscountRate[r];

otoole.results.results module#

class otoole.results.results.ReadCbc(user_config: Dict[str, Dict])[source]#

Bases: ReadWideResults

Read a CBC solution file into memory

Parameters
  • user_config (Dict[str, Dict]) –

  • results_config (Dict[str, Dict]) –

class otoole.results.results.ReadCplex(user_config: Dict[str, Dict])[source]#

Bases: ReadWideResults

Read a CPLEX solution file into memeory

class otoole.results.results.ReadGlpk(user_config: Dict[str, Dict], glpk_model: Union[str, TextIO])[source]#

Bases: ReadWideResults

Reads a GLPK Solution file into memory

Parameters
  • user_config (Dict[str, Dict]) –

  • glpk_model (Union[str, TextIO]) – Path to GLPK model file. Can be created using the –wglp flag.

read_model(file_path: Union[str, TextIO]) DataFrame[source]#

Reads in a GLPK Model File

Parameters

file_path (Union[str, TextIO]) – Path to GLPK model file. Can be created using the –wglp flag.

Returns

  • pd.DataFrame – ID NUM NAME INDEX

  • 0 i 1 CAa4_Constraint_Capacity “SIMPLICITY,ID,BACKSTOP1,2015”

  • 1 j 2 NewCapacity “SIMPLICITY,WINDPOWER,2039”

Notes

-> GENERAL LAYOUT OF SOLUTION FILE

n p NAME # p = problem instance n z NAME # z = objective function n i ROW NAME # i = constraint name, ROW is the row ordinal number n j COL NAME # j = variable name, COL is the column ordinal number

read_solution(file_path: Union[str, TextIO]) Tuple[Dict[str, Union[str, float]], DataFrame][source]#

Reads a GLPK solution file

Parameters

file_path (Union[str, TextIO]) – Path to GLPK solution file. Can be created using the –write flag

Returns

  • Tuple[Dict[str,Union[str, float]], pd.DataFrame] – Dict[str,Union[str, float]] -> Problem name, status, and objective value pd.DataFrame -> Variables and constraints

  • {“name” (“osemosys”, “status”:”OPTIMAL”, “objective”:4497.31976}) – ID NUM STATUS PRIM DUAL

  • 0 i 1 b 5 0

  • 1 j 2 l 0 2

Notes

-> ROWS IN SOLUTION FILE

i ROW ST PRIM DUAL

ROW is the ordinal number of the row ST is one of: - b = inactive constraint; - l = inequality constraint active on its lower bound; - u = inequality constraint active on its upper bound; - f = active free (unounded) row; - s = active equality constraint. PRIM specifies the row primal value (float) DUAL specifies the row dual value (float)

-> COLUMNS IN SOLUTION FILE

j COL ST PRIM DUAL

COL specifies the column ordinal number ST contains one of the following lower-case letters that specifies the column status in the basic solution: - b = basic variable - l = non-basic variable having its lower bound active - u = non-basic variable having its upper bound active - f = non-basic free (unbounded) variable - s = non-basic fixed variable. PRIM field contains column primal value (float) DUAL field contains the column dual value (float)

class otoole.results.results.ReadGurobi(user_config: Dict[str, Dict])[source]#

Bases: ReadWideResults

Read a Gurobi solution file into memory

class otoole.results.results.ReadResults(user_config: Dict[str, Dict])[source]#

Bases: ReadStrategy

calculate_results(available_results: Dict[str, DataFrame], input_data: Dict[str, DataFrame]) Dict[str, DataFrame][source]#

Populates the results with calculated values using input data

abstract get_results_from_file(filepath, input_data)[source]#
read(filepath: Union[str, TextIO], **kwargs) Tuple[Dict[str, DataFrame], Dict[str, Any]][source]#

Read a solution file from filepath and process using input_data

Parameters
  • filepath (str, TextIO) – A path name or file buffer pointing to the solution file

  • input_data (dict, default=None) – dict of dataframes

Returns

A tuple containing dict of pandas.DataFrames and a dict of default_values

Return type

tuple

class otoole.results.results.ReadWideResults(user_config: Dict[str, Dict])[source]#

Bases: ReadResults

get_results_from_file(filepath, input_data)[source]#
otoole.results.results.check_duplicate_index(df: DataFrame, columns: List, index: List) DataFrame[source]#

Catches pandas error when there are duplicate column indices

otoole.results.results.check_for_duplicates(index: List) bool[source]#
otoole.results.results.identify_duplicate(index: List) Union[int, bool][source]#
otoole.results.results.rename_duplicate_column(index: List) List[source]#

Module contents#