Skip to content
Snippets Groups Projects
Commit 9d9a4c37 authored by Michel Spils's avatar Michel Spils
Browse files

wiski export

parent cd43fc61
Branches
Tags
No related merge requests found
...@@ -107,13 +107,14 @@ def read_dat_file(zip_file:Path,dat_file:str,tsVorh:str) -> pd.DataFrame: ...@@ -107,13 +107,14 @@ def read_dat_file(zip_file:Path,dat_file:str,tsVorh:str) -> pd.DataFrame:
df = df[["timestamp","forecast","member","pegel"]] df = df[["timestamp","forecast","member","pegel"]]
return df return df
def writeZrxp(target_file:Path,df:pd.DataFrame): def writeZrxp(target_file:Path,df:pd.DataFrame,only_two=False):
"""Writes the DataFrame to a .zrx file with the correct header. """Writes the DataFrame to a .zrx file with the correct header.
Overwrites the file if it already exists. Overwrites the file if it already exists.
Args: Args:
target_file (Path): Where the file should be saved target_file (Path): Where the file should be saved
df (pd.DataFrame): DataFrame with zrx data df (pd.DataFrame): DataFrame with zrx data
only_two (bool, optional): If True, only the cols for wiski are written.
""" """
if target_file.exists(): if target_file.exists():
print(f"Overwriting existing file {target_file}") print(f"Overwriting existing file {target_file}")
...@@ -122,6 +123,10 @@ def writeZrxp(target_file:Path,df:pd.DataFrame): ...@@ -122,6 +123,10 @@ def writeZrxp(target_file:Path,df:pd.DataFrame):
with open(target_file , 'w', encoding='utf-8') as file: with open(target_file , 'w', encoding='utf-8') as file:
file.write('#REXCHANGE9530010.W.BSH_VH|*|\n') file.write('#REXCHANGE9530010.W.BSH_VH|*|\n')
file.write('#RINVAL-777|*|\n') file.write('#RINVAL-777|*|\n')
if only_two:
file.write('#LAYOUT(timestamp,value)|*|\n')
df = df[["forecast","pegel"]]
else:
file.write('#LAYOUT(timestamp,forecast,member,value)|*|\n') file.write('#LAYOUT(timestamp,forecast,member,value)|*|\n')
df.to_csv(path_or_buf =target_file , df.to_csv(path_or_buf =target_file ,
...@@ -158,7 +163,7 @@ def main(): ...@@ -158,7 +163,7 @@ def main():
target_file = make_target_file_name(base_dir / '4WISKI',tsVorh) target_file = make_target_file_name(base_dir / '4WISKI',tsVorh)
df = read_dat_file(mos_file_name,dat_file,tsVorh) df = read_dat_file(mos_file_name,dat_file,tsVorh)
writeZrxp(target_file,df) writeZrxp(target_file,df,only_two=True)
#Resample and cut data to fit the 3h interval, hourly sample rate used by ICON #Resample and cut data to fit the 3h interval, hourly sample rate used by ICON
df2 = df[["forecast","pegel"]].resample("1h",on="forecast").first() df2 = df[["forecast","pegel"]].resample("1h",on="forecast").first()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment