diff --git a/src/scripts/bsh_extractor_v2.py b/src/scripts/bsh_extractor_v2.py index 6e28958c680c77f33488ca312b48dfde2d818fed..3d79c39d2a61c0e26cfa4aa46ca7a03644469ce7 100644 --- a/src/scripts/bsh_extractor_v2.py +++ b/src/scripts/bsh_extractor_v2.py @@ -107,13 +107,14 @@ def read_dat_file(zip_file:Path,dat_file:str,tsVorh:str) -> pd.DataFrame: df = df[["timestamp","forecast","member","pegel"]] 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. Overwrites the file if it already exists. Args: target_file (Path): Where the file should be saved df (pd.DataFrame): DataFrame with zrx data + only_two (bool, optional): If True, only the cols for wiski are written. """ if target_file.exists(): print(f"Overwriting existing file {target_file}") @@ -122,7 +123,11 @@ def writeZrxp(target_file:Path,df:pd.DataFrame): with open(target_file , 'w', encoding='utf-8') as file: file.write('#REXCHANGE9530010.W.BSH_VH|*|\n') file.write('#RINVAL-777|*|\n') - file.write('#LAYOUT(timestamp,forecast,member,value)|*|\n') + if only_two: + file.write('#LAYOUT(timestamp,value)|*|\n') + df = df[["forecast","pegel"]] + else: + file.write('#LAYOUT(timestamp,forecast,member,value)|*|\n') df.to_csv(path_or_buf =target_file , header = False, @@ -158,7 +163,7 @@ def main(): target_file = make_target_file_name(base_dir / '4WISKI',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 df2 = df[["forecast","pegel"]].resample("1h",on="forecast").first()