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