1010from switch_model .financials import capital_recovery_factor as crf
1111import pandas as pd
1212from switch_model .reporting import write_table
13- from switch_model .tools .graph import graph
1413
1514dependencies = (
1615 "switch_model.timescales" ,
@@ -194,21 +193,27 @@ def define_components(mod):
194193 mod .trans_new_build_allowed = Param (
195194 mod .TRANSMISSION_LINES , within = Boolean , default = True
196195 )
196+ mod .trans_capital_cost_per_mw_km = Param (within = NonNegativeReals , default = 1000 )
197197 mod .TRANS_BLD_YRS = Set (
198198 dimen = 2 ,
199199 initialize = mod .TRANSMISSION_LINES * mod .PERIODS ,
200- filter = lambda m , tx , p : m .trans_new_build_allowed [tx ],
200+ filter = lambda m , tx , p : m .trans_new_build_allowed [tx ]
201+ and m .trans_capital_cost_per_mw_km != float ("inf" ),
201202 )
202203 mod .BuildTx = Var (mod .TRANS_BLD_YRS , within = NonNegativeReals )
203- mod .TxCapacityNameplate = Expression (
204+ mod .NewTxCapacity = Expression (
204205 mod .TRANSMISSION_LINES ,
205206 mod .PERIODS ,
206207 rule = lambda m , tx , period : sum (
207208 m .BuildTx [tx , bld_yr ]
208209 for bld_yr in m .PERIODS
209210 if bld_yr <= period and (tx , bld_yr ) in m .TRANS_BLD_YRS
210- )
211- + m .existing_trans_cap [tx ],
211+ ),
212+ )
213+ mod .TxCapacityNameplate = Expression (
214+ mod .TRANSMISSION_LINES ,
215+ mod .PERIODS ,
216+ rule = lambda m , tx , p : m .NewTxCapacity [tx , p ] + m .existing_trans_cap [tx ],
212217 )
213218 mod .trans_derating_factor = Param (
214219 mod .TRANSMISSION_LINES , within = PercentFraction , default = 1
@@ -223,7 +228,6 @@ def define_components(mod):
223228 mod .trans_terrain_multiplier = Param (
224229 mod .TRANSMISSION_LINES , within = NonNegativeReals , default = 1
225230 )
226- mod .trans_capital_cost_per_mw_km = Param (within = NonNegativeReals , default = 1000 )
227231 mod .trans_lifetime_yrs = Param (within = NonNegativeReals , default = 20 )
228232 mod .trans_fixed_om_fraction = Param (within = NonNegativeReals , default = 0.03 )
229233 # Total annual fixed costs for building new transmission lines...
@@ -244,12 +248,16 @@ def define_components(mod):
244248 # function. Units should be total annual future costs in $base_year
245249 # real dollars. The objective function will convert these to
246250 # base_year Net Present Value in $base_year real dollars.
251+ mod .TxLineCosts = Expression (
252+ mod .TRANSMISSION_LINES ,
253+ mod .PERIODS ,
254+ rule = lambda m , tx , p : m .NewTxCapacity [tx , p ] * m .trans_cost_annual [tx ]
255+ if (tx , p ) in m .TRANS_BLD_YRS
256+ else 0 ,
257+ )
247258 mod .TxFixedCosts = Expression (
248259 mod .PERIODS ,
249- rule = lambda m , p : sum (
250- m .TxCapacityNameplate [tx , p ] * m .trans_cost_annual [tx ]
251- for tx in m .TRANSMISSION_LINES
252- ),
260+ rule = lambda m , p : sum (m .TxLineCosts [tx , p ] for tx in m .TRANSMISSION_LINES ),
253261 )
254262 mod .Cost_Components_Per_Period .append ("TxFixedCosts" )
255263
@@ -354,61 +362,41 @@ def load_inputs(mod, switch_data, inputs_dir):
354362
355363def post_solve (instance , outdir ):
356364 mod = instance
357- tx_build_df = pd .DataFrame (
358- [
359- {
360- "TRANSMISSION_LINE" : tx ,
361- "PERIOD" : p ,
362- "trans_lz1" : mod .trans_lz1 [tx ],
363- "trans_lz2" : mod .trans_lz2 [tx ],
364- "trans_dbid" : mod .trans_dbid [tx ],
365- "trans_length_km" : mod .trans_length_km [tx ],
366- "trans_efficiency" : mod .trans_efficiency [tx ],
367- "trans_derating_factor" : mod .trans_derating_factor [tx ],
368- "existing_trans_cap" : mod .existing_trans_cap [tx ],
369- "BuildTx" : value (mod .BuildTx [tx , p ]) if (tx , p ) in mod .BuildTx else "." ,
370- "TxCapacityNameplate" : value (mod .TxCapacityNameplate [tx , p ]),
371- "TxCapacityNameplateAvailable" : value (
372- mod .TxCapacityNameplateAvailable [tx , p ]
373- ),
374- "TotalAnnualCost" : value (
375- mod .TxCapacityNameplate [tx , p ] * mod .trans_cost_annual [tx ]
376- ),
377- }
378- for tx , p in mod .TRANSMISSION_LINES * mod .PERIODS
379- ]
380- )
365+ normalized_dat = [
366+ {
367+ "TRANSMISSION_LINE" : tx ,
368+ "PERIOD" : p ,
369+ "trans_lz1" : mod .trans_lz1 [tx ],
370+ "trans_lz2" : mod .trans_lz2 [tx ],
371+ "trans_dbid" : mod .trans_dbid [tx ],
372+ "trans_length_km" : mod .trans_length_km [tx ],
373+ "trans_efficiency" : mod .trans_efficiency [tx ],
374+ "trans_derating_factor" : mod .trans_derating_factor [tx ],
375+ "existing_trans_cap" : mod .existing_trans_cap [tx ],
376+ "BuildTx" : value (mod .BuildTx [tx , p ]) if (tx , p ) in mod .BuildTx else "." ,
377+ "TxCapacityNameplate" : value (mod .TxCapacityNameplate [tx , p ]),
378+ "TxCapacityNameplateAvailable" : value (
379+ mod .TxCapacityNameplateAvailable [tx , p ]
380+ ),
381+ "TotalAnnualCost" : value (mod .TxLineCosts [tx , p ]),
382+ }
383+ for tx , p in mod .TRANSMISSION_LINES * mod .PERIODS
384+ ]
385+ tx_build_df = pd .DataFrame (normalized_dat )
381386 tx_build_df .set_index (["TRANSMISSION_LINE" , "PERIOD" ], inplace = True )
382387 write_table (
383388 instance , df = tx_build_df , output_file = os .path .join (outdir , "transmission.csv" )
384389 )
385390
386391
387- @graph (
388- "transmission_capacity" ,
389- title = "Transmission capacity per period"
390- )
391392def graph (tools ):
392- transmission = tools .get_dataframe ("transmission" , convert_dot_to_na = True ).fillna (0 )
393- transmission = transmission .groupby ("PERIOD" , as_index = False ).sum ()
394- transmission ["Existing Capacity" ] = (
395- transmission ["TxCapacityNameplate" ] - transmission ["BuildTx" ]
396- )
397- transmission = transmission [["PERIOD" , "Existing Capacity" , "BuildTx" ]]
398- transmission = transmission .set_index ("PERIOD" )
399- transmission = transmission .rename ({"BuildTx" : "New Capacity" }, axis = 1 )
400- transmission *= 1e-3 # Convert to GW
393+ transmission = tools .get_dataframe ("transmission" )
394+ transmission = transmission .groupby ("PERIOD" ).sum ()["TxCapacityNameplate" ]
395+ transmission *= 1e-3
401396
402- < << << << HEAD
403- ax = tools .get_axes (
397+ ax = tools .get_new_axes (
404398 out = "transmission_capacity" , title = "Transmission capacity per period"
405399 )
406- == == == =
407- >> >> >> > b3590fdb (Redesign graphing API )
408400 transmission .plot (
409- kind = "bar" ,
410- stacked = True ,
411- ax = tools .get_axes (),
412- xlabel = "Period" ,
413- ylabel = "Transmission capacity (GW)" ,
401+ kind = "bar" , ax = ax , xlabel = "Period" , ylabel = "Transmission capacity (GW)"
414402 )
0 commit comments