-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvobs2sql.R
executable file
·96 lines (75 loc) · 2.91 KB
/
vobs2sql.R
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
93
94
95
96
#!/usr/bin/env Rscript
#================================================#
# READ VOBS DATA AND CONVERT TO SQLITE FORMAT
#================================================#
#================================================#
# PACKAGES
#================================================#
suppressPackageStartupMessages({
library(harp)
library(argparse)
library(here)
library(yaml)
})
#================================================#
# READ COMMAND LINE ARGUMENTS
#================================================#
if (!interactive()) {
parser <- argparse::ArgumentParser()
parser$add_argument("-start_date",
type = "character",
default = "None",
help = "First date to process [default %(default)s]",
metavar = "String")
parser$add_argument("-end_date",
type = "character",
default = "None",
help = "Last date to process [default %(default)s]",
metavar = "String")
parser$add_argument("-config_file",
type = "character",
default = "None",
help = "Config file to use [default %(default)s]",
metavar = "String")
args <- parser$parse_args()
start_date <- args$start_date
end_date <- args$end_date
config_file <- args$config_file
} else {
start_date <- "2025010100"
end_date <- "2025010123"
config_file <- "config_files/config_det_example.yml"
}
# Check if required arguments are missing
if (any(c(start_date,end_date,config_file) == "None")) {
stop("You need to provide start_date, end_date, and a config file")
}
# Check if config_file exists
if (!file.exists(here::here(config_file))) {
stop("Cannot find config file",here::here(config_file))
}
#================================================#
# READ OPTIONS FROM THE CONFIG FILE
#================================================#
CONFIG <- yaml::yaml.load_file(here::here(config_file))
vobs_path <- check_config_input(CONFIG,"pre","vobs_path")
obs_path <- check_config_input(CONFIG,"verif","obs_path")
by_val <- check_config_input(CONFIG,"pre","vobs_by")
#================================================#
# OPTION CHECKS
#================================================#
check_dirs_exist(c(vobs_path,obs_path))
if (!(by_val %in% paste0(seq(0,200),"h"))) {
cat("vobs_by =",by_val,"is not valid - use e.g. 1h\n")
stop("Aborting")
}
#================================================#
# VOBS CONVERT
#================================================#
cat("Collecting vobs data from",start_date,"to",end_date,"\n")
obs_data <- harpIO::read_obs(
dttm = harpCore::seq_dttm(start_date,end_date,by = by_val),
file_path = vobs_path,
output_format_opts = harpIO::obstable_opts(path = obs_path)
)
cat("Finished vobs conversion\n")