Skip to content

Commit

Permalink
detect minisondes and apply minisonde profile in aspen
Browse files Browse the repository at this point in the history
This change will automatically detect minisondes and will run the aspen
CLI with the mini-dropsonde profile in these cases.
  • Loading branch information
d70-t authored and hgloeckner committed Feb 6, 2025
1 parent e942a8d commit 1788f5b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions pydropsonde/helper/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 12 additions & 1 deletion pydropsonde/helper/rawreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from datetime import datetime
import logging
from typing import List
from typing import List, Optional
import os
import fsspec
import yaml
Expand Down Expand Up @@ -91,6 +91,17 @@ def get_sonde_id(a_file: "str") -> str:
return afile_base.split(".")[0][1:]


def get_sonde_rev(a_file: str) -> Optional[str]:
with open(a_file, "r") as f:
module_logger.debug(f"Opened File: {a_file=}")

for i, line in enumerate(f):
if "Sonde ID/Type/Rev" in line:
module_logger.debug(f'"Sonde ID/Type/Rev" found on line {i=}')
return line.split(":")[1].split(",")[2].lstrip()
return None


def get_launch_time(a_file: "str") -> np.datetime64:
"""Returns launch time for a given A-file
Expand Down
38 changes: 24 additions & 14 deletions pydropsonde/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -241,21 +246,26 @@ 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)

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(
[
"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,
check=True,
)
else:
Expand Down

0 comments on commit 1788f5b

Please sign in to comment.