From 1729ed2f8836ab1e6a2d1bbae90f418b221c97a0 Mon Sep 17 00:00:00 2001 From: jdorfner Date: Thu, 18 Aug 2016 11:18:22 +0200 Subject: [PATCH 1/2] report() and get_timeseries() work with get_entity Series --- urbs.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/urbs.py b/urbs.py index 23abff34..18183e9a 100644 --- a/urbs.py +++ b/urbs.py @@ -1525,7 +1525,10 @@ def get_entity(instance, name): # convert to Series results = results[name] - + + # if Series has MultiIndex, sort it to avoid PerformanceWarnings + if isinstance(results.index, pd.core.index.MultiIndex): + results = results.sortlevel() return results @@ -1766,7 +1769,7 @@ def get_timeseries(instance, com, sit, timesteps=None): demand.name = 'Demand' # STOCK - eco = get_entity(instance, 'e_co_stock')['e_co_stock'].unstack()['Stock'] + eco = get_entity(instance, 'e_co_stock').unstack()['Stock'] eco = eco.xs(sit, level='sit').unstack().fillna(0) try: stock = eco.loc[timesteps][com] @@ -1777,23 +1780,19 @@ def get_timeseries(instance, com, sit, timesteps=None): # DEMAND SIDE MANAGEMENT (load shifting) dsmup = get_entity(instance, 'dsm_up') dsmdo = get_entity(instance, 'dsm_down') - # Extract site and commodity timeseries - dsmup = dsmup.xs(sit, level = 'sit') - dsmup = dsmup.xs(com, level = 'com') - # Create series - dsmup = dsmup['dsm_up'] - # Extract site and commodity timeseries - dsmdo = dsmdo.xs(sit, level = 'sit') - dsmdo = dsmdo.xs(com, level = 'com') - # Create series by summing the first time step - dsmdo = dsmdo['dsm_down'].unstack().sum(axis=0) - # Rename index names + + dsmup = dsmup.xs(sit, level = 'sit').xs(com, level = 'com') + dsmdo = dsmdo.xs(sit, level = 'sit').xs(com, level = 'com') + + # series by summing the first time step set + dsmdo = dsmdo.unstack().sum(axis=0) dsmdo.index.names = ['t'] + + # derive secondary timeseries demanddelta = dsmup - dsmdo shifted = demand + demanddelta - - shifted.name = 'Shifted Demand' demanddelta.name = 'Delta of Demand to shifted Demand' + shifted.name = 'Shifted Demand' # PROCESS # select all entries of created and consumed desired commodity com and site @@ -1883,7 +1882,7 @@ def report(instance, filename, commodities=None, sites=None): with pd.ExcelWriter(filename) as writer: # write constants to spreadsheet - costs.to_excel(writer, 'Costs') + costs.to_frame().to_excel(writer, 'Costs') cpro.to_excel(writer, 'Process caps') ctra.to_excel(writer, 'Transmission caps') csto.to_excel(writer, 'Storage caps') From d7e28a066a55c5f9c769596abf93596a05699f03 Mon Sep 17 00:00:00 2001 From: jdorfner Date: Thu, 18 Aug 2016 14:02:20 +0200 Subject: [PATCH 2/2] remove save from default runme (due to rare use and poooor performance) --- runme.py | 5 ----- urbs.py | 10 ++++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/runme.py b/runme.py index c72e66f9..a90700ae 100644 --- a/runme.py +++ b/runme.py @@ -115,11 +115,6 @@ def run_scenario(input_file, timesteps, scenario, result_dir, plot_periods={}): os.path.join(result_dir, '{}.xlsx').format(sce), prob.com_demand, prob.sit) - # store optimisation problem for later re-analysis - urbs.save( - prob, - os.path.join(result_dir, '{}.pgz').format(sce)) - urbs.result_figures( prob, os.path.join(result_dir, '{}'.format(sce)), diff --git a/urbs.py b/urbs.py index 18183e9a..8b39e3d8 100644 --- a/urbs.py +++ b/urbs.py @@ -1525,10 +1525,6 @@ def get_entity(instance, name): # convert to Series results = results[name] - - # if Series has MultiIndex, sort it to avoid PerformanceWarnings - if isinstance(results.index, pd.core.index.MultiIndex): - results = results.sortlevel() return results @@ -1781,8 +1777,10 @@ def get_timeseries(instance, com, sit, timesteps=None): dsmup = get_entity(instance, 'dsm_up') dsmdo = get_entity(instance, 'dsm_down') - dsmup = dsmup.xs(sit, level = 'sit').xs(com, level = 'com') - dsmdo = dsmdo.xs(sit, level = 'sit').xs(com, level = 'com') + dsmup = dsmup.xs(sit, level = 'sit') + dsmup = dsmup.xs(com, level = 'com') + dsmdo = dsmdo.xs(sit, level = 'sit') + dsmdo = dsmdo.xs(com, level = 'com') # series by summing the first time step set dsmdo = dsmdo.unstack().sum(axis=0)