Skip to content

Commit 4ae493c

Browse files
committed
Support filepaths in PollyXT processing
1 parent 7d4c979 commit 4ae493c

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

cloudnetpy/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def _process_instrument_product(
171171
fun = instruments.thies2nc
172172
input_files = _concatenate_(input_files, tmpdir)
173173
case ("lidar", _id) if "pollyxt" in _id:
174+
site_meta["snr_limit"] = calibration.get("snr_limit", 25)
174175
fun = instruments.pollyxt2nc
175176
case ("lidar", _id) if _id == "cl61d":
176177
fun = instruments.ceilo2nc

cloudnetpy/instruments/pollyxt.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import glob
55
import logging
66
from collections import Counter
7+
from collections.abc import Sequence
8+
from fnmatch import fnmatch
79
from os import PathLike
810
from uuid import UUID
911

@@ -21,7 +23,7 @@
2123

2224

2325
def pollyxt2nc(
24-
input_folder: str | PathLike,
26+
input_data: str | PathLike | Sequence[str | PathLike],
2527
output_file: str | PathLike,
2628
site_meta: dict,
2729
uuid: str | UUID | None = None,
@@ -30,7 +32,8 @@ def pollyxt2nc(
3032
"""Converts PollyXT Raman lidar data into Cloudnet Level 1b netCDF file.
3133
3234
Args:
33-
input_folder: Path to pollyxt netCDF files.
35+
input_data: Path to folder containing pollyxt netCDF files
36+
or a sequence of filename paths.
3437
output_file: Output filename.
3538
site_meta: Dictionary containing information about the site with keys:
3639
@@ -58,7 +61,7 @@ def pollyxt2nc(
5861
uuid = utils.get_uuid(uuid)
5962
snr_limit = site_meta.get("snr_limit", 2)
6063
polly = PollyXt(site_meta, date)
61-
epoch = polly.fetch_data(input_folder)
64+
epoch = polly.fetch_data(input_data)
6265
polly.get_date_and_time(epoch)
6366
polly.fetch_zenith_angle()
6467
polly.calc_screened_products(snr_limit)
@@ -102,10 +105,19 @@ def fetch_zenith_angle(self) -> None:
102105
default = 5
103106
self.data["zenith_angle"] = float(self.metadata.get("zenith_angle", default))
104107

105-
def fetch_data(self, input_folder: str | PathLike) -> datetime.datetime:
106-
"""Read input data."""
107-
bsc_files = glob.glob(f"{input_folder}/*[0-9]_att*.nc")
108-
depol_files = glob.glob(f"{input_folder}/*[0-9]_vol*.nc")
108+
def fetch_data(
109+
self, input_data: str | PathLike | Sequence[str | PathLike]
110+
) -> datetime.datetime:
111+
att_id = "*[0-9]_att*.nc"
112+
vol_id = "*[0-9]_vol*.nc"
113+
if isinstance(input_data, (str, PathLike)):
114+
bsc_files = glob.glob(f"{input_data}/{att_id}")
115+
depol_files = glob.glob(f"{input_data}/{vol_id}")
116+
else:
117+
file_list = [str(f) for f in input_data]
118+
bsc_files = [f for f in file_list if fnmatch(f, att_id)]
119+
depol_files = [f for f in file_list if fnmatch(f, vol_id)]
120+
109121
bsc_files.sort()
110122
depol_files.sort()
111123
if not bsc_files:

tests/unit/test_pollyxt.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ def test_site_meta(self, tmp_path):
9292
for key in ("latitude", "longitude", "kissa"):
9393
assert key not in nc.variables
9494

95+
def test_filepaths_instead_of_folder(self, tmp_path):
96+
temp_path = tmp_path / "filepaths.nc"
97+
file1 = f"{SCRIPT_PATH}/data/pollyxt/2021_09_17_Fri_CPV_00_00_31_att_bsc.nc"
98+
file2 = f"{SCRIPT_PATH}/data/pollyxt/2021_09_17_Fri_CPV_00_00_31_vol_depol.nc"
99+
pollyxt2nc([file1, file2], temp_path, SITE_META)
100+
with netCDF4.Dataset(temp_path) as nc:
101+
assert len(nc.variables["time"]) == 20
102+
95103

96104
def test_broken_channel():
97105
filepath = f"{SCRIPT_PATH}/data/pollyxt/broken_1064_channel"

0 commit comments

Comments
 (0)