carlos-alberto-silva / rGEDI

rGEDI: An R Package for NASA's Global Ecosystem Dynamics Investigation (GEDI) Data Visualization and Processing.
157 stars 67 forks source link

Error in readLines(response) : HTTP error 400. #35

Closed swinersha closed 2 years ago

swinersha commented 2 years ago

When I try to run the code in the example on the readme page:

gLevel1B<-gedifinder(product="GEDI01_B",ul_lat, ul_lon, lr_lat, lr_lon,version="002",daterange=daterange)

I get the error: Error in readLines(response) : HTTP error 400. I'm guessing their is a bad URL somewhere. If you could take a look that would be much appreciated.

My system specs are: R version 4.1.0 (2021-05-18) -- "Camp Pontanezen" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit)

caiohamamura commented 2 years ago

Which version of rGEDI are you using? From CRAN or from github? CRAN version is old and still don't support version="002".

Lily-LLJ commented 2 years ago

How to install rGEDI from github? When I try to run the code in the example on the readme page:

library(devtools) devtools::install_git("https://github.com/carlos-alberto-silva/rGEDI", dependencies = TRUE)

I get the error:Failed to install 'unknown package' from Git. What should i do?If you could take a look that would be much appreciated.

wiesehahn commented 2 years ago

Similar problem here. devtools::install_git("https://github.com/carlos-alberto-silva/rGEDI", dependencies = TRUE) starts running but exits with ERROR: package installation failed Not sure if its a local problem though.

shrestha2019 commented 2 years ago

I got similar issue while installing rGEDI. Anyone able to solve it?

Edgarypz commented 2 years ago

I have the same problem to installing rGEDI.

remotes::install_github('carlos-alberto-silva/rGEDI') Downloading GitHub repo carlos-alberto-silva/rGEDI@HEAD Error: Failed to install 'rGEDI' from GitHub: Git does not seem to be installed on your system.

ShingObt commented 2 years ago

I got similar issue while installing rGEDI. I ran

devtools::install_git("https://github.com/carlos-alberto-silva/rGEDI", dependencies = TRUE)

but I got error message,

error:Failed to install 'unknown package' from Git.

Though it is naive and patchy method, directly copying the latest gedifinder function worked for me and I could download the HDF files of my interest.

gedifinder <- function(product,
                       ul_lat,
                       ul_lon,
                       lr_lat,
                       lr_lon,
                       version = "002",
                       daterange = NULL) {
  concept_ids <- list(
    GEDI01_B.001 = "C1656765475-LPDAAC_ECS",
    GEDI02_A.001 = "C1656766463-LPDAAC_ECS",
    GEDI02_B.001 = "C1656767133-LPDAAC_ECS",
    GEDI01_B.002 = "C1908344278-LPDAAC_ECS",
    GEDI02_A.002 = "C1908348134-LPDAAC_ECS",
    GEDI02_B.002 = "C1908350066-LPDAAC_ECS"
  )

  page <- 1
  bbox <- paste(ul_lon, lr_lat, lr_lon, ul_lat, sep = ",")

  # Granules search url pattern
  url_format <- paste0(
    "https://cmr.earthdata.nasa.gov/search/granules.json?",
    "pretty=true&provider=LPDAAC_ECS&page_size=2000&concept_id=%s",
    "&bounding_box=%s"
  )
  request_url <- sprintf(
    url_format,
    concept_ids[paste0(product, ".", version)],
    bbox
  )

  # Add temporal search if not null
  if (!is.null(daterange)) {
    url_format <- paste0(request_url, "&temporal=%s,%s")
    request_url <- sprintf(url_format, daterange[1], daterange[2])
  }

  granules_href <- c()
  # Append fetched granules to granules_href
  # recursively, for each page (max 2000 per page)
  repeat {
    response <- curl::curl_fetch_memory(paste0(
      request_url,
      "&pageNum=",
      page
    ))
    content <- rawToChar(response$content)
    result <- jsonlite::parse_json(content)
    if (response$status_code != 200) {
      stop(paste("\n", result$errors, collapse = "\n"))
    }
    granules <- result$feed$entry

    if (length(granules) == 0) break

    granules_href <- c(
      granules_href,
      sapply(granules, function(x) x$links[[1]]$href)
    )
    page <- page + 1
  }

  return(granules_href)
}

I am not sure if using the old version results in other issues but so far so good for my project.

Rapsodia86 commented 2 years ago

For those with "error: Failed to install 'unknown package' from Git." It says: "Git does not seem to be installed on your system.", so you need to download and install Git from https://git-scm.com/

caiohamamura commented 2 years ago

Thanks @Rapsodia86