| @@ 423-484 (lines=62) @@ | ||
| 420 | return load_ts_df, curves_individual |
|
| 421 | ||
| 422 | ||
| 423 | def insert_sites_ind_load(): |
|
| 424 | """Inserts electrical industry loads assigned to osm landuse areas to the |
|
| 425 | database. |
|
| 426 | ||
| 427 | Returns |
|
| 428 | ------- |
|
| 429 | None. |
|
| 430 | ||
| 431 | """ |
|
| 432 | ||
| 433 | targets = egon.data.config.datasets()["electrical_load_curves_industry"][ |
|
| 434 | "targets" |
|
| 435 | ] |
|
| 436 | ||
| 437 | for scenario in egon.data.config.settings()["egon-data"]["--scenarios"]: |
|
| 438 | # Delete existing data from database |
|
| 439 | db.execute_sql( |
|
| 440 | f""" |
|
| 441 | DELETE FROM |
|
| 442 | {targets['sites_load']['schema']}.{targets['sites_load']['table']} |
|
| 443 | WHERE scn_name = '{scenario}' |
|
| 444 | """ |
|
| 445 | ) |
|
| 446 | ||
| 447 | # Delete existing data from database |
|
| 448 | db.execute_sql( |
|
| 449 | f""" |
|
| 450 | DELETE FROM |
|
| 451 | {targets['sites_load_individual']['schema']}. |
|
| 452 | {targets['sites_load_individual']['table']} |
|
| 453 | WHERE scn_name = '{scenario}' |
|
| 454 | """ |
|
| 455 | ) |
|
| 456 | ||
| 457 | # Calculate industrial load curves per bus |
|
| 458 | data, curves_individual = calc_load_curves_ind_sites(scenario) |
|
| 459 | data.index = data.index.rename(["bus", "wz"]) |
|
| 460 | data["scn_name"] = scenario |
|
| 461 | ||
| 462 | data.set_index(["scn_name"], inplace=True, append=True) |
|
| 463 | ||
| 464 | # Insert into database |
|
| 465 | data.to_sql( |
|
| 466 | targets["sites_load"]["table"], |
|
| 467 | schema=targets["sites_load"]["schema"], |
|
| 468 | con=db.engine(), |
|
| 469 | if_exists="append", |
|
| 470 | ) |
|
| 471 | ||
| 472 | curves_individual["peak_load"] = np.array( |
|
| 473 | curves_individual["p_set"].values.tolist() |
|
| 474 | ).max(axis=1) |
|
| 475 | curves_individual["demand"] = np.array( |
|
| 476 | curves_individual["p_set"].values.tolist() |
|
| 477 | ).sum(axis=1) |
|
| 478 | curves_individual = identify_voltage_level(curves_individual) |
|
| 479 | ||
| 480 | curves_individual.to_sql( |
|
| 481 | targets["sites_load_individual"]["table"], |
|
| 482 | schema=targets["sites_load_individual"]["schema"], |
|
| 483 | con=db.engine(), |
|
| 484 | if_exists="append", |
|
| 485 | ) |
|
| 486 | ||
| @@ 253-313 (lines=61) @@ | ||
| 250 | return load_ts_df, curves_individual |
|
| 251 | ||
| 252 | ||
| 253 | def insert_osm_ind_load(): |
|
| 254 | """Inserts electrical industry loads assigned to osm landuse areas to the |
|
| 255 | database. |
|
| 256 | ||
| 257 | Returns |
|
| 258 | ------- |
|
| 259 | None. |
|
| 260 | ||
| 261 | """ |
|
| 262 | ||
| 263 | targets = egon.data.config.datasets()["electrical_load_curves_industry"][ |
|
| 264 | "targets" |
|
| 265 | ] |
|
| 266 | ||
| 267 | for scenario in egon.data.config.settings()["egon-data"]["--scenarios"]: |
|
| 268 | # Delete existing data from database |
|
| 269 | db.execute_sql( |
|
| 270 | f""" |
|
| 271 | DELETE FROM |
|
| 272 | {targets['osm_load']['schema']}.{targets['osm_load']['table']} |
|
| 273 | WHERE scn_name = '{scenario}' |
|
| 274 | """ |
|
| 275 | ) |
|
| 276 | ||
| 277 | db.execute_sql( |
|
| 278 | f""" |
|
| 279 | DELETE FROM |
|
| 280 | {targets['osm_load_individual']['schema']}. |
|
| 281 | {targets['osm_load_individual']['table']} |
|
| 282 | WHERE scn_name = '{scenario}' |
|
| 283 | """ |
|
| 284 | ) |
|
| 285 | ||
| 286 | # Calculate cts load curves per mv substation (hvmv bus) |
|
| 287 | data, curves_individual = calc_load_curves_ind_osm(scenario) |
|
| 288 | data.index = data.index.rename("bus") |
|
| 289 | data["scn_name"] = scenario |
|
| 290 | ||
| 291 | data.set_index(["scn_name"], inplace=True, append=True) |
|
| 292 | ||
| 293 | # Insert into database |
|
| 294 | data.to_sql( |
|
| 295 | targets["osm_load"]["table"], |
|
| 296 | schema=targets["osm_load"]["schema"], |
|
| 297 | con=db.engine(), |
|
| 298 | if_exists="append", |
|
| 299 | ) |
|
| 300 | ||
| 301 | curves_individual["peak_load"] = np.array( |
|
| 302 | curves_individual["p_set"].values.tolist() |
|
| 303 | ).max(axis=1) |
|
| 304 | curves_individual["demand"] = np.array( |
|
| 305 | curves_individual["p_set"].values.tolist() |
|
| 306 | ).sum(axis=1) |
|
| 307 | curves_individual = identify_voltage_level(curves_individual) |
|
| 308 | ||
| 309 | curves_individual.to_sql( |
|
| 310 | targets["osm_load_individual"]["table"], |
|
| 311 | schema=targets["osm_load_individual"]["schema"], |
|
| 312 | con=db.engine(), |
|
| 313 | if_exists="append", |
|
| 314 | ) |
|
| 315 | ||
| 316 | ||