Code Duplication    Length = 48-53 lines in 2 locations

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

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