Skip to content

Commit

Permalink
remove vrt file if the editing of metadata failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Jan 26, 2024
1 parent 5b81663 commit 55ca348
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/download_chelsa.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ download_chelsa <- function(dataset, bio_var, filename) {
time_vector = time_vector, time_bp=FALSE)
if (!edit_res){
file.remove(vrt_path)
stop("something went wrong setting up this dataset")
stop("something went wrong setting up this dataset", , "\n the dataset wil need downloading again")
}
return(TRUE)
}
Expand Down
2 changes: 1 addition & 1 deletion R/download_chelsa_trace21k.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ download_chelsa_trace21k <- function(dataset, bio_var, filename=NULL, time_bp=NU
time_vector = time_bp, time_bp=TRUE)
if (!edit_res){
file.remove(vrt_path)
stop("something went wrong setting up this dataset")
stop("something went wrong setting up this dataset", , "\n the dataset wil need downloading again")
}
return()
}
Expand Down
8 changes: 5 additions & 3 deletions R/vrt_set_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param description a string with the description of the variable in this dataset
#' @param time_vector a vector of descriptions (same length as the number of bands)
#' @param time_bp boolean defining whether time is in BP or (if FALSE) CE
#' @returns TRUE if the file was updated correctly
#' @returns TRUE if the file was updated correctly, FALSE if the update failed
#'
#' @keywords internal
## Edit the vrt metadata
Expand All @@ -18,7 +18,8 @@ vrt_set_meta <- function (vrt_path, description, time_vector, time_bp=TRUE){
# check that we don't alreayd have metadata information needed for pastclim
has_time_node <- xml2::xml_find_first(x, "./Metadata/MDI[@key = 'pastclim_time_bp']")
if (!inherits(has_time_node,"xml_missing")){
stop ("metadata for pastclim is already present")
warning ("metadata for pastclim is already present")
return(FALSE)
}
# add metadata to indicate that we have a time axis
xml2::xml_add_child(x,"Description",description,.where=0)
Expand All @@ -28,7 +29,8 @@ vrt_set_meta <- function (vrt_path, description, time_vector, time_bp=TRUE){
# add band description and times
band_nodes <- xml2::xml_find_all(x, xpath="VRTRasterBand")
if (length(band_nodes)!=length(time_vector)){
stop("the vrt has a different number of bands from the length of the time vector")
warning("the vrt has a different number of bands from the length of the time vector")
return(FALSE)
}
for (i_node in seq_len(length(band_nodes))){
# add a unique description label for this band (variable_time combination)
Expand Down

0 comments on commit 55ca348

Please sign in to comment.