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