From 95f4380c6c78bc94c23a6343f618ec9e7d958cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=B6lling?= Date: Thu, 6 Feb 2025 13:13:43 +0100 Subject: [PATCH] detect minisondes and apply minisonde profile in aspen This change will automatically detect minisondes and will run the aspen CLI with the mini-dropsonde profile in these cases. --- pydropsonde/helper/paths.py | 1 + pydropsonde/helper/rawreader.py | 13 +++++++++++ pydropsonde/processor.py | 39 ++++++++++++++++++++------------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/pydropsonde/helper/paths.py b/pydropsonde/helper/paths.py index fa0b743b..675b4680 100644 --- a/pydropsonde/helper/paths.py +++ b/pydropsonde/helper/paths.py @@ -169,6 +169,7 @@ def populate_sonde_instances(self, config) -> Dict: launch_time = "UNKNOWN" Sondes[sonde_id] = Sonde(_serial_id=sonde_id, _launch_time=launch_time) Sondes[sonde_id].add_launch_detect(launch_detect) + Sondes[sonde_id].sonde_rev = rr.get_sonde_rev(a_file) Sondes[sonde_id].add_flight_id( self.flight_id, config.get( diff --git a/pydropsonde/helper/rawreader.py b/pydropsonde/helper/rawreader.py index 6f7ff315..21a82b2b 100644 --- a/pydropsonde/helper/rawreader.py +++ b/pydropsonde/helper/rawreader.py @@ -91,6 +91,19 @@ def get_sonde_id(a_file: "str") -> str: return afile_base.split(".")[0][1:] +def get_sonde_rev(a_file: str) -> str: + with open(a_file, "r") as f: + module_logger.debug(f"Opened File: {a_file=}") + lines = f.readlines() + + for i, line in enumerate(lines): + if "Sonde ID/Type/Rev" in line: + module_logger.debug(f'"Sonde ID/Type/Rev" found on line {i=}') + break + + return lines[i].split(":")[1].split(",")[2].lstrip() + + def get_launch_time(a_file: "str") -> np.datetime64: """Returns launch time for a given A-file diff --git a/pydropsonde/processor.py b/pydropsonde/processor.py index fb1930e0..e103c1e2 100644 --- a/pydropsonde/processor.py +++ b/pydropsonde/processor.py @@ -43,6 +43,7 @@ class Sonde: cont: bool = True _: KW_ONLY _launch_time: Optional[Any] = None + sonde_rev: Optional[str] = None @property def flight_id(self): @@ -80,6 +81,10 @@ def l2_ds(self): def set_l2_ds(self, ds): self._l2_ds = ds + @property + def is_minisonde(self): + return self.sonde_rev == "N1" + def __post_init__(self): """ Initializes the 'qc' attribute as an empty object and sets the 'sort_index' attribute based on 'launch_time'. @@ -241,21 +246,25 @@ def run_aspen(self, path_to_postaspenfile: str = None) -> None: if os.path.getsize(os.path.join(l0_dir, dname)) > 0: os.makedirs(l1_dir, exist_ok=True) - subprocess.run( - [ - "docker", - "run", - "--rm", - "--mount", - f"type=bind,source={l0_dir},target=/input", - "--mount", - f"type=bind,source={l1_dir},target=/output", - "ghcr.io/atmdrops/aspenqc:4.0.2", - "-i", - f"/input/{dname}", - "-n", - f"/output/{l1_name}", - ], + command = [ + "docker", + "run", + "--rm", + "--mount", + f"type=bind,source={l0_dir},target=/input", + "--mount", + f"type=bind,source={l1_dir},target=/output", + "ghcr.io/atmdrops/aspenqc:4.0.2", + "-i", + f"/input/{dname}", + "-n", + f"/output/{l1_name}", + ] + + if self.is_minisonde: + command += ["-1", "mini-dropsonde"] + + subprocess.run(command, check=True, ) else: