Skip to content

Commit

Permalink
Use as_apsim_met() to import SILO data and add comments back
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks committed May 15, 2024
1 parent 191fdea commit 7e7d5a5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions R/get_data_drill_apsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#'
#' @section Saving objects:
#' To save \dQuote{met} objects, please use [apsimx::write_apsim_met()].
#' Note that when saving, comments from SILO will be included, but these will
#' not be printed as a part of the resulting `met` object in your \R session.
#'
#' @return An \CRANpkg{apsimx} object of class \sQuote{met} with attributes.
#'
Expand Down
2 changes: 2 additions & 0 deletions R/get_patched_point_apsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
#'
#' @section Saving objects:
#' To save \dQuote{met} objects, please use [apsimx::write_apsim_met()].
#' Note that when saving, comments from SILO will be included, but these will
#' not be printed as a part of the resulting `met` object in your \R session.
#'
#' @return An \CRANpkg{apsimx} object of class \sQuote{met} with attributes.
#'
Expand Down
30 changes: 29 additions & 1 deletion R/query_silo_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,35 @@
met_file_path <- file.path(tempdir(), "apsim.met")
on.exit(unlink(met_file_path))
writeLines(text = response$parse("UTF8"), con = met_file_path)
return(apsimx::read_apsim_met(file = "apsim.met", src.dir = tempdir()))
apsim <- readLines(met_file_path)
data <- data.table::fread(file = met_file_path,
skip = grep(pattern = "^year",
x = apsim) + 2)
apsim_met <- apsimx::as_apsim_met(
x = data,
filename = sprintf("station.%s.met",
trimws(sub("^.*=", "",
apsim[grep(pattern = "^!station number =",
x = apsim)]))),
site = trimws(sub("^.*=", "",
apsim[grep(pattern = "^!station name =", x = apsim)])),
latitude = trimws(sub("^.*=", "",
apsim[grep(pattern = "^latitude =", x = apsim)])),
longitude = trimws(sub("^.*=", "",
apsim[grep(pattern = "^longitude =", x = apsim)])),
colnames = scan(
text = apsim[grep(pattern = "year", x = apsim)],
what = '',
quiet = TRUE
),
units = scan(
text = apsim[grep(pattern = "\\(\\)", x = apsim)],
what = '',
quiet = TRUE
),
comments = apsim[grep(pattern = "^!", x = apsim)]
)
return(apsim_met)
}

response_data <- data.table::fread(response$parse("UTF8"))
Expand Down
2 changes: 2 additions & 0 deletions man/get_data_drill_apsim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/get_patched_point_apsim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e7d5a5

Please sign in to comment.