From 65498f79ce53741b6d08f2c8145e421afd2b21ae Mon Sep 17 00:00:00 2001 From: Christian Chwala Date: Fri, 17 Jul 2026 11:00:13 +0200 Subject: [PATCH] Update CHWALA reader to handle daily zip archives of .dat files --- disdrodb/l0/readers/LPM/KIT/CHWALA.py | 38 ++++++++++++--------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/disdrodb/l0/readers/LPM/KIT/CHWALA.py b/disdrodb/l0/readers/LPM/KIT/CHWALA.py index 9ce60ae2..4afb73a7 100644 --- a/disdrodb/l0/readers/LPM/KIT/CHWALA.py +++ b/disdrodb/l0/readers/LPM/KIT/CHWALA.py @@ -16,13 +16,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -----------------------------------------------------------------------------. -"""DISDRODB reader for GID LPM sensors not measuring wind.""" -import os +"""DISDRODB reader for KIT IMK-IFU Thies LPM disdrometer.""" +import zipfile import pandas as pd from disdrodb.l0.l0_reader import is_documented_by, reader_generic_docstring from disdrodb.l0.l0a_processing import read_raw_text_file +from disdrodb.utils.logger import log_error @is_documented_by(reader_generic_docstring) @@ -199,27 +200,22 @@ def read_txt_file(file, filename): # Return the dataframe adhering to DISDRODB L0 standards return df - #### TEMPORARY: to read just a single 1-min timestep - df = read_txt_file(file=filepath, filename=os.path.basename(filepath)) - - #### FUTURE: Iterate over all files (aka 1-min timesteps) in the daily zip archive - # - Each file contain a single timestep ! - # list_df = [] - # with zipfile.ZipFile(filepath, "r") as zip_ref: - # filenames = sorted(zip_ref.namelist()) - # for filename in filenames: - # if filename.endswith(".dat"): - # # Open file - # with zip_ref.open(filename) as file: - # try: - # df = read_txt_file(file=file, filename=filename) - # list_df.append(df) - # except Exception as e: - # msg = f"An error occurred while reading {filename}. The error is: {e}." - # log_error(logger=logger, msg=msg, verbose=True) + #### Iterate over all .dat files in the daily zip archive + list_df = [] + with zipfile.ZipFile(filepath, "r") as zip_ref: + filenames = sorted(zip_ref.namelist()) + for filename in filenames: + if filename.endswith(".dat"): + with zip_ref.open(filename) as file: + try: + df = read_txt_file(file=file, filename=filename) + list_df.append(df) + except Exception as e: + msg = f"An error occurred while reading {filename}. The error is: {e}." + log_error(logger=logger, msg=msg, verbose=True) # Concatenate all dataframes into a single one - # df = pd.concat(list_df) + df = pd.concat(list_df) # Return the dataframe adhering to DISDRODB L0 standards return df