Skip to content

Commit

Permalink
Add_industry_heat_profile (#3)
Browse files Browse the repository at this point in the history
* Loaded electricity profile from industry as IND-PHH profile

* Finished industry heat demand profile

* Made sure all python scripts are also tracked by snakemake

* Merge branch 'spatial_study' into add_industry_heat_profile
  • Loading branch information
Mathias157 authored Sep 24, 2024
1 parent d737821 commit b5a2ed0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 44 deletions.
58 changes: 45 additions & 13 deletions src/Modules/exo_heat_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,17 @@ def create_INDIVUSERS_DH(incfile, new_dataset: xr.Dataset):

## 2.3.2 INDUSTRY_DH_VAR_T.inc
@create_incfile
def create_INDUSTRY_DH_VAR_T(incfile):
incfile.body = '\n'.join([
"* Assume that heat demand profile of industry correlates exactly to electricity demand profile",
"DH_VAR_T(AAA,'IND-PHH',SSS,TTT)$(SUM((S,T), DE_VAR_T(RRR,'PII',SSS,TTT))) = DE_VAR_T(RRR,'PII',SSS,TTT);",
"DH_VAR_T(AAA,'IND-PHM',SSS,TTT)$(SUM((S,T), DE_VAR_T(RRR,'PII',SSS,TTT))) = DE_VAR_T(RRR,'PII',SSS,TTT);",
"DH_VAR_T(AAA,'IND-PHL',SSS,TTT)$(SUM((S,T), DE_VAR_T(RRR,'PII',SSS,TTT))) = DE_VAR_T(RRR,'PII',SSS,TTT);"
])
def create_INDUSTRY_DH_VAR_T(incfile, el_new_dataset: xr.Dataset):
incfile.body = (
transform_xrdata(el_new_dataset,
'electricity_demand_mwh')
.to_dataframe()
.reset_index()
)
incfile.body.loc[:, 'A'] = incfile.body.loc[:, 'A'].values + '_IND-HT-NODH'
incfile.body_prepare(['S', 'T'],
['A', 'DHUSER'], values='electricity_demand_mwh')


#%% ------------------------------- ###
### 3. Main ###
Expand All @@ -211,22 +215,39 @@ def main(show_difference: bool = False):

# 3.1 Format Dataset
conversion_file = 'Modules/Submodules/exo_heat_dem_conversion_dictionaries.pkl'

## 3.1.1 Heat Demand
dataset, new_dataset = convert_names(conversion_file, dataset, 'heat_demand_mwh')

## Drop dimensions
### Drop dimensions
new_dataset = (
new_dataset
.drop_dims(['lat', 'lon'])
.drop_vars('polygons')
)

if show_difference:
print('###\nHeat Dataset\n###')
print('Before: \n', dataset, '\n\n')
print('After: \n', new_dataset, '\n\n')

## 3.1.2 Electricity Profile for Industry
eldem = (
xr.load_dataset('Data/Timeseries/energinet_eldem.nc')
.sel(user='industry')
.assign_coords(user='industry_phh')
.rename({'week' : 'S', 'hour' : 'T'})
)
eldataset, el_new_dataset = convert_names(conversion_file, eldem, 'electricity_demand_mwh', convert_seasons_and_terms=True)

if show_difference:
print('###\nElectricity Dataset\n###')
print('Before: \n', eldataset, '\n\n')
print('After: \n', el_new_dataset, '\n\n')


out_path = 'Output'

# 3.2 Create .inc files
out_path = 'Output'
## 3.2.1 DH.inc
create_DH(new_dataset=new_dataset, name='DH', path=out_path,
prefix='\n'.join([
Expand Down Expand Up @@ -285,10 +306,21 @@ def main(show_difference: bool = False):
]))

## 1.3 Make Heat Variation Profiles
create_INDUSTRY_DH_VAR_T(name='INDUSTRY_DH_VAR_T', path=out_path,
prefix='', suffix='')
create_INDUSTRY_DH_VAR_T(el_new_dataset=el_new_dataset,
name='INDUSTRY_DH_VAR_T',
path=out_path,
prefix="""TABLE DH_VAR_T_IND(SSS,TTT,AAA,DHUSER)\n""",
suffix="""\n;\n* Collect series to other heat series, if there is a industry heat series
DH_VAR_T(AAA,DHUSER,SSS,TTT)$(SUM((S,T), DH_VAR_T_IND(S,T,AAA,DHUSER))) = DH_VAR_T_IND(SSS,TTT,AAA,DHUSER);
DH_VAR_T_IND(SSS,TTT,AAA,DHUSER)=0;
* Assume that other temperature processes follow the same pattern, if there is a profile
DH_VAR_T(AAA,'IND-PHM',SSS,TTT)$(SUM((S,T), DH_VAR_T(AAA,'IND-PHH',SSS,TTT))) = DH_VAR_T(AAA,'IND-PHH',SSS,TTT);
DH_VAR_T(AAA,'IND-PHL',SSS,TTT)$(SUM((S,T), DH_VAR_T(AAA,'IND-PHH',SSS,TTT))) = DH_VAR_T(AAA,'IND-PHH',SSS,TTT);
""")




if __name__ == '__main__':
main()
main(show_difference=False)
54 changes: 23 additions & 31 deletions src/snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,40 @@ rule create_conversion_dictionaries:
output:
[f"{submod_path}exo_elec_dem_conversion_dictionaries.pkl",
f"{submod_path}exo_heat_dem_conversion_dictionaries.pkl"]
shell:
f"""
python {submod_path}create_conversion_dictionaries.py
"""

script:
f"{submod_path}create_conversion_dictionaries.py"

rule get_grid_from_Balmorel:
output:
f"{data_path}Power Grid/municipal_connectivity.nc"
shell:
"""
python Modules/Submodules/get_grid.py
"""
script:
f"{submod_path}get_grid.py"

rule do_clustering:
input:
f"{data_path}Power Grid/municipal_connectivity.nc"
shell:
"""
python Modules/clustering.py
"""
script:
f"{modules_path}clustering.py"

# 2. Exogenous Electricity Demands
rule format_energinet_data:
input:
f"{data_path}Timeseries/ElConsumptionEnerginet2023.csv"
output:
f"{data_path}Timeseries/energinet_eldem.nc"
shell:
"""
python Modules/format_energinet.py
"""
script:
f"{modules_path}format_energinet.py"

rule exo_electricity_demand:
input:
[f"{submod_path}exo_elec_dem_conversion_dictionaries.pkl", f"{data_path}Timeseries/energinet_eldem.nc"]
[f"{submod_path}exo_elec_dem_conversion_dictionaries.pkl",
f"{data_path}Timeseries/energinet_eldem.nc",
f"{modules_path}exo_electricity_demand.py"]
output:
[f"{out_path}DE.inc", f"{out_path}DE_VAR_T.inc"]
shell:
"""
python Modules/exo_electricity_demand.py --conversion-file={input[0]} --el-dataset={input[1]} --show-difference=False
python {input[2]} --conversion-file={input[0]} --el-dataset={input[1]} --show-difference=False
"""

# 3. Exogenous Heat Demands
Expand All @@ -67,19 +61,18 @@ rule format_vpdk21_data:
output:
[f"{data_path}AAU Kommuneplan/districtheat_exo_heatdem.nc",
f"{data_path}AAU Kommuneplan/industry_exo_heatdem.nc"]
shell:
"""
python Modules/format_vpdk21.py
"""
script:
f"{modules_path}format_vpdk21.py"

rule format_dkstat_industry_data:
input:
r"Data\Danmarks Statistik\Industriforbrug Type.xlsx"
[r"Data\Danmarks Statistik\Industriforbrug Type.xlsx",
f"{modules_path}format_dkstat.py"]
output:
f"{data_path}Danmarks Statistik/industry_demand.nc"
shell:
"""
python Modules/format_dkstat.py --get-industry-demand
python {input[1]} --get-industry-demand
"""

rule exo_heat_demand:
Expand All @@ -93,19 +86,18 @@ rule exo_heat_demand:
[f'{out_path}DH.inc', f'{out_path}DH_VAR_T.inc',
f'{out_path}INDUSTRY_DH.inc', f'{out_path}INDUSTRY_DH_VAR_T.inc',
f'{out_path}INDIVUSERS_DH.inc', f'{out_path}INDIVUSERS_DH_VAR_T.inc']
shell:
"""
python Modules/exo_heat_demand.py
"""
script:
f"{modules_path}exo_heat_demand.py"

# 4. Transport Demand
rule format_dkstat_transport_data:
input:
r"Data\Danmarks Statistik\Transportforbrug Type.xlsx"
[r"Data\Danmarks Statistik\Transportforbrug Type.xlsx",
f"{modules_path}format_dkstat.py"]
output:
f"{data_path}Danmarks Statistik/transport_demand.csv"
shell:
"""
python Modules/format_dkstat.py --get-transport-demand --include-bunkering=false
python {input[1]} --get-transport-demand --include-bunkering=false
"""

0 comments on commit b5a2ed0

Please sign in to comment.