|
21 | 21 | from tools.plots import (make_all_plots,plot_line_loading, plot_stacked_gen, |
22 | 22 | add_coordinates, curtailment, gen_dist, |
23 | 23 | storage_distribution, igeoplot) |
| 24 | + # For importing geopandas you need to install spatialindex on your system http://github.com/libspatialindex/libspatialindex/wiki/1.-Getting-Started |
24 | 25 | from tools.utilities import get_scenario_setting, get_time_steps |
25 | 26 | from tools.io import geolocation_buses, etrago_from_oedb |
26 | | - from tools.results import total_storage_charges |
| 27 | + from tools.results import eGo |
27 | 28 | from sqlalchemy.orm import sessionmaker |
28 | 29 | from egoio.tools import db |
29 | 30 | from etrago.tools.io import results_to_oedb |
|
33 | 34 | logging.basicConfig(level=logging.INFO) |
34 | 35 | logger = logging.getLogger(__name__) |
35 | 36 |
|
| 37 | +## Logging |
| 38 | +logging.basicConfig(format='%(asctime)s %(message)s',level=logging.INFO) |
| 39 | + |
| 40 | +logger = logging.getLogger(__name__) |
| 41 | +ego_logger = logging.getLogger('ego') |
| 42 | + |
| 43 | +fh = logging.FileHandler('ego.log', mode='w') |
| 44 | +fh.setLevel(logging.INFO) |
| 45 | +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') |
| 46 | +fh.setFormatter(formatter) |
| 47 | + |
| 48 | +logger.addHandler(fh) |
| 49 | +ego_logger.addHandler(fh) |
| 50 | + |
36 | 51 |
|
37 | 52 | if __name__ == '__main__': |
38 | 53 | # import scenario settings **args of eTraGo |
39 | 54 | args = get_scenario_setting(json_file='scenario_setting.json') |
| 55 | + print (args) |
40 | 56 |
|
41 | 57 | try: |
42 | 58 | conn = db.connection(section=args['global']['db']) |
|
50 | 66 | # start eTraGo calculation |
51 | 67 | eTraGo = etrago(args['eTraGo']) |
52 | 68 |
|
53 | | - #ToDo save result to db |
54 | | - # Does not work wait for eTraGo release 0.5.1 |
55 | | - #results_to_oedb(session, eTraGo, args['eTraGo'], grid='hv') |
| 69 | + eGo = eGo(eTraGo=eTraGo, scn_name='Status Quo') |
56 | 70 |
|
57 | 71 | # add country code to bus and geometry (shapely) |
58 | 72 | # eTraGo.buses = eTraGo.buses.drop(['country_code','geometry'], axis=1) |
59 | 73 | #test = geolocation_buses(network = eTraGo, session) |
60 | 74 |
|
61 | | - # other plots based on matplotlib |
62 | | - make_all_plots(eTraGo) |
63 | 75 | # make a line loading plot |
64 | | - plot_line_loading(eTraGo) |
| 76 | + eGo.eTraGo.plot_line_loading(eTraGo) |
65 | 77 |
|
66 | | - # plot stacked sum of nominal power for each generator type and timestep |
67 | | - plot_stacked_gen(eTraGo, resolution="MW") |
68 | | - |
69 | | - # plot to show extendable storages |
70 | | - storage_distribution(eTraGo) |
71 | | - |
72 | | - # plot storage total charges and discharge |
73 | | - total_storage_charges(eTraGo, plot=True) |
74 | 78 |
|
75 | 79 | # get eTraGo results form db |
76 | | - if args['global']['result_id']: |
| 80 | + if args['global']['recover']: |
77 | 81 | eTraGo = etrago_from_oedb(session,args) |
78 | 82 |
|
79 | | - |
80 | 83 | # use eTraGo results from ego calculations if true |
81 | 84 | # ToDo make function edisgo_direct_specs() |
82 | 85 |
|
83 | | - if args['eDisGo']['direct_specs']: |
84 | | - # ToDo: add this to utilities.py |
85 | | - bus_id = 27334 |
86 | | - specs_meta_data = {} |
87 | | - specs_meta_data.update({'TG Bus ID':bus_id}) |
88 | 86 |
|
89 | | - # Retrieve all Data |
90 | | - ### Snapshot Range |
91 | | - #snap_idx = eTraGo_network.snapshots |
92 | 87 |
|
93 | | - ## Bus Power |
94 | | - |
95 | | - try: |
96 | | - active_power_kW = eTraGo_network.buses_t.p[str(bus_id)] * 1000 # PyPSA result is in MW |
97 | | - except: |
98 | | - logger.warning('No active power series') |
99 | | - active_power_kW = None |
| 88 | + if args['eDisGo']['direct_specs']: |
| 89 | + # ToDo: add this to utilities.py |
100 | 90 |
|
101 | | - try: |
102 | | - reactive_power_kvar = eTraGo_network.buses_t.q[str(bus_id)] * 1000 # PyPSA result is in Mvar |
103 | | - except: |
104 | | - logger.warning('No reactive power series') |
105 | | - reactive_power_kvar = None |
| 91 | + logging.info('Retrieving Specs') |
106 | 92 |
|
| 93 | + bus_id = 27574 #23971 |
107 | 94 |
|
108 | | - ## Gens |
109 | | - all_gens = eTraGo_network.generators.bus |
110 | | - bus_gens = all_gens.index[all_gens == str(bus_id)] |
111 | | - p_nom = eTraGo_network.generators.p_nom[bus_gens] |
112 | | - gen_type = eTraGo_network.generators.carrier[bus_gens] |
| 95 | + from ego.tools.specs import get_etragospecs_direct, get_mvgrid_from_bus_id |
| 96 | + from egoio.db_tables import model_draft |
| 97 | + specs = get_etragospecs_direct(session, bus_id, eTraGo, args) |
113 | 98 |
|
114 | | - gen_df = pd.DataFrame({'p_nom': p_nom,'gen_type':gen_type}) |
115 | | - capacity = gen_df[['p_nom','gen_type']].groupby('gen_type').sum().T |
116 | 99 |
|
117 | | - gens = eTraGo_network.generators |
118 | | - for key, value in gens.items(): |
119 | | - print (key) |
120 | 100 |
|
121 | 101 | # ToDo make loop for all bus ids |
122 | 102 | # make function which links bus_id (subst_id) |
123 | 103 | if args['eDisGo']['specs']: |
124 | 104 |
|
| 105 | + |
125 | 106 | logging.info('Retrieving Specs') |
126 | 107 | # ToDo make it more generic |
127 | 108 | # ToDo iteration of grids |
128 | 109 | # ToDo move part as function to utilities or specs |
129 | | - bus_id = 23971 |
| 110 | + bus_id = 27574 #23971 |
130 | 111 | result_id = args['global']['result_id'] |
131 | | - scn_name = args['global']['scn_name'] # Six is Germany for 2 Snaps with minimal residual load |
132 | 112 |
|
133 | | - from ego.tools.specs import get_etragospecs_from_db |
| 113 | + from ego.tools.specs import get_etragospecs_from_db, get_mvgrid_from_bus_id |
134 | 114 | from egoio.db_tables import model_draft |
135 | | - specs = get_etragospecs_from_db(session, bus_id, result_id, scn_name) |
| 115 | + specs = get_etragospecs_from_db(session, bus_id, result_id) |
| 116 | + |
| 117 | + mv_grid = get_mvgrid_from_bus_id(session, bus_id) # This function can be used to call the correct MV grid |
136 | 118 |
|
137 | 119 | if args['global']['eDisGo']: |
| 120 | + |
138 | 121 | logging.info('Starting eDisGo') |
139 | 122 |
|
140 | 123 | # ToDo move part as function to utilities or specs |
|
145 | 128 |
|
146 | 129 | # ToDo get ding0 grids over db |
147 | 130 | # ToDo implemente iteration |
148 | | - file_path = '/home/dozeumbuw/ego_dev/src/ding0_grids__1802.pkl' |
| 131 | + file_path = 'data/ding0_grids/ding0_grids__1802.pkl' |
149 | 132 |
|
150 | 133 | #mv_grid = open(file_path) |
151 | 134 |
|
|
157 | 140 | scenario = Scenario(etrago_specs=specs, |
158 | 141 | power_flow=(), |
159 | 142 | mv_grid_id=mv_grid_id, |
160 | | - scenario_name= args['global']['scn_name']) |
| 143 | + scenario_name= args['eTraGo']['scn_name']) |
161 | 144 |
|
162 | 145 | network = Network.import_from_ding0(file_path, |
163 | 146 | id=mv_grid_id, |
|
182 | 165 | print(costs) |
183 | 166 |
|
184 | 167 |
|
| 168 | + |
185 | 169 | # make interactive plot with folium |
186 | 170 | #logging.info('Starting interactive plot') |
187 | 171 | #igeoplot(network=eTraGo, session=session, args=args) # ToDo: add eDisGo results |
|
0 commit comments