Skip to content

Commit

Permalink
Wrote code for writing DE and DE_VAR_T
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias157 committed Sep 20, 2024
1 parent 6354bca commit 0fdb733
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

"""Is used to convert the easy-to-read-for-non-balmorel-user sets and elements to Balmorel input
"""
import pickle



conversion_dictionaries = {


Expand All @@ -12,7 +15,14 @@

'coord_element_names' : {'user' : {'industry' : 'PII',
'public' : 'OTHER',
'residential' : 'RESE'}},
'residential' : 'RESE'},
'municipality' : {'æ' : 'ae',
'ø' : 'oe',
'å' : 'aa',
'Æ' : 'Ae',
'Ø' : 'Oe',
'Å' : 'Aa'
}},

'week_to_seasons' : ['S0%d'%i for i in range(1, 10)] +\
['S%d'%i for i in range(10, 53)],
Expand Down
62 changes: 57 additions & 5 deletions RawDataProcessing/Modules/createDE.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import matplotlib.pyplot as plt
import pandas as pd
import textwrap
import numpy as np
import click
import pickle
Expand Down Expand Up @@ -51,6 +52,15 @@
### ------------------------------- ###

def convert_names(conversion_file: str, el_dataset: str):
"""_summary_
Args:
conversion_file (str): _description_
el_dataset (str): _description_
Returns:
_type_: _description_
"""
# Load dataset
dataset = xr.load_dataset(el_dataset)

Expand Down Expand Up @@ -78,7 +88,7 @@ def convert_names(conversion_file: str, el_dataset: str):

return dataset, new_dataset

def make_inc_file(xarray: xr.Dataset,
def transform_xrdata(xarray: xr.Dataset,
data_variable: str,
selection: Tuple[dict, None] = None,
sets_to_sum: Tuple[str, list, None] = None):
Expand All @@ -94,7 +104,7 @@ def make_inc_file(xarray: xr.Dataset,
if selection != None:
output = output.sel(selection)

print(output)
return output

# Main function
@click.command()
Expand Down Expand Up @@ -124,10 +134,52 @@ def main(conversion_file: str,
print('After: \n', new_dataset, '\n\n')

# 1.2 Make .inc-files
out_path = 'Output'
## 1.2.1 DE
make_inc_file(new_dataset,
'electricity_demand_mwh',
sets_to_sum=['S', 'T'])
DE = IncFile(name='DE',
prefix=textwrap.dedent("""* Data from Energinet Dataservice 2023
TABLE DE1(RRR,DEUSER,YYY) 'Annual electricity consumption (MWh)'
"""),
suffix=textwrap.dedent(""";
DE(YYY,RRR,DEUSER)=DE1(RRR,DEUSER,YYY);
DE('2050',RRR,DEUSER) = DE('2023', RRR, DEUSER);
"""),
path=out_path
)
### Sum to annual electricity demands
DE.body = (
transform_xrdata(new_dataset,
'electricity_demand_mwh',
sets_to_sum=['S', 'T'])
.to_dataframe()
)
DE.body_prepare(['R', 'DEUSER'],
'Y',
values='electricity_demand_mwh')
DE.save()

## 1.2.2 DE_VAR_T
DE_VAR_T = IncFile(name='DE_VAR_T',
prefix=textwrap.dedent("""
* Data from Energinet Dataservice 2023
TABLE DE_VAR_T1(DEUSER,SSS,TTT,RRR) "Variation in electricity demand"
"""),
suffix=textwrap.dedent("""
;
PARAMETER DE_VAR_T(RRR,DEUSER,SSS,TTT) "Variation in electricity demand";
DE_VAR_T(RRR,DEUSER,SSS,TTT) = DE_VAR_T1(DEUSER,SSS,TTT,RRR);
"""),
path=out_path)
DE_VAR_T.body = (
transform_xrdata(new_dataset,
'electricity_demand_mwh')
.to_dataframe()
)
DE_VAR_T.body_prepare(['DEUSER', 'S', 'T'],
'R',
values='electricity_demand_mwh')
DE_VAR_T.save()


if __name__ == '__main__':
main()

0 comments on commit 0fdb733

Please sign in to comment.