Code Duplication    Length = 48-53 lines in 2 locations

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

@@ 500-552 (lines=53) @@
497
    ]
498
499
500
def import_ch4_demandTS():
501
    """Import from the PyPSA-eur-sec run the timeseries of
502
    residential rural heat per neighbor country.
503
    This timeserie is used to calculate:
504
    - the global (yearly) heat demand of Norway (that will be supplied by CH4)
505
    - the normalized CH4 hourly resolved demand profile
506
507
    Parameters
508
    ----------
509
    None.
510
511
    Returns
512
    -------
513
    Norway_global_demand: Float
514
        Yearly heat demand of Norway in MWh
515
    neighbor_loads_t: pandas.DataFrame
516
        Normalized CH4 hourly resolved demand profiles per neighbor country
517
518
    """
519
520
    cwd = Path(".")
521
    target_file = (
522
        cwd
523
        / "data_bundle_egon_data"
524
        / "pypsa_eur_sec"
525
        / "2022-07-26-egondata-integration"
526
        / "postnetworks"
527
        / "elec_s_37_lv2.0__Co2L0-1H-T-H-B-I-dist1_2050.nc"
528
    )
529
530
    network = pypsa.Network(str(target_file))
531
532
    # Set country tag for all buses
533
    network.buses.country = network.buses.index.str[:2]
534
    neighbors = network.buses[network.buses.country != "DE"]
535
    neighbors = neighbors[
536
        (neighbors["country"].isin(countries))
537
        & (neighbors["carrier"] == "residential rural heat")
538
    ].drop_duplicates(subset="country")
539
540
    neighbor_loads = network.loads[network.loads.bus.isin(neighbors.index)]
541
    neighbor_loads_t_index = neighbor_loads.index[
542
        neighbor_loads.index.isin(network.loads_t.p_set.columns)
543
    ]
544
    neighbor_loads_t = network.loads_t["p_set"][neighbor_loads_t_index]
545
    Norway_global_demand = neighbor_loads_t[
546
        "NO3 0 residential rural heat"
547
    ].sum()
548
549
    for i in neighbor_loads_t.columns:
550
        neighbor_loads_t[i] = neighbor_loads_t[i] / neighbor_loads_t[i].sum()
551
552
    return Norway_global_demand, neighbor_loads_t
553
554
555
def import_power_to_h2_demandTS():
@@ 555-602 (lines=48) @@
552
    return Norway_global_demand, neighbor_loads_t
553
554
555
def import_power_to_h2_demandTS():
556
    """Import from the PyPSA-eur-sec run the timeseries of
557
    industry demand heat per neighbor country and normalize it
558
    in order to model the power-to-H2 hourly resolved demand profile.
559
560
    Parameters
561
    ----------
562
    None.
563
564
    Returns
565
    -------
566
    neighbor_loads_t: pandas.DataFrame
567
        Normalized CH4 hourly resolved demand profiles per neighbor country
568
569
    """
570
571
    cwd = Path(".")
572
    target_file = (
573
        cwd
574
        / "data_bundle_egon_data"
575
        / "pypsa_eur_sec"
576
        / "2022-07-26-egondata-integration"
577
        / "postnetworks"
578
        / "elec_s_37_lv2.0__Co2L0-1H-T-H-B-I-dist1_2050.nc"
579
    )
580
581
    network = pypsa.Network(str(target_file))
582
583
    # Set country tag for all buses
584
    network.buses.country = network.buses.index.str[:2]
585
    neighbors = network.buses[network.buses.country != "DE"]
586
    neighbors = neighbors[
587
        (neighbors["country"].isin(countries))
588
        & (
589
            neighbors["carrier"] == "residential rural heat"
590
        )  # no available industry profile for now, using another timeserie
591
    ]  # .drop_duplicates(subset="country")
592
593
    neighbor_loads = network.loads[network.loads.bus.isin(neighbors.index)]
594
    neighbor_loads_t_index = neighbor_loads.index[
595
        neighbor_loads.index.isin(network.loads_t.p_set.columns)
596
    ]
597
    neighbor_loads_t = network.loads_t["p_set"][neighbor_loads_t_index]
598
599
    for i in neighbor_loads_t.columns:
600
        neighbor_loads_t[i] = neighbor_loads_t[i] / neighbor_loads_t[i].sum()
601
602
    return neighbor_loads_t
603
604
605
def insert_ch4_demand(global_demand, normalized_ch4_demandTS):