From e42ec299f8560fd1a28e1ed2e4fd2ef1ddd8579d Mon Sep 17 00:00:00 2001 From: maverick-7487 <93658675+maverick-7487@users.noreply.github.com> Date: Fri, 29 May 2026 15:18:58 +0200 Subject: [PATCH 1/2] script to reset ppcon floats --- src/bitsea/Float/ppcon/reset_ppcon_dataset.py | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/bitsea/Float/ppcon/reset_ppcon_dataset.py diff --git a/src/bitsea/Float/ppcon/reset_ppcon_dataset.py b/src/bitsea/Float/ppcon/reset_ppcon_dataset.py new file mode 100644 index 00000000..14d23538 --- /dev/null +++ b/src/bitsea/Float/ppcon/reset_ppcon_dataset.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +import argparse +import os +import shutil +from pathlib import Path + + +def argument() -> argparse.Namespace: + parser = argparse.ArgumentParser( + description="""Filter UPDATE_FILE_PATH rows and maintain PPCON copies from SUPERFLOAT.""") + parser.add_argument( + "--UPDATE_FILE_PATH", + required=True, + help="Path to the update file (input CSV-like text).", + ) + parser.add_argument( + "--LOCAL_INPUT", + required=True, + help="Path to the local filtered file to write.", + ) + return parser.parse_args() + + +def _strip_prefix_once(value: str, prefix: str) -> str: + return value.replace(prefix, "", 1) + + +def main() -> str: + args = argument() + + online_repo = os.environ.get("ONLINE_REPO") + if not online_repo: + raise RuntimeError("ONLINE_REPO environment variable is not set.") + + update_file_path = Path(args.UPDATE_FILE_PATH) + local_input = Path(args.LOCAL_INPUT) + + local_input.parent.mkdir(parents=True, exist_ok=True) + + with update_file_path.open("r", encoding="utf-8") as src, local_input.open("w", encoding="utf-8") as dst: + for raw_line in src: + line = raw_line.rstrip("\n") + if not line: + continue + + filename = line.split(",", 1)[0] + v1 = _strip_prefix_once(filename, "coriolis/") + v2 = _strip_prefix_once(v1, "profiles/") + superfloat_file = Path(online_repo) / "SUPERFLOAT" / v2 + + # Keep only lines that already exist in SUPERFLOAT. + if superfloat_file.is_file(): + dst.write(line + "\n") + + wmo = v2.split("/", 1)[0] + ppcon_wmo = Path(online_repo) / "PPCON" / wmo + ppcon_wmo.mkdir(parents=True, exist_ok=True) + + dst_file = Path(online_repo) / "PPCON" / v2 + dst_file.parent.mkdir(parents=True, exist_ok=True) + shutil.copy2(superfloat_file, dst_file) + + nrows_int = sum(1 for _ in dst) + nrows = str(nrows_int) + + return nrows + + +if __name__ == "__main__": + nr_value = main() + # Print only NR so shell can capture it with command substitution. + print(nr_value) \ No newline at end of file From cc125d15ace5264f7e8575fb5f106298a082d0f1 Mon Sep 17 00:00:00 2001 From: maverick-7487 <93658675+maverick-7487@users.noreply.github.com> Date: Fri, 29 May 2026 15:54:07 +0200 Subject: [PATCH 2/2] adjustments to input parameters of reset_ppcon_dataset.py --- src/bitsea/Float/ppcon/reset_ppcon_dataset.py | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/bitsea/Float/ppcon/reset_ppcon_dataset.py b/src/bitsea/Float/ppcon/reset_ppcon_dataset.py index 14d23538..52e89431 100644 --- a/src/bitsea/Float/ppcon/reset_ppcon_dataset.py +++ b/src/bitsea/Float/ppcon/reset_ppcon_dataset.py @@ -9,15 +9,29 @@ def argument() -> argparse.Namespace: parser = argparse.ArgumentParser( description="""Filter UPDATE_FILE_PATH rows and maintain PPCON copies from SUPERFLOAT.""") parser.add_argument( - "--UPDATE_FILE_PATH", + "--inputfile", + "-i", required=True, - help="Path to the update file (input CSV-like text).", + help="Path to the update file (input list of float files).", ) parser.add_argument( - "--LOCAL_INPUT", + "--outputfile", + "-o", required=True, help="Path to the local filtered file to write.", ) + parser.add_argument( + "--inputdir", + "-I", + required=True, + help="Path to the directory containing the input superfloat files.", + ) + parser.add_argument( + "--outputdir", + "-O", + required=True, + help="Path to the directory where the PPCON files will be maintained.", + ) return parser.parse_args() @@ -25,15 +39,13 @@ def _strip_prefix_once(value: str, prefix: str) -> str: return value.replace(prefix, "", 1) -def main() -> str: +def main(): args = argument() - online_repo = os.environ.get("ONLINE_REPO") - if not online_repo: - raise RuntimeError("ONLINE_REPO environment variable is not set.") - - update_file_path = Path(args.UPDATE_FILE_PATH) - local_input = Path(args.LOCAL_INPUT) + update_file_path = Path(args.inputfile) + local_input = Path(args.outputfile) + superfloat_dir = Path(args.inputdir) + ppcon_dir = Path(args.outputdir) local_input.parent.mkdir(parents=True, exist_ok=True) @@ -46,27 +58,21 @@ def main() -> str: filename = line.split(",", 1)[0] v1 = _strip_prefix_once(filename, "coriolis/") v2 = _strip_prefix_once(v1, "profiles/") - superfloat_file = Path(online_repo) / "SUPERFLOAT" / v2 + superfloat_file = superfloat_dir / v2 # Keep only lines that already exist in SUPERFLOAT. if superfloat_file.is_file(): dst.write(line + "\n") + # Maintain PPCON copy of the file. + wmo = v2.split("/", 1)[0] - ppcon_wmo = Path(online_repo) / "PPCON" / wmo + ppcon_wmo = ppcon_dir / wmo ppcon_wmo.mkdir(parents=True, exist_ok=True) - dst_file = Path(online_repo) / "PPCON" / v2 + dst_file = ppcon_dir / v2 dst_file.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(superfloat_file, dst_file) - nrows_int = sum(1 for _ in dst) - nrows = str(nrows_int) - - return nrows - - if __name__ == "__main__": - nr_value = main() - # Print only NR so shell can capture it with command substitution. - print(nr_value) \ No newline at end of file + main() \ No newline at end of file