From 536a8e25a8473f71955001cf80b81f4b39412c3a Mon Sep 17 00:00:00 2001 From: Lampros Mouselimis Date: Thu, 14 Dec 2023 20:35:02 +0200 Subject: [PATCH] fixed a bug in the "vsi_time_specific_orbits_wkt()" function related to #14 --- DESCRIPTION | 2 +- NEWS.md | 1 + R/mission_orbits.R | 28 +++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 13131fc..ff5524e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: IceSat2R Type: Package Title: ICESat-2 Altimeter Data using R Version: 1.0.5 -Date: 2023-12-08 +Date: 2023-12-14 Authors@R: c( person(given = "Lampros", family = "Mouselimis", email = "mouselimislampros@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "https://orcid.org/0000-0002-8024-1546")), person("OpenAltimetry.org", role = "cph")) Description: Programmatic connection to the 'OpenAltimetry API' to download and process 'ATL03' (Global Geolocated Photon Data), 'ATL06' (Land Ice Height), 'ATL07' (Sea Ice Height), 'ATL08' (Land and Vegetation Height), 'ATL10' (Sea Ice Freeboard), 'ATL12' (Ocean Surface Height) and 'ATL13' (Inland Water Surface Height) 'ICESat-2' Altimeter Data. The user has the option to download the data by selecting a bounding box from a 1- or 5-degree grid globally utilizing a shiny application. The 'ICESat-2' mission collects altimetry data of the Earth's surface. The sole instrument on 'ICESat-2' is the Advanced Topographic Laser Altimeter System (ATLAS) instrument that measures ice sheet elevation change and sea ice thickness, while also generating an estimate of global vegetation biomass. 'ICESat-2' continues the important observations of ice-sheet elevation change, sea-ice freeboard, and vegetation canopy height begun by 'ICESat' in 2003. License: GPL-3 diff --git a/NEWS.md b/NEWS.md index 2e705df..4962267 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ * I renamed the Dockerfiles and I added a separate Dockerfile for the IceSatR package because the docker image didn't work due to the similar naming of the binder image. I also added (in the Dockerfiles) the "awscli" installation which is required for the vignettes. The ".github/workflows/docker_image.yml" file was adjusted as well. * I updated the documentation to account for the migration of OpenAltimetry to EARTHDATA (https://openaltimetry.earthdatacloud.nasa.gov/) * I updated the *getTracks()* function +* I fixed a bug in the *vsi_time_specific_orbits_wkt()* function ## IceSat2R 1.0.4 diff --git a/R/mission_orbits.R b/R/mission_orbits.R index b8be354..469a63a 100644 --- a/R/mission_orbits.R +++ b/R/mission_orbits.R @@ -1404,13 +1404,31 @@ vsi_time_specific_orbits_wkt = function(date_from, if (length(idx_relev) > 0) { - if (length(idx_relev) == 1) { - dat_all = dat_all[[idx_relev]] - } else { - dat_all = dat_all[idx_relev] # the sublists 'dat_all' can return POINT, LINESTRING (cast all to POINT) - dat_all = data.table::rbindlist(dat_all) + dat_all = dat_all[idx_relev] + + # I expect each sublist to be of type "sfc_POINT" and normally observations which are not (and can be for instance "sfc_LINESTRING") won't have a description column either. Therefore use the next line for removal + descr_not_idx = which(as.vector(unlist(lapply(dat_all, function(x) { + colnams = colnames(x) + if ('description' %in% colnams) { + verify_descr = (is.na(x$description) | x$description == "") + } + else if ('Description' %in% colnams) { + verify_descr = (is.na(x$Description) | x$Description == "") # In Macintosh (osx) the "description" column appears with an upper case "D" as "Description", see the following issue: https://github.com/mlampros/IceSat2R/issues/9#issuecomment-1152020607 + } + else { + stop("The 'D(d)escription' column must exist in every sublist!", call. = F) + } + verify_descr + })))) + + LEN_exc = length(descr_not_idx) + if (LEN_exc > 0) { + if (verbose) message(glue::glue("{LEN_exc} output sublist did not have a valid 'description' and will be removed!")) + dat_all = dat_all[-descr_not_idx] } + dat_all = data.table::rbindlist(dat_all) + if (nrow(dat_all) > 0) { dat_all }