Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cryptic error in lsSearch #13

Open
bholtdwyer opened this issue Oct 22, 2022 · 0 comments
Open

Cryptic error in lsSearch #13

bholtdwyer opened this issue Oct 22, 2022 · 0 comments

Comments

@bholtdwyer
Copy link

bholtdwyer commented Oct 22, 2022

I'm trying to download Landsat bands for Indonesia, but I keep getting an obscure (not helpful) error message. An example below. Note that in the real example I'm of course using my own EarthExplorer/USGS username and password, as character strings. I'm currently logged into EarthExplorer with those credentials.

#Import a basic map of the world to try to pull down data associated with Indonesia.
require(maptools)
require(sf)
#Pull in a shapefile of simplified country outlines
data(wrld_simpl)
class(wrld_simpl)

#Make this a "sf" class object
wrld_simpl=st_as_sf(wrld_simpl)
class(wrld_simpl)

#Shapefile of just Indonesia.
require(dplyr)
indonesia = wrld_simpl %>% filter(NAME=="Indonesia")

#Plot the shapefile. It's a real place.
require(ggplot)
ggplot(indonesia) + geom_sf()

#############################
#Attempt to search for Landsat 8 data over Indonesia, specifying the area of interest 2 different ways:

#From the documentation of "lsSearch"
# region: a ‘Spatial*’, projected ‘raster*’, o r ‘sf’ class object
#       defining the area of interest. This argument is mandatory if
#       ‘pathrow’, ‘extent’, or ‘lonlat’ are not defined.
class(indonesia)

#Literally the example given in the help file, just using my username and password and the Indonesia shapefile.
sres <- lsSearch(product = "LANDSAT_8_C1",
                      startDate = as.Date("01-01-2011", "%d-%m-%Y"),
                      endDate = as.Date("31-12-2013", "%d-%m-%Y"),
                      username = earthexplorer_username,
                      password = earthexplorer_password,
                      region = indonesia)
#Returns a cryptic error:
#Error in if (res$error != "") { : argument is of length zero

#From the documentation of "lsSearch"
# extent: an ‘extent’, ‘Raster*’, or ‘Spatial*’ object
#               representing the region of interest with
#               longitude/latitude (EPSG:4326) coordinates. This argument
#               is mandatory if ‘region’, ‘pathrow’ or ‘lonlat’ are not
#               defined.
require(raster)
class(extent(wrld_simpl))

#Literally the example given in the help file, just using my username and password and the Indonesia shapefile.
sres <- lsSearch(product = "LANDSAT_8_C1",
                      startDate = as.Date("01-01-2011", "%d-%m-%Y"),
                      endDate = as.Date("31-12-2013", "%d-%m-%Y"),
                      username = earthexplorer_username,
                      password = earthexplorer_password,
                      extent = extent(wrld_simpl))
#Exact same cryptic error.

I'm not sure what the problem is, but whatever it is, returning an error that tells me something other than res$error != "" would be really helpful. Given the naming, I suspect there was an error downloading the files? If so, returning an error message like "Unable to download files, please check credentials" or "EarthData server not responding" would be really helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant