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