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 committed Feb 6, 2025
1 parent 0ee2899 commit 95f4380
Show file tree
Hide file tree
Showing 3 changed files with 38 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: 13 additions & 0 deletions pydropsonde/helper/rawreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 24 additions & 15 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,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:
Expand Down

0 comments on commit 95f4380

Please sign in to comment.