Calliope National Scale Example Model

In [1]:
import calliope

# We increase logging verbosity
calliope.set_log_level('INFO')
In [2]:
model = calliope.examples.national_scale()
[2019-05-27 15:04:38] INFO: Model: initialising
[2019-05-27 15:04:38] INFO: Model: preprocessing stage 1 (model_run)
/Users/brynmorp/OneDrive/Projects/project-calliope/repos/calliope/calliope/core/preprocess/model_run.py:233: FutureWarning:

There will be no default cost class for the objective function in v0.7.0 (currently "monetary" with a weight of 1). Explicitly specify the cost class(es) you would like to use under `run.objective_options.cost_class`. E.g. `{"monetary": 1}` to replicate the current default.

[2019-05-27 15:04:38] INFO: Model: preprocessing stage 2 (model_data)
[2019-05-27 15:04:38] INFO: Model: preprocessing complete. Time since start: 0:00:00.797770
In [3]:
# Model inputs can be viewed at `model.inputs`. 
# Variables are indexed over any combination of `techs`, `locs`, `carriers`, `costs` and `timesteps`, 
# although `techs`, `locs`, and `carriers` are often concatenated. 
# e.g. `ccgt`, `region1`, `power` -> `region1::ccgt::power` 
model.inputs
Out[3]:
<xarray.Dataset>
Dimensions:                         (carriers: 1, coordinates: 2, costs: 1, loc_carriers: 5, loc_techs: 15, loc_techs_area: 3, loc_techs_finite_resource: 5, loc_techs_investment_cost: 7, loc_techs_non_conversion: 15, loc_techs_om_cost: 12, loc_techs_store: 4, loc_techs_supply_plus: 3, loc_techs_transmission: 8, locs: 5, techs: 6, timesteps: 120)
Coordinates:
  * loc_techs_area                  (loc_techs_area) object 'region1-1::csp' ... 'region1-2::csp'
  * loc_techs                       (loc_techs) object 'region1-1::free_transmission:region1' ... 'region1::ccgt'
  * loc_techs_supply_plus           (loc_techs_supply_plus) object 'region1-1::csp' ... 'region1-2::csp'
  * locs                            (locs) object 'region1-2' ... 'region2'
  * loc_techs_om_cost               (loc_techs_om_cost) object 'region1-1::free_transmission:region1' ... 'region1::ccgt'
  * coordinates                     (coordinates) object 'lon' 'lat'
  * timesteps                       (timesteps) datetime64[ns] 2005-01-01 ... 2005-01-05T23:00:00
  * loc_techs_transmission          (loc_techs_transmission) object 'region1-1::free_transmission:region1' ... 'region1::free_transmission:region1-3'
  * loc_carriers                    (loc_carriers) object 'region1-3::power' ... 'region1::power'
  * loc_techs_non_conversion        (loc_techs_non_conversion) object 'region1-1::free_transmission:region1' ... 'region1::ccgt'
  * techs                           (techs) object 'battery' ... 'ccgt'
  * carriers                        (carriers) object 'power'
  * costs                           (costs) object 'monetary'
  * loc_techs_store                 (loc_techs_store) object 'region2::battery' ... 'region1-2::csp'
  * loc_techs_investment_cost       (loc_techs_investment_cost) object 'region1::ac_transmission:region2' ... 'region1::ccgt'
  * loc_techs_finite_resource       (loc_techs_finite_resource) object 'region1-2::csp' ... 'region1-3::csp'
Data variables:
    resource_area_max               (loc_techs_area) float64 inf inf inf
    lifetime                        (loc_techs) float64 nan nan ... nan 25.0
    resource                        (loc_techs_finite_resource, timesteps) float64 0.0 ... 0.0
    energy_ramping                  (loc_techs) float64 nan nan nan ... nan 0.8
    storage_cap_max                 (loc_techs_store) float64 inf ... 6.14e+05
    storage_loss                    (loc_techs_store) float64 0.0 ... 0.002
    energy_prod                     (loc_techs) float64 1.0 1.0 1.0 ... 1.0 1.0
    parasitic_eff                   (loc_techs_supply_plus) float64 0.9 0.9 0.9
    resource_unit                   (loc_techs_finite_resource) <U15 'energy_per_area' ... 'energy_per_area'
    resource_eff                    (loc_techs_finite_resource) float64 1.0 ... 1.0
    energy_con                      (loc_techs) float64 1.0 1.0 nan ... 1.0 nan
    force_resource                  (loc_techs_finite_resource) float64 nan ... nan
    energy_eff                      (loc_techs) float64 1.0 1.0 0.4 ... 1.0 0.5
    energy_cap_per_storage_cap_max  (loc_techs_store) int64 4 1 1 1
    energy_cap_max                  (loc_techs) float64 inf inf ... inf 3e+04
    cost_om_prod                    (costs, loc_techs_om_cost) float64 0.0 ... nan
    cost_depreciation_rate          (costs, loc_techs_investment_cost) float64 0.1102 ... 0.1102
    cost_resource_area              (costs, loc_techs_investment_cost) float64 nan ... nan
    cost_resource_cap               (costs, loc_techs_investment_cost) float64 nan ... nan
    cost_energy_cap                 (costs, loc_techs_investment_cost) float64 200.0 ... 750.0
    cost_om_con                     (costs, loc_techs_om_cost) float64 nan ... 0.02
    cost_storage_cap                (costs, loc_techs_investment_cost) float64 nan ... nan
    lookup_remotes                  (loc_techs_transmission) <U36 'region1::free_transmission:region1-1' ... 'region1-3::free_transmission:region1'
    loc_coordinates                 (coordinates, locs) int64 -1 -2 -2 ... 39 40
    colors                          (techs) <U7 '#3B61E3' ... '#E37A72'
    inheritance                     (techs) <U12 'storage' ... 'supply'
    names                           (techs) <U26 'Battery storage' ... 'Combined cycle gas turbine'
    energy_cap_max_systemwide       (techs) float64 nan nan nan nan nan 1e+05
    lookup_loc_carriers             (loc_carriers) <U221 'region1-3::free_transmission:region1::power,region1-3::csp::power' ... 'region1::ac_transmission:region2::power,region1::demand_power::power,region1::free_transmission:region1-1::power,region1::free_transmission:region1-3::power,region1::ccgt::power,region1::free_transmission:region1-2::power'
    lookup_loc_techs                (loc_techs_non_conversion) <U43 'region1-1::free_transmission:region1::power' ... 'region1::ccgt::power'
    lookup_loc_techs_area           (locs) <U14 'region1-2::csp' ... ''
    timestep_resolution             (timesteps) float64 1.0 1.0 1.0 ... 1.0 1.0
    timestep_weights                (timesteps) float64 1.0 1.0 1.0 ... 1.0 1.0
    max_demand_timesteps            (carriers) datetime64[ns] 2005-01-05T16:00:00
Attributes:
    calliope_version:    0.6.4-dev
    applied_overrides:   
    scenario:            None
    defaults:            available_area: null\ncarrier_ratios: {}\ncharge_rat...
    allow_operate_mode:  1
In [4]:
# Individual data variables can be accessed easily, `to_pandas()` reformats the data to look nicer
model.inputs.resource.to_pandas()
Out[4]:
timesteps 2005-01-01 00:00:00 2005-01-01 01:00:00 2005-01-01 02:00:00 2005-01-01 03:00:00 2005-01-01 04:00:00 2005-01-01 05:00:00 2005-01-01 06:00:00 2005-01-01 07:00:00 2005-01-01 08:00:00 2005-01-01 09:00:00 ... 2005-01-05 14:00:00 2005-01-05 15:00:00 2005-01-05 16:00:00 2005-01-05 17:00:00 2005-01-05 18:00:00 2005-01-05 19:00:00 2005-01-05 20:00:00 2005-01-05 21:00:00 2005-01-05 22:00:00 2005-01-05 23:00:00
loc_techs_finite_resource
region1-2::csp 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.009056 0.096755 0.245351 ... 0.000000 0.00000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
region2::demand_power -2254.098 -2131.148 -2090.164 -2131.148 -2172.132 -2172.132 -2213.114 -2295.082000 -2459.016000 -2459.016000 ... -2295.082000 -2459.01600 -2909.836 -2868.852 -2786.886 -2745.902 -2622.950 -2459.016 -2254.098 -2295.082
region1-1::csp 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.021060 0.263805 0.434037 ... 0.322062 0.07927 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
region1::demand_power -25284.480 -24387.440 -23730.656 -23123.040 -23119.600 -23683.280 -24364.720 -25249.968000 -26090.208000 -26870.464000 ... -37078.160000 -38203.12000 -39033.520 -38631.008 -36990.800 -35330.832 -33623.456 -31341.168 -29390.624 -28132.928
region1-3::csp 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000000 0.000000 0.026837 ... 0.118691 0.00000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000

5 rows × 120 columns

In [5]:
# To reformat the array, deconcatenating loc_techs / loc_tech_carriers, you can use model.get_formatted_array()
# You can then apply loc/tech/carrier only operations, like summing information over locations: 
model.get_formatted_array('resource').sum('locs').to_pandas()
Out[5]:
timesteps 2005-01-01 00:00:00 2005-01-01 01:00:00 2005-01-01 02:00:00 2005-01-01 03:00:00 2005-01-01 04:00:00 2005-01-01 05:00:00 2005-01-01 06:00:00 2005-01-01 07:00:00 2005-01-01 08:00:00 2005-01-01 09:00:00 ... 2005-01-05 14:00:00 2005-01-05 15:00:00 2005-01-05 16:00:00 2005-01-05 17:00:00 2005-01-05 18:00:00 2005-01-05 19:00:00 2005-01-05 20:00:00 2005-01-05 21:00:00 2005-01-05 22:00:00 2005-01-05 23:00:00
techs
csp 0.000 0.000 0.00 0.000 0.000 0.000 0.000 0.030116 0.36056 0.706225 ... 0.440753 0.07927 0.000 0.00 0.000 0.000 0.000 0.000 0.000 0.00
demand_power -27538.578 -26518.588 -25820.82 -25254.188 -25291.732 -25855.412 -26577.834 -27545.050000 -28549.22400 -29329.480000 ... -39373.242000 -40662.13600 -41943.356 -41499.86 -39777.686 -38076.734 -36246.406 -33800.184 -31644.722 -30428.01

2 rows × 120 columns

In [6]:
# Solve the model. Results are loaded into `model.results`. 
# By including logging (see package importing), we can see the timing of parts of the run, as well as the solver's log
model.run()
[2019-05-27 15:04:39] INFO: Backend: starting model run
[2019-05-27 15:04:39] INFO: Backend: model generated. Time since start: 0:00:01.779917
[2019-05-27 15:04:39] INFO: Backend: sending model to solver
[2019-05-27 15:04:41] INFO: Backend: solver finished running. Time since start: 0:00:03.054161
[2019-05-27 15:04:41] INFO: Backend: loaded results
[2019-05-27 15:04:41] INFO: Backend: generated solution array. Time since start: 0:00:03.241858
[2019-05-27 15:04:41] INFO: Postprocessing: started
[2019-05-27 15:04:41] INFO: Postprocessing: All values < 1e-10 set to 0 in carrier_con
[2019-05-27 15:04:41] INFO: Postprocessing: Model was feasible, deleting unmet_demand variable
[2019-05-27 15:04:41] INFO: Postprocessing: ended. Time since start: 0:00:03.567733
In [7]:
# Model results are held in the same structure as model inputs. 
# The results consist of the optimal values for all decision variables, including capacities and carrier flow
# There are also results, like system capacity factor and levelised costs, which are calculated in postprocessing
# before being added to the results Dataset

model.results
Out[7]:
<xarray.Dataset>
Dimensions:                     (carriers: 1, costs: 1, loc_tech_carriers_con: 11, loc_tech_carriers_prod: 13, loc_techs: 15, loc_techs_area: 3, loc_techs_cost: 13, loc_techs_investment_cost: 7, loc_techs_om_cost: 12, loc_techs_store: 4, loc_techs_supply_plus: 3, techs: 6, timesteps: 120)
Coordinates:
  * loc_techs_area              (loc_techs_area) object 'region1-1::csp' ... 'region1-2::csp'
  * loc_techs                   (loc_techs) object 'region1-1::free_transmission:region1' ... 'region1::ccgt'
  * loc_techs_supply_plus       (loc_techs_supply_plus) object 'region1-1::csp' ... 'region1-2::csp'
  * loc_techs_om_cost           (loc_techs_om_cost) object 'region1-1::free_transmission:region1' ... 'region1::ccgt'
  * timesteps                   (timesteps) datetime64[ns] 2005-01-01 ... 2005-01-05T23:00:00
  * loc_techs_cost              (loc_techs_cost) object 'region1-1::free_transmission:region1' ... 'region1::ccgt'
  * loc_tech_carriers_con       (loc_tech_carriers_con) object 'region1::ac_transmission:region2::power' ... 'region1::free_transmission:region1-2::power'
  * techs                       (techs) object 'battery' ... 'ccgt'
  * carriers                    (carriers) <U5 'power'
  * costs                       (costs) object 'monetary'
  * loc_techs_store             (loc_techs_store) object 'region2::battery' ... 'region1-2::csp'
  * loc_techs_investment_cost   (loc_techs_investment_cost) object 'region1::ac_transmission:region2' ... 'region1::ccgt'
  * loc_tech_carriers_prod      (loc_tech_carriers_prod) object 'region1::ac_transmission:region2::power' ... 'region1::free_transmission:region1-2::power'
Data variables:
    energy_cap                  (loc_techs) float64 9e+03 2.28e+03 ... 3e+04
    carrier_prod                (loc_tech_carriers_prod, timesteps) float64 0.0 ... 0.0
    carrier_con                 (loc_tech_carriers_con, timesteps) float64 -2.652e+03 ... 0.0
    cost                        (costs, loc_techs_cost) float64 0.0 ... 1.703e+05
    resource_area               (loc_techs_area) float64 1.304e+05 8.486e+03 0.0
    storage_cap                 (loc_techs_store) float64 5.239e+03 ... 0.0
    storage                     (loc_techs_store, timesteps) float64 0.0 ... -0.0
    resource_con                (loc_techs_supply_plus, timesteps) float64 0.0 ... 0.0
    resource_cap                (loc_techs_supply_plus) float64 6.722e+04 ... 0.0
    cost_var                    (costs, loc_techs_om_cost, timesteps) float64 0.0 ... 913.4
    cost_investment             (costs, loc_techs_investment_cost) float64 487.5 ... 3.396e+04
    capacity_factor             (loc_tech_carriers_prod, timesteps) float64 0.0 ... 0.0
    systemwide_capacity_factor  (carriers, techs) float64 0.1317 nan ... 0.9469
    systemwide_levelised_cost   (carriers, costs, techs) float64 0.1 ... 0.04996
    total_levelised_cost        (carriers, costs) float64 0.06701
Attributes:
    calliope_version:       0.6.4-dev
    applied_overrides:      
    scenario:               None
    defaults:               available_area: null\ncarrier_ratios: {}\ncharge_...
    allow_operate_mode:     1
    model_config:           calliope_version: 0.6.4\nname: National-scale exa...
    run_config:             backend: pyomo\nbigM: 1000000.0\ncyclic_storage: ...
    termination_condition:  optimal
    solution_time:          2.253876
    time_finished:          2019-05-27 15:04:41
In [8]:
# We can sum power output over all locations and turn the result into a pandas DataFrame
df_power = model.get_formatted_array('carrier_prod').loc[{'carriers':'power'}].sum('locs').to_pandas().T

#The information about the dataframe tells us about the amount of data it holds in the index and in each column
df_power.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 120 entries, 2005-01-01 00:00:00 to 2005-01-05 23:00:00
Data columns (total 9 columns):
ac_transmission:region1        120 non-null float64
ac_transmission:region2        120 non-null float64
battery                        120 non-null float64
ccgt                           120 non-null float64
csp                            120 non-null float64
free_transmission:region1      120 non-null float64
free_transmission:region1-1    120 non-null float64
free_transmission:region1-2    120 non-null float64
free_transmission:region1-3    120 non-null float64
dtypes: float64(9)
memory usage: 9.4 KB
In [9]:
# Using .head() to see the first few rows of power generation and demand

# Note: power output in ac_transmission:region1 is power received by the high voltage line at any location connected to `r1`

df_power.head()
Out[9]:
techs ac_transmission:region1 ac_transmission:region2 battery ccgt csp free_transmission:region1 free_transmission:region1-1 free_transmission:region1-2 free_transmission:region1-3
timesteps
2005-01-01 00:00:00 2254.098 0.0 0.0 27936.360 0.0 0.0 0.0 0.0 0.0
2005-01-01 01:00:00 2131.148 0.0 0.0 26894.673 0.0 0.0 0.0 0.0 0.0
2005-01-01 02:00:00 2090.164 0.0 0.0 26189.672 0.0 0.0 0.0 0.0 0.0
2005-01-01 03:00:00 2131.148 0.0 0.0 25630.273 0.0 0.0 0.0 0.0 0.0
2005-01-01 04:00:00 2172.132 0.0 0.0 25675.049 0.0 0.0 0.0 0.0 0.0
In [10]:
# We can plot this by using the timeseries plotting functionality.
# The top-left dropdown gives us the chance to scroll through other timeseries data too.

model.plot.timeseries()