Code Duplication    Length = 48-53 lines in 2 locations

src/egon/data/datasets/gas_neighbours/eGon2035.py 2 locations

@@ 381-433 (lines=53) @@
378
    ]
379
380
381
def import_ch4_demandTS():
382
    """Import from the PyPSA-eur-sec run the timeseries of
383
    residential rural heat per neighbor country.
384
    This timeserie is used to calculate:
385
    - the global (yearly) heat demand of Norway (that will be supplied by CH4)
386
    - the normalized CH4 hourly resolved demand profile
387
388
    Parameters
389
    ----------
390
    None.
391
392
    Returns
393
    -------
394
    Norway_global_demand: Float
395
        Yearly heat demand of Norway in MWh
396
    neighbor_loads_t: pandas.DataFrame
397
        Normalized CH4 hourly resolved demand profiles per neighbor country
398
399
    """
400
401
    cwd = Path(".")
402
    target_file = (
403
        cwd
404
        / "data_bundle_egon_data"
405
        / "pypsa_eur_sec"
406
        / "2022-07-26-egondata-integration"
407
        / "postnetworks"
408
        / "elec_s_37_lv2.0__Co2L0-1H-T-H-B-I-dist1_2050.nc"
409
    )
410
411
    network = pypsa.Network(str(target_file))
412
413
    # Set country tag for all buses
414
    network.buses.country = network.buses.index.str[:2]
415
    neighbors = network.buses[network.buses.country != "DE"]
416
    neighbors = neighbors[
417
        (neighbors["country"].isin(countries))
418
        & (neighbors["carrier"] == "residential rural heat")
419
    ].drop_duplicates(subset="country")
420
421
    neighbor_loads = network.loads[network.loads.bus.isin(neighbors.index)]
422
    neighbor_loads_t_index = neighbor_loads.index[
423
        neighbor_loads.index.isin(network.loads_t.p_set.columns)
424
    ]
425
    neighbor_loads_t = network.loads_t["p_set"][neighbor_loads_t_index]
426
    Norway_global_demand = neighbor_loads_t[
427
        "NO3 0 residential rural heat"
428
    ].sum()
429
430
    for i in neighbor_loads_t.columns:
431
        neighbor_loads_t[i] = neighbor_loads_t[i] / neighbor_loads_t[i].sum()
432
433
    return Norway_global_demand, neighbor_loads_t
434
435
436
def import_power_to_h2_demandTS():
@@ 436-483 (lines=48) @@
433
    return Norway_global_demand, neighbor_loads_t
434
435
436
def import_power_to_h2_demandTS():
437
    """Import from the PyPSA-eur-sec run the timeseries of
438
    industry demand heat per neighbor country and normalize it
439
    in order to model the power-to-H2 hourly resolved demand profile.
440
441
    Parameters
442
    ----------
443
    None.
444
445
    Returns
446
    -------
447
    neighbor_loads_t: pandas.DataFrame
448
        Normalized CH4 hourly resolved demand profiles per neighbor country
449
450
    """
451
452
    cwd = Path(".")
453
    target_file = (
454
        cwd
455
        / "data_bundle_egon_data"
456
        / "pypsa_eur_sec"
457
        / "2022-07-26-egondata-integration"
458
        / "postnetworks"
459
        / "elec_s_37_lv2.0__Co2L0-1H-T-H-B-I-dist1_2050.nc"
460
    )
461
462
    network = pypsa.Network(str(target_file))
463
464
    # Set country tag for all buses
465
    network.buses.country = network.buses.index.str[:2]
466
    neighbors = network.buses[network.buses.country != "DE"]
467
    neighbors = neighbors[
468
        (neighbors["country"].isin(countries))
469
        & (
470
            neighbors["carrier"] == "residential rural heat"
471
        )  # no available industry profile for now, using another timeserie
472
    ]  # .drop_duplicates(subset="country")
473
474
    neighbor_loads = network.loads[network.loads.bus.isin(neighbors.index)]
475
    neighbor_loads_t_index = neighbor_loads.index[
476
        neighbor_loads.index.isin(network.loads_t.p_set.columns)
477
    ]
478
    neighbor_loads_t = network.loads_t["p_set"][neighbor_loads_t_index]
479
480
    for i in neighbor_loads_t.columns:
481
        neighbor_loads_t[i] = neighbor_loads_t[i] / neighbor_loads_t[i].sum()
482
483
    return neighbor_loads_t
484
485
486
def insert_ch4_demand(global_demand, normalized_ch4_demandTS):