Conditions | 1 |
Total Lines | 222 |
Code Lines | 86 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | """ |
||
275 | def etrago_eGon2035_heat(): |
||
276 | """Execute basic sanity checks. |
||
277 | |||
278 | Returns print statements as sanity checks for the heat sector in |
||
279 | the eGon2035 scenario. |
||
280 | |||
281 | Parameters |
||
282 | ---------- |
||
283 | None |
||
284 | |||
285 | Returns |
||
286 | ------- |
||
287 | None |
||
288 | """ |
||
289 | |||
290 | # Check input and output values for the carriers "other_non_renewable", |
||
291 | # "other_renewable", "reservoir", "run_of_river" and "oil" |
||
292 | |||
293 | scn = "eGon2035" |
||
294 | |||
295 | # Section to check generator capacities |
||
296 | print(f"Sanity checks for scenario {scn}") |
||
297 | print( |
||
298 | "For German heat demands the following deviations between the inputs" |
||
299 | " and outputs can be observed:" |
||
300 | ) |
||
301 | |||
302 | # Sanity checks for heat demand |
||
303 | |||
304 | output_heat_demand = db.select_dataframe( |
||
305 | """SELECT a.scn_name, |
||
306 | (SUM( |
||
307 | (SELECT SUM(p) FROM UNNEST(b.p_set) p))/1000000)::numeric as load_twh |
||
308 | FROM grid.egon_etrago_load a |
||
309 | JOIN grid.egon_etrago_load_timeseries b |
||
310 | ON (a.load_id = b.load_id) |
||
311 | JOIN grid.egon_etrago_bus c |
||
312 | ON (a.bus=c.bus_id) |
||
313 | AND b.scn_name = 'eGon2035' |
||
314 | AND a.scn_name = 'eGon2035' |
||
315 | AND c.scn_name= 'eGon2035' |
||
316 | AND c.country='DE' |
||
317 | AND a.carrier IN ('rural_heat', 'central_heat') |
||
318 | GROUP BY (a.scn_name); |
||
319 | """, |
||
320 | warning=False, |
||
321 | )["load_twh"].values[0] |
||
322 | |||
323 | input_heat_demand = db.select_dataframe( |
||
324 | """SELECT scenario, SUM(demand::numeric/1000000) as demand_mw_peta_heat |
||
325 | FROM demand.egon_peta_heat |
||
326 | WHERE scenario= 'eGon2035' |
||
327 | GROUP BY (scenario); |
||
328 | """, |
||
329 | warning=False, |
||
330 | )["demand_mw_peta_heat"].values[0] |
||
331 | |||
332 | e_demand = ( |
||
333 | round((output_heat_demand - input_heat_demand) / input_heat_demand, 2) |
||
334 | * 100 |
||
335 | ) |
||
336 | |||
337 | print(f"heat demand: {e_demand} %") |
||
338 | |||
339 | # Sanity checks for heat supply |
||
340 | |||
341 | print( |
||
342 | "For German heat supplies the following deviations between the inputs " |
||
343 | "and outputs can be observed:" |
||
344 | ) |
||
345 | |||
346 | # Comparison for central heat pumps |
||
347 | heat_pump_input = db.select_dataframe( |
||
348 | """SELECT carrier, SUM(capacity::numeric) as Urban_central_heat_pump_mw |
||
349 | FROM supply.egon_scenario_capacities |
||
350 | WHERE carrier= 'urban_central_heat_pump' |
||
351 | AND scenario_name IN ('eGon2035') |
||
352 | GROUP BY (carrier); |
||
353 | """, |
||
354 | warning=False, |
||
355 | )["urban_central_heat_pump_mw"].values[0] |
||
356 | |||
357 | heat_pump_output = db.select_dataframe( |
||
358 | """SELECT carrier, SUM(p_nom::numeric) as Central_heat_pump_mw |
||
359 | FROM grid.egon_etrago_link |
||
360 | WHERE carrier= 'central_heat_pump' |
||
361 | AND scn_name IN ('eGon2035') |
||
362 | GROUP BY (carrier); |
||
363 | """, |
||
364 | warning=False, |
||
365 | )["central_heat_pump_mw"].values[0] |
||
366 | |||
367 | e_heat_pump = ( |
||
368 | round((heat_pump_output - heat_pump_input) / heat_pump_output, 2) * 100 |
||
369 | ) |
||
370 | |||
371 | print(f"'central_heat_pump': {e_heat_pump} % ") |
||
372 | |||
373 | # Comparison for residential heat pumps |
||
374 | |||
375 | input_residential_heat_pump = db.select_dataframe( |
||
376 | """SELECT carrier, SUM(capacity::numeric) as residential_heat_pump_mw |
||
377 | FROM supply.egon_scenario_capacities |
||
378 | WHERE carrier= 'residential_rural_heat_pump' |
||
379 | AND scenario_name IN ('eGon2035') |
||
380 | GROUP BY (carrier); |
||
381 | """, |
||
382 | warning=False, |
||
383 | )["residential_heat_pump_mw"].values[0] |
||
384 | |||
385 | output_residential_heat_pump = db.select_dataframe( |
||
386 | """SELECT carrier, SUM(p_nom::numeric) as rural_heat_pump_mw |
||
387 | FROM grid.egon_etrago_link |
||
388 | WHERE carrier= 'rural_heat_pump' |
||
389 | AND scn_name IN ('eGon2035') |
||
390 | GROUP BY (carrier); |
||
391 | """, |
||
392 | warning=False, |
||
393 | )["rural_heat_pump_mw"].values[0] |
||
394 | |||
395 | e_residential_heat_pump = ( |
||
396 | round( |
||
397 | (output_residential_heat_pump - input_residential_heat_pump) |
||
398 | / input_residential_heat_pump, |
||
399 | 2, |
||
400 | ) |
||
401 | * 100 |
||
402 | ) |
||
403 | print(f"'residential heat pumps': {e_residential_heat_pump} %") |
||
404 | |||
405 | # Comparison for resistive heater |
||
406 | resistive_heater_input = db.select_dataframe( |
||
407 | """SELECT carrier, |
||
408 | SUM(capacity::numeric) as Urban_central_resistive_heater_MW |
||
409 | FROM supply.egon_scenario_capacities |
||
410 | WHERE carrier= 'urban_central_resistive_heater' |
||
411 | AND scenario_name IN ('eGon2035') |
||
412 | GROUP BY (carrier); |
||
413 | """, |
||
414 | warning=False, |
||
415 | )["urban_central_resistive_heater_mw"].values[0] |
||
416 | |||
417 | resistive_heater_output = db.select_dataframe( |
||
418 | """SELECT carrier, SUM(p_nom::numeric) as central_resistive_heater_MW |
||
419 | FROM grid.egon_etrago_link |
||
420 | WHERE carrier= 'central_resistive_heater' |
||
421 | AND scn_name IN ('eGon2035') |
||
422 | GROUP BY (carrier); |
||
423 | """, |
||
424 | warning=False, |
||
425 | )["central_resistive_heater_mw"].values[0] |
||
426 | |||
427 | e_resistive_heater = ( |
||
428 | round( |
||
429 | (resistive_heater_output - resistive_heater_input) |
||
430 | / resistive_heater_input, |
||
431 | 2, |
||
432 | ) |
||
433 | * 100 |
||
434 | ) |
||
435 | |||
436 | print(f"'resistive heater': {e_resistive_heater} %") |
||
437 | |||
438 | # Comparison for solar thermal collectors |
||
439 | |||
440 | input_solar_thermal = db.select_dataframe( |
||
441 | """SELECT carrier, SUM(capacity::numeric) as solar_thermal_collector_mw |
||
442 | FROM supply.egon_scenario_capacities |
||
443 | WHERE carrier= 'urban_central_solar_thermal_collector' |
||
444 | AND scenario_name IN ('eGon2035') |
||
445 | GROUP BY (carrier); |
||
446 | """, |
||
447 | warning=False, |
||
448 | )["solar_thermal_collector_mw"].values[0] |
||
449 | |||
450 | output_solar_thermal = db.select_dataframe( |
||
451 | """SELECT carrier, SUM(p_nom::numeric) as solar_thermal_collector_mw |
||
452 | FROM grid.egon_etrago_generator |
||
453 | WHERE carrier= 'solar_thermal_collector' |
||
454 | AND scn_name IN ('eGon2035') |
||
455 | GROUP BY (carrier); |
||
456 | """, |
||
457 | warning=False, |
||
458 | )["solar_thermal_collector_mw"].values[0] |
||
459 | |||
460 | e_solar_thermal = ( |
||
461 | round( |
||
462 | (output_solar_thermal - input_solar_thermal) / input_solar_thermal, |
||
463 | 2, |
||
464 | ) |
||
465 | * 100 |
||
466 | ) |
||
467 | print(f"'solar thermal collector': {e_solar_thermal} %") |
||
468 | |||
469 | # Comparison for geothermal |
||
470 | |||
471 | input_geo_thermal = db.select_dataframe( |
||
472 | """SELECT carrier, |
||
473 | SUM(capacity::numeric) as Urban_central_geo_thermal_MW |
||
474 | FROM supply.egon_scenario_capacities |
||
475 | WHERE carrier= 'urban_central_geo_thermal' |
||
476 | AND scenario_name IN ('eGon2035') |
||
477 | GROUP BY (carrier); |
||
478 | """, |
||
479 | warning=False, |
||
480 | )["urban_central_geo_thermal_mw"].values[0] |
||
481 | |||
482 | output_geo_thermal = db.select_dataframe( |
||
483 | """SELECT carrier, SUM(p_nom::numeric) as geo_thermal_MW |
||
484 | FROM grid.egon_etrago_generator |
||
485 | WHERE carrier= 'geo_thermal' |
||
486 | AND scn_name IN ('eGon2035') |
||
487 | GROUP BY (carrier); |
||
488 | """, |
||
489 | warning=False, |
||
490 | )["geo_thermal_mw"].values[0] |
||
491 | |||
492 | e_geo_thermal = ( |
||
493 | round((output_geo_thermal - input_geo_thermal) / input_geo_thermal, 2) |
||
494 | * 100 |
||
495 | ) |
||
496 | print(f"'geothermal': {e_geo_thermal} %") |
||
497 | |||
575 |