-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_xband_lidar_time_differences.py
92 lines (80 loc) · 2.64 KB
/
get_xband_lidar_time_differences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Get time differences between lidar and xband files.
Author: Jenna Ritvanen <[email protected]>
"""
import argparse
from datetime import datetime
import logging
import pandas as pd
import file_utils
if __name__ == "__main__":
argparser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
argparser.add_argument("xband_path", type=str, help="Path to xband directory")
argparser.add_argument("lidar_path", type=str, help="Path to lidar directory")
argparser.add_argument("outfile", type=str, help="Output csv file")
argparser.add_argument(
"--tasks",
nargs="+",
default=["WND-02", "WND-03", "MWS-PPI1_G"],
help="X-band tasks that are processed",
)
argparser.add_argument(
"--scan_type",
type=str,
default="ppi",
help="Lidar scan type that is matched to",
)
argparser.add_argument(
"--scan_angle",
type=float,
default=2.0,
help="Lidar scan fixed angle that is matched to",
)
args = argparser.parse_args()
logging.basicConfig(level=logging.INFO)
xband_files = file_utils.get_sigmet_file_list_by_task(args.xband_path)
lidar_files = file_utils.get_lidar_file_list_by_type(args.lidar_path)
lidar_dict = {}
for fn in lidar_files[(args.scan_type, args.scan_angle)]:
tt = file_utils.parse_time_from_filename(
fn,
r"WLS400s-113_([0-9_-]{19})_([\w]+)_([\d]+)_([\d]+)m.nc",
"%Y-%m-%d_%H-%M-%S",
0,
)
lidar_dict[tt] = fn
data = []
# Get closest lidar file for each xband file
for task in args.tasks:
if task not in xband_files.keys():
logging.info(f"No files for task {task}, skipping!")
continue
logging.info(f"Processing task {task} with {len(xband_files[task])} files")
for xband_fn in xband_files[task]:
xband_time = datetime.strptime(xband_fn.split(".")[0], "WRS%y%m%d%H%M%S")
lidar_time, lidar_fn, timediff = file_utils.find_closest_file(
xband_time, lidar_dict
)
data.append(
[
task,
xband_fn,
xband_time,
lidar_fn,
lidar_time,
timediff,
]
)
df = pd.DataFrame(
data,
columns=[
"task",
"xband_file",
"xband_time",
"lidar_file",
"lidar_time",
"time_difference_sec",
],
)
df.to_csv(args.outfile, index=False)