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