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