Passed
Pull Request — dev (#1129)
by
unknown
01:48
created

calculate_total_demand_100RE()   A

Complexity

Conditions 3

Size

Total Lines 37
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 37
rs 9.45
c 0
b 0
f 0
cc 3
nop 0
1
# -*- coding: utf-8 -*-
2
"""
3
The central module containing code dealing with gas industrial demand
4
5
In this this module, the functions to import the industrial hydrogen and
6
methane demands from the opendata.ffe database and to insert them in
7
the database after modification are to be found.
8
9
"""
10
11
from pathlib import Path
12
import os
13
14
from geoalchemy2.types import Geometry
15
from shapely import wkt
16
import numpy as np
17
import pandas as pd
18
import requests
19
20
from egon.data import db
21
from egon.data.config import settings
22
from egon.data.datasets import Dataset
23
from egon.data.datasets.etrago_helpers import (
24
    finalize_bus_insertion,
25
    initialise_bus_insertion,
26
)
27
from egon.data.datasets.etrago_setup import link_geom_from_buses
28
from egon.data.datasets.pypsaeursec import read_network
29
from egon.data.datasets.scenario_parameters import get_sector_parameters
30
31
32
class IndustrialGasDemand(Dataset):
33
    """
34
    Download the industrial gas demands from the opendata.ffe database
35
36
    Data are downloaded in the folder ./datasets/gas_data/demand using
37
    the function :py:func:`download_industrial_gas_demand` and no dataset is resulting.
38
39
    *Dependencies*
40
      * :py:class:`ScenarioParameters <egon.data.datasets.scenario_parameters.ScenarioParameters>`
41
42
    """
43
44
    #:
45
    name: str = "IndustrialGasDemand"
46
    #:
47
    version: str = "0.0.4"
48
49
    def __init__(self, dependencies):
50
        super().__init__(
51
            name=self.name,
52
            version=self.version,
53
            dependencies=dependencies,
54
            tasks=(download_industrial_gas_demand),
55
        )
56
57
58
class IndustrialGasDemandeGon2035(Dataset):
59
    """Insert the hourly resolved industrial gas demands into the database for eGon2035
60
61
    Insert the industrial methane and hydrogen demands and their
62
    associated time series for the scenario eGon2035 by executing the
63
    function :py:func:`insert_industrial_gas_demand_egon2035`.
64
65
    *Dependencies*
66
      * :py:class:`GasAreaseGon2035 <egon.data.datasets.gas_areas.GasAreaseGon2035>`
67
      * :py:class:`GasNodesAndPipes <egon.data.datasets.gas_grid.GasNodesAndPipes>`
68
      * :py:class:`HydrogenBusEtrago <egon.data.datasets.hydrogen_etrago.HydrogenBusEtrago>`
69
      * :py:class:`IndustrialGasDemand <IndustrialGasDemand>`
70
71
    *Resulting tables*
72
      * :py:class:`grid.egon_etrago_load <egon.data.datasets.etrago_setup.EgonPfHvLoad>` is extended
73
      * :py:class:`grid.egon_etrago_load_timeseries <egon.data.datasets.etrago_setup.EgonPfHvLoadTimeseries>` is extended
74
75
    """
76
77
    #:
78
    name: str = "IndustrialGasDemandeGon2035"
79
    #:
80
    version: str = "0.0.3"
81
82
    def __init__(self, dependencies):
83
        super().__init__(
84
            name=self.name,
85
            version=self.version,
86
            dependencies=dependencies,
87
            tasks=(insert_industrial_gas_demand_egon2035),
88
        )
89
90
91
class IndustrialGasDemandeGon100RE(Dataset):
92
    """Insert the hourly resolved industrial gas demands into the database for eGon100RE
93
94
    Insert the industrial methane and hydrogen demands and their
95
    associated time series for the scenario eGon100RE by executing the
96
    function :py:func:`insert_industrial_gas_demand_egon100RE`.
97
98
    *Dependencies*
99
      * :py:class:`GasAreaseGon100RE <egon.data.datasets.gas_areas.GasAreaseGon100RE>`
100
      * :py:class:`GasNodesAndPipes <egon.data.datasets.gas_grid.GasNodesAndPipes>`
101
      * :py:class:`HydrogenBusEtrago <egon.data.datasets.hydrogen_etrago.HydrogenBusEtrago>`
102
      * :py:class:`IndustrialGasDemand <IndustrialGasDemand>`
103
104
    *Resulting tables*
105
      * :py:class:`grid.egon_etrago_load <egon.data.datasets.etrago_setup.EgonPfHvLoad>` is extended
106
      * :py:class:`grid.egon_etrago_load_timeseries <egon.data.datasets.etrago_setup.EgonPfHvLoadTimeseries>` is extended
107
108
    """
109
110
    #:
111
    name: str = "IndustrialGasDemandeGon100RE"
112
    #:
113
    version: str = "0.0.3"
114
115
    def __init__(self, dependencies):
116
        super().__init__(
117
            name=self.name,
118
            version=self.version,
119
            dependencies=dependencies,
120
            tasks=(insert_industrial_gas_demand_egon100RE),
121
        )
122
123
124
def read_industrial_demand(scn_name, carrier):
125
    """Read the industrial gas demand data in Germany
126
127
    This function reads the methane or hydrogen industrial demand time
128
    series previously downloaded in :py:func:`download_industrial_gas_demand` for
129
    the scenarios eGon2035 or eGon100RE.
130
131
    Parameters
132
    ----------
133
    scn_name : str
134
        Name of the scenario
135
    carrier : str
136
        Name of the gas carrier
137
138
    Returns
139
    -------
140
    df : pandas.DataFrame
141
        Dataframe containing the industrial gas demand time series
142
143
    """
144
    target_file = Path(".") / "datasets/gas_data/demand/region_corr.json"
145
    df_corr = pd.read_json(target_file)
146
    df_corr = df_corr.loc[:, ["id_region", "name_short"]]
147
    df_corr.set_index("id_region", inplace=True)
148
149
    target_file = (
150
        Path(".")
151
        / "datasets/gas_data/demand"
152
        / (carrier + "_" + scn_name + ".json")
153
    )
154
    industrial_loads = pd.read_json(target_file)
155
    industrial_loads = industrial_loads.loc[:, ["id_region", "values"]]
156
    industrial_loads.set_index("id_region", inplace=True)
157
158
    # Match the id_region to obtain the NUT3 region names
159
    industrial_loads_list = pd.concat(
160
        [industrial_loads, df_corr], axis=1, join="inner"
161
    )
162
    industrial_loads_list["NUTS0"] = (industrial_loads_list["name_short"].str)[
163
        0:2
164
    ]
165
    industrial_loads_list["NUTS1"] = (industrial_loads_list["name_short"].str)[
166
        0:3
167
    ]
168
    industrial_loads_list = industrial_loads_list[
169
        industrial_loads_list["NUTS0"].str.match("DE")
170
    ]
171
172
    # Cut data to federal state if in testmode
173
    boundary = settings()["egon-data"]["--dataset-boundary"]
174
    if boundary != "Everything":
175
        map_states = {
176
            "Baden-Württemberg": "DE1",
177
            "Nordrhein-Westfalen": "DEA",
178
            "Hessen": "DE7",
179
            "Brandenburg": "DE4",
180
            "Bremen": "DE5",
181
            "Rheinland-Pfalz": "DEB",
182
            "Sachsen-Anhalt": "DEE",
183
            "Schleswig-Holstein": "DEF",
184
            "Mecklenburg-Vorpommern": "DE8",
185
            "Thüringen": "DEG",
186
            "Niedersachsen": "DE9",
187
            "Sachsen": "DED",
188
            "Hamburg": "DE6",
189
            "Saarland": "DEC",
190
            "Berlin": "DE3",
191
            "Bayern": "DE2",
192
        }
193
194
        industrial_loads_list = industrial_loads_list[
195
            industrial_loads_list["NUTS1"].isin([map_states[boundary], np.nan])
196
        ]
197
198
    industrial_loads_list = industrial_loads_list.rename(
199
        columns={"name_short": "nuts3", "values": "p_set"}
200
    )
201
    industrial_loads_list = industrial_loads_list.set_index("nuts3")
202
203
    # Add the centroid point to each NUTS3 area
204
    sql_vg250 = """SELECT nuts as nuts3, geometry as geom
205
                    FROM boundaries.vg250_krs
206
                    WHERE gf = 4 ;"""
207
    gdf_vg250 = db.select_geodataframe(sql_vg250, epsg=4326)
208
209
    point = []
210
    for index, row in gdf_vg250.iterrows():
211
        point.append(wkt.loads(str(row["geom"])).centroid)
212
    gdf_vg250["point"] = point
213
    gdf_vg250 = gdf_vg250.set_index("nuts3")
214
    gdf_vg250 = gdf_vg250.drop(columns=["geom"])
215
216
    # Match the load to the NUTS3 points
217
    industrial_loads_list = pd.concat(
218
        [industrial_loads_list, gdf_vg250], axis=1, join="inner"
219
    )
220
    return industrial_loads_list.rename(
221
        columns={"point": "geom"}
222
    ).set_geometry("geom", crs=4326)
223
224
225
def read_and_process_demand(
226
    scn_name="eGon2035", carrier=None, grid_carrier=None
227
):
228
    """Assign the industrial gas demand in Germany to buses
229
230
    This function prepares and returns the industrial gas demand time
231
    series for CH4 or H2 and for a specific scenario by executing the
232
    following steps:
233
234
      * Read the industrial demand time series in Germany with the
235
        fonction :py:func:`read_industrial_demand`
236
      * Attribute the bus_id to which each load and it associated time
237
        serie is associated by calling the function :py:func:`assign_gas_bus_id <egon.data.db.assign_gas_bus_id>`
238
        from :py:mod:`egon.data.db <egon.data.db>`
239
      * Adjust the columns: add "carrier" and remove useless ones
240
241
    Parameters
242
    ----------
243
    scn_name : str
244
        Name of the scenario
245
    carrier : str
246
        Name of the carrier, the demand should hold
247
    grid_carrier : str
248
        Carrier name of the buses, the demand should be assigned to
249
250
    Returns
251
    -------
252
    industrial_demand : pandas.DataFrame
253
        Dataframe containing the industrial demand in Germany
254
255
    """
256
    if grid_carrier is None:
257
        grid_carrier = carrier
258
    industrial_loads_list = read_industrial_demand(scn_name, carrier)
259
    number_loads = len(industrial_loads_list)
260
261
    # Match to associated gas bus
262
    industrial_loads_list = db.assign_gas_bus_id(
263
        industrial_loads_list, scn_name, grid_carrier
264
    )
265
266
    # Add carrier
267
    industrial_loads_list["carrier"] = carrier
268
269
    # Remove useless columns
270
    industrial_loads_list = industrial_loads_list.drop(
271
        columns=["geom", "NUTS0", "NUTS1", "bus_id"], errors="ignore"
272
    )
273
274
    msg = (
275
        "The number of load changed when assigning to the respective buses."
276
        f"It should be {number_loads} loads, but only"
277
        f"{len(industrial_loads_list)} got assigned to buses."
278
        f"scn_name: {scn_name}, load carrier: {carrier}, carrier of buses to"
279
        f"connect loads to: {grid_carrier}"
280
    )
281
    assert len(industrial_loads_list) == number_loads, msg
282
283
    return industrial_loads_list
284
285
286
def delete_old_entries(scn_name):
287
    """
288
    Delete CH4 and H2 loads and load time series for the specified scenario
289
290
    This function cleans the database and has no return.
291
292
    Parameters
293
    ----------
294
    scn_name : str
295
        Name of the scenario.
296
297
    """
298
    # Clean tables
299
    db.execute_sql(
300
        f"""
301
        DELETE FROM grid.egon_etrago_load_timeseries
302
        WHERE "load_id" IN (
303
            SELECT load_id FROM grid.egon_etrago_load
304
            WHERE "carrier" IN ('CH4_for_industry', 'H2_for_industry') AND
305
            scn_name = '{scn_name}' AND bus not IN (
306
                SELECT bus_id FROM grid.egon_etrago_bus
307
                WHERE scn_name = '{scn_name}' AND country != 'DE'
308
            )
309
        );
310
        """
311
    )
312
313
    db.execute_sql(
314
        f"""
315
        DELETE FROM grid.egon_etrago_load
316
        WHERE "load_id" IN (
317
            SELECT load_id FROM grid.egon_etrago_load
318
            WHERE "carrier" IN ('CH4_for_industry', 'H2_for_industry') AND
319
            scn_name = '{scn_name}' AND bus not IN (
320
                SELECT bus_id FROM grid.egon_etrago_bus
321
                WHERE scn_name = '{scn_name}' AND country != 'DE'
322
            )
323
        );
324
        """
325
    )
326
327
328
def insert_new_entries(industrial_gas_demand, scn_name):
329
    """
330
    Insert industrial gas loads into the database
331
332
    This function prepares and imports the industrial gas loads, by
333
    executing the following steps:
334
335
      * Attribution of an id to each load in the list received as paramater
336
      * Deletion of the column containing the time series (they will be
337
        inserted in another table (grid.egon_etrago_load_timeseries) in
338
        the :py:func:`insert_industrial_gas_demand_time_series`)
339
      * Insertion of the loads into the database
340
      * Return of the dataframe still containing the time series columns
341
342
    Parameters
343
    ----------
344
    industrial_gas_demand : pandas.DataFrame
345
        Load data to insert (containing the time series)
346
    scn_name : str
347
        Name of the scenario.
348
349
    Returns
350
    -------
351
    industrial_gas_demand : pandas.DataFrame
352
        Dataframe containing the loads that have been inserted in
353
        the database with their time series
354
355
    """
356
357
    new_id = db.next_etrago_id("load")
358
    industrial_gas_demand["load_id"] = range(
359
        new_id, new_id + len(industrial_gas_demand)
360
    )
361
362
    # Add missing columns
363
    c = {"scn_name": scn_name, "sign": -1}
364
    industrial_gas_demand = industrial_gas_demand.assign(**c)
365
366
    industrial_gas_demand = industrial_gas_demand.reset_index(drop=True)
367
368
    # Remove useless columns
369
    egon_etrago_load_gas = industrial_gas_demand.drop(columns=["p_set"])
370
371
    engine = db.engine()
372
    # Insert data to db
373
    egon_etrago_load_gas.to_sql(
374
        "egon_etrago_load",
375
        engine,
376
        schema="grid",
377
        index=False,
378
        if_exists="append",
379
    )
380
381
    return industrial_gas_demand
382
383
384
def insert_industrial_gas_demand_egon2035():
385
    """Insert industrial gas demands into the database for eGon2035
386
387
    Insert the industrial CH4 and H2 demands and their associated time
388
    series into the database for the eGon2035 scenario. The data,
389
    previously downloaded in :py:func:`download_industrial_gas_demand`
390
    are adjusted by executing the following steps:
391
392
      * Clean the database with the fonction :py:func:`delete_old_entries`
393
      * Read and prepare the CH4 and the H2 industrial demands and their
394
        associated time series in Germany with the fonction :py:func:`read_and_process_demand`
395
      * Aggregate the demands with the same properties at the same gas bus
396
      * Insert the loads into the database by executing :py:func:`insert_new_entries`
397
      * Insert the time series associated to the loads into the database
398
        by executing :py:func:`insert_industrial_gas_demand_time_series`
399
400
    Returns
401
    -------
402
    None
403
404
    """
405
    scn_name = "eGon2035"
406
    delete_old_entries(scn_name)
407
408
    industrial_gas_demand = pd.concat(
409
        [
410
            read_and_process_demand(
411
                scn_name=scn_name,
412
                carrier="CH4_for_industry",
413
                grid_carrier="CH4",
414
            ),
415
            read_and_process_demand(
416
                scn_name=scn_name,
417
                carrier="H2_for_industry",
418
                grid_carrier="H2_grid",
419
            ),
420
        ]
421
    )
422
423
    industrial_gas_demand = (
424
        industrial_gas_demand.groupby(["bus", "carrier"])["p_set"]
425
        .apply(lambda x: [sum(y) for y in zip(*x)])
426
        .reset_index(drop=False)
427
    )
428
429
    industrial_gas_demand = insert_new_entries(industrial_gas_demand, scn_name)
430
    insert_industrial_gas_demand_time_series(industrial_gas_demand)
431
432
433
def calculate_total_demand_100RE():
434
    """
435
    Calculate total industrial gas demands in Germany in eGon100RE
436
437
    These global values are red from the p-e-s run.
438
439
    Returns
440
    -------
441
        H2_total_PES, CH4_total_PES : floats
442
            Total industrial gas demand in Germany in eGon100RE
443
444
    """
445
    n = read_network()
446
447
    try:
448
        H2_total_PES = (
449
            n.loads[n.loads["carrier"] == "H2 for industry"].loc[
450
                "DE0 0 H2 for industry", "p_set"
451
            ]
452
            * 8760
453
        )
454
    except KeyError:
455
        H2_total_PES = 42090000
456
        print("Could not find data from PES-run, assigning fallback number.")
457
458
    try:
459
        CH4_total_PES = (
460
            n.loads[n.loads["carrier"] == "gas for industry"].loc[
461
                "DE0 0 gas for industry", "p_set"
462
            ]
463
            * 8760
464
        )
465
    except KeyError:
466
        CH4_total_PES = 105490000
467
        print("Could not find data from PES-run, assigning fallback number.")
468
469
    return H2_total_PES, CH4_total_PES
470
471
472
def insert_industrial_gas_demand_egon100RE():
473
    """
474
    Insert industrial gas demands into the database for eGon100RE
475
476
    Insert the industrial CH4 and H2 demands and their associated time
477
    series into the database for the eGon100RE scenario by executing the
478
    following steps:
479
480
      * Clean the database with the fonction :py:func:`delete_old_entries`
481
      * Read and prepare the CH4 and the H2 industrial demands and their
482
        associated time series in Germany with the fonction :py:func:`read_and_process_demand`
483
      * Calculate total industrial CH4 and H2 demands in Germany in
484
        eGon100RE with the function :py:func:`calculate_total_demand_100RE`
485
      * Adjust the total industrial CH4 and H2 loads for Germany
486
        generated by PyPSA-Eur-Sec
487
          * For the CH4, the time serie used is the one from H2, because
488
            the industrial CH4 demand in the opendata.ffe database is 0
489
          * In test mode, the total values are obtained by
490
            evaluating the share of H2 demand in the test region
491
            (NUTS1: DEF, Schleswig-Holstein) with respect to the H2
492
            demand in full Germany model (NUTS0: DE). This task has been
493
            outsourced to save processing cost.
494
      * Aggregate the demands with the same properties at the same gas bus
495
      * Insert the loads into the database by executing :py:func:`insert_new_entries`
496
      * Insert the time series associated to the loads into the database
497
        by executing :py:func:`insert_industrial_gas_demand_time_series`
498
499
    Parameters
500
    ----------
501
    scn_name : str
502
        Name of the scenario
503
504
    Returns
505
    -------
506
        industrial_gas_demand : Dataframe containing the industrial gas demand
507
        in Germany
508
    """
509
    scn_name = "eGon100RE"
510
    delete_old_entries(scn_name)
511
512
    # read demands
513
    industrial_gas_demand_CH4 = read_and_process_demand(
514
        scn_name=scn_name, carrier="CH4_for_industry", grid_carrier="CH4"
515
    )
516
    industrial_gas_demand_H2 = read_and_process_demand(
517
        scn_name=scn_name, carrier="H2_for_industry", grid_carrier="H2_grid"
518
    )
519
520
    # adjust H2 and CH4 total demands (values from PES)
521
    # CH4 demand = 0 in 100RE, therefore scale H2 ts
522
    # fallback values see https://github.com/openego/eGon-data/issues/626
523
524
    H2_total_PES, CH4_total_PES = calculate_total_demand_100RE()
525
526
    boundary = settings()["egon-data"]["--dataset-boundary"]
527
    if boundary != "Everything":
528
        # modify values for test mode
529
        # the values are obtained by evaluating the share of H2 demand in
530
        # test region (NUTS1: DEF, Schleswig-Holstein) with respect to the H2
531
        # demand in full Germany model (NUTS0: DE). The task has been outsourced
532
        # to save processing cost
533
        H2_total_PES *= 0.01855683050330346
534
        CH4_total_PES *= 0.01855683050330346
535
536
    H2_total = industrial_gas_demand_H2["p_set"].apply(sum).astype(float).sum()
537
538
    industrial_gas_demand_CH4["p_set"] = industrial_gas_demand_H2[
539
        "p_set"
540
    ].apply(lambda x: [val / H2_total * CH4_total_PES for val in x])
541
    industrial_gas_demand_H2["p_set"] = industrial_gas_demand_H2[
542
        "p_set"
543
    ].apply(lambda x: [val / H2_total * H2_total_PES for val in x])
544
545
    # consistency check
546
    total_CH4_distributed = sum(
547
        [sum(x) for x in industrial_gas_demand_CH4["p_set"].to_list()]
548
    )
549
    total_H2_distributed = sum(
550
        [sum(x) for x in industrial_gas_demand_H2["p_set"].to_list()]
551
    )
552
553
    print(
554
        f"Total amount of industrial H2 demand distributed is "
555
        f"{total_H2_distributed} MWh. Total amount of industrial CH4 demand "
556
        f"distributed is {total_CH4_distributed} MWh."
557
    )
558
    msg = (
559
        f"Total amount of industrial H2 demand from P-E-S is equal to "
560
        f"{H2_total_PES}, which should be identical to the distributed amount "
561
        f"of {total_H2_distributed}, but it is not."
562
    )
563
    assert round(H2_total_PES) == round(total_H2_distributed), msg
564
565
    msg = (
566
        f"Total amount of industrial CH4 demand from P-E-S is equal to "
567
        f"{CH4_total_PES}, which should be identical to the distributed amount "
568
        f"of {total_CH4_distributed}, but it is not."
569
    )
570
    assert round(CH4_total_PES) == round(total_CH4_distributed), msg
571
572
    industrial_gas_demand = pd.concat(
573
        [
574
            industrial_gas_demand_CH4,
575
            industrial_gas_demand_H2,
576
        ]
577
    )
578
    industrial_gas_demand = (
579
        industrial_gas_demand.groupby(["bus", "carrier"])["p_set"]
580
        .apply(lambda x: [sum(y) for y in zip(*x)])
581
        .reset_index(drop=False)
582
    )
583
584
    industrial_gas_demand = insert_new_entries(industrial_gas_demand, scn_name)
585
    insert_industrial_gas_demand_time_series(industrial_gas_demand)
586
587
588
def insert_industrial_gas_demand_time_series(egon_etrago_load_gas):
589
    """
590
    Insert list of industrial gas demand time series (one per NUTS3)
591
592
    These loads are hourly and NUTS3-geographic resolved.
593
594
    Parameters
595
    ----------
596
    industrial_gas_demand : pandas.DataFrame
597
        Dataframe containing the loads that have been inserted in
598
        the database and whose time serie will be inserted into the
599
        database.
600
601
    Returns
602
    -------
603
    None
604
605
    """
606
    egon_etrago_load_gas_timeseries = egon_etrago_load_gas
607
608
    # Connect to local database
609
    engine = db.engine()
610
611
    # Adjust columns
612
    egon_etrago_load_gas_timeseries = egon_etrago_load_gas_timeseries.drop(
613
        columns=["carrier", "bus", "sign"]
614
    )
615
    egon_etrago_load_gas_timeseries["temp_id"] = 1
616
617
    # Insert data to db
618
    egon_etrago_load_gas_timeseries.to_sql(
619
        "egon_etrago_load_timeseries",
620
        engine,
621
        schema="grid",
622
        index=False,
623
        if_exists="append",
624
    )
625
626
627
def download_industrial_gas_demand():
628
    """Download the industrial gas demand data from opendata.ffe database
629
630
    The industrial demands for hydrogen and methane are downloaded in
631
    the folder ./datasets/gas_data/demand and the function has no
632
    return.
633
    These loads are hourly and NUTS3-geographic resolved. For more
634
    information on these data, refer to the `Extremos project documentation <https://opendata.ffe.de/project/extremos/>`_.
635
636
    """
637
    correspondance_url = (
638
        "http://opendata.ffe.de:3000/region?id_region_type=eq.38"
639
    )
640
641
    # Read and save data
642
    result_corr = requests.get(correspondance_url)
643
    target_file = Path(".") / "datasets/gas_data/demand/region_corr.json"
644
    os.makedirs(os.path.dirname(target_file), exist_ok=True)
645
    pd.read_json(result_corr.content).to_json(target_file)
646
647
    carriers = {"H2_for_industry": "2,162", "CH4_for_industry": "2,11"}
648
    url = "http://opendata.ffe.de:3000/opendata?id_opendata=eq.66&&year=eq."
649
650
    for scn_name in ["eGon2035", "eGon100RE"]:
651
        year = str(
652
            get_sector_parameters("global", scn_name)["population_year"]
653
        )
654
655
        for carrier, internal_id in carriers.items():
656
            # Download the data
657
            datafilter = "&&internal_id=eq.{" + internal_id + "}"
658
            request = url + year + datafilter
659
660
            # Read and save data
661
            result = requests.get(request)
662
            target_file = (
663
                Path(".")
664
                / "datasets/gas_data/demand"
665
                / (carrier + "_" + scn_name + ".json")
666
            )
667
            pd.read_json(result.content).to_json(target_file)
668