From b5a2ed0757dd88695d9ade2a38a9f683354a3579 Mon Sep 17 00:00:00 2001 From: Mathias Berg Rosendal <77012503+Mathias157@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:32:48 +0200 Subject: [PATCH] Add_industry_heat_profile (#3) * 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 --- src/Modules/exo_heat_demand.py | 58 ++++++++++++++++++++++++++-------- src/snakefile | 54 ++++++++++++++----------------- 2 files changed, 68 insertions(+), 44 deletions(-) diff --git a/src/Modules/exo_heat_demand.py b/src/Modules/exo_heat_demand.py index 1a57f6a..70d0cd4 100644 --- a/src/Modules/exo_heat_demand.py +++ b/src/Modules/exo_heat_demand.py @@ -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 ### @@ -211,9 +215,11 @@ 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']) @@ -221,12 +227,27 @@ def main(show_difference: bool = False): ) 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([ @@ -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() \ No newline at end of file + main(show_difference=False) \ No newline at end of file diff --git a/src/snakefile b/src/snakefile index abeaafe..d5f7b87 100644 --- a/src/snakefile +++ b/src/snakefile @@ -18,26 +18,20 @@ 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: @@ -45,19 +39,19 @@ rule format_energinet_data: 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 @@ -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: @@ -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 """ \ No newline at end of file