bevingtona / planetR

(early development) R tools to search, activate and download satellite imagery from the Planet API.
Apache License 2.0
45 stars 14 forks source link

planet_search() error #12

Closed monsoonforest closed 2 years ago

monsoonforest commented 2 years ago

I'm trying to search for images within my bounding box and even after trying several combinations of dates I receive the same error after running response <- planet_search(bbox, date_end, date_start, cloud_lim, item_name) Error in permissions[, 1] : subscript out of bounds Above my item_name = "PSScene" after the recent changes in Planet's item assets and merging of the SuperDove datasets. Not sure what the error is referring to within the planet_search() variables. Upon trying the example in the README i still receive the same error.

agronomofiorentini commented 2 years ago

I have got the same issue by running the README example.

While by defining a small area i have got the follow error output

[1] "Found 17 suitable PSScene4Band analytic_sr images" [1] "Day of year: 1-31" [1] "Year: 2022-2022" [1] "Save the Order ID: " [1] "You can restart the download with planet_order_download(order_id, order_name)" Error in while (get_content$state != "success") { : argument is of length zero

bevingtona commented 2 years ago

@monsoonforest I am able to reproduce this error with the 8 band super dove imagery. I get the following error:

request <- httr::POST(url, body = order_json, httr::content_type_json(),username = api_key)

Response [https://@api.planet.com/compute/ops/orders/v2]
  Date: 2022-02-10 00:39
  Status: 400
  Content-Type: application/json
  Size: 227 B
{"field":{"Products":[{"message":"Bad bundle type: 'basic_analytic_8b'"},{"message":"Bad bundle type: 'basic_analytic_8b'"}

It seems that the bundle type is not correct, however the search function returns a list of images for the same bundle type... so I am confused. Search works for 8 band imagery, but not the download function... I was able to download the imagery from the website, which means this should work..

@agronomofiorentini I am not able to reproduce your error. The PSScene4Band images download just fine. Can you post your AOI and the search parameters that you used?

agronomofiorentini commented 2 years ago

Dear @bevingtona, i will report here the parameters of my query.

for my AOI

class : Extent xmin : 13.3699 xmax : 13.4514 ymin : 43.55308 ymax : 43.60005

While the others parameters are:

  1. date start 2022-01-02
  2. date end 2022-01-06
  3. start_doy 1
  4. end_doy 5
  5. cloud_lim 0.5
  6. item_name PSScene4Band
  7. product analytic_sr

The aim of the download is to monitor a grain field.

bevingtona commented 2 years ago

@agronomofiorentini can you update the package and see if it works? I am able to download these images. See below:

# install.packages("remotes")
# remotes::install_github("bevingtona/planetR")
library(planetR)
library(httr)
library(jsonlite)
library(raster)
library(stringr)

site = "Field"
api_key = "" 
start_year = 2022
end_year   = 2022
start_doy  = 1
end_doy    = 5
date_start = as.Date(paste0(start_year,"-01-01"))+start_doy
date_end   = as.Date(paste0(end_year,"-01-01"))+end_doy
bbox         = extent(13.3699,13.4514,43.55308,43.60005)
cloud_lim    = 0.5 
item_name    = "PSScene4Band"
product      = "analytic_sr" 
exportfolder = paste(site, item_name, product, start_year, end_year, start_doy, end_doy, sep = "_")
dir.create(exportfolder, showWarnings = F)

planet_order(api_key = api_key, 
             bbox = bbox, 
             date_start = date_start, 
             date_end = date_end, 
             start_doy = start_doy, 
             end_doy = end_doy, 
             cloud_lim = cloud_lim, 
             item_name = item_name, 
             product = product,
             order_name = exportfolder)
#> [1] "Search from yday and year ranges"
#> [1] "Found 4 suitable PSScene4Band analytic_sr images that you have permission to download."
#> [1] "Between yday: 1 to 5"
#> [1] "Save the Order ID: 92789f8b-380c-4b27-a18e-cab212d35d3c"
#> [1] "You can restart the download with `planet_order_download(order_id, order_name)`"
#> [1] "Order still being proccessed, trying again in 60 seconds..."
#> [1] "queued"
#> [1] "Order still being proccessed, trying again in 60 seconds..."
#> [1] "running"
#> [1] "Order still being proccessed, trying again in 60 seconds..."
#> [1] "running"
#> [1] "Starting download"
#> [1] "Download: 6%"
#> [1] "Download: 10%"
#> [1] "Download: 20%"
#> [1] "Download: 20%"
#> [1] "Download: 30%"
#> [1] "Download: 40%"
#> [1] "Download: 40%"
#> [1] "Download: 50%"
#> [1] "Download: 50%"
#> [1] "Download: 60%"
#> [1] "Download: 60%"
#> [1] "Download: 70%"
#> [1] "Download: 80%"
#> [1] "Download: 80%"
#> [1] "Download: 90%"
#> [1] "Download: 90%"
#> [1] "Download: 100%"
#> [1] "Download complete"
#> [1] "Items located in Temp/RtmpeGikhI/reprex-78c47b6914b1-sly-agama/Field_PSScene4Band_analytic_sr_2022_2022_1_5"
agronomofiorentini commented 2 years ago

I have update the package as you suggested but now i have got a different error output

[1] "Search from yday and year ranges" [1] "Found 0 suitable PSScene4Band analytic_sr images that you have permission to download." [1] "Between yday: 1 to 2" [1] "Save the Order ID: " [1] "You can restart the download with planet_order_download(order_id, order_name)" Error in while (get_content$state != "success") { : argument is of length zero

I think i don't have the permission to download the images. I think it is related to the api key.

agronomofiorentini commented 2 years ago

I checked if the api key is correct via https://account.planet.com/.

The api key reported in the script it is correct. I don't know how to fix it.

Do you have any idea?

bevingtona commented 2 years ago

The only thing I can think of is that your account does not have download permissions for these images. Are you sure your API gives you access to these images?

I just pushed a change so that now it prints the type of permissions you have and if you do not have download permissions, then the script stops.

Can you try again (update the package and re-run)?

It should say that you do or do not have download permissions:

[1] "Search from yday and year ranges"
[1] "You have DOWNLOAD permissions for these images."
[1] "Found 4 suitable PSScene4Band analytic_sr images that you have permission to download."
[1] "Between yday: 1 to 5"
[1] "Save the Order ID: 23f2e8f5-6329-4eb5-a014-f1f05b29afd9"
[1] "You can restart the download with `planet_order_download(order_id, order_name)`"
[1] "Order still being proccessed, trying again in 60 seconds..."
[1] "queued"
[1] "Order still being proccessed, trying again in 60 seconds..."
[1] "running"
monsoonforest commented 2 years ago

@bevingtona after I updated the package i made these changes item_name = "PSScene4Band and product = analytic_sr but upon running the planet_search function I receive the error Error in permissions[, 1] : subscript out of bounds. Do you suspect I have an API permission issue? I can't access 8 band as yet on planet explorer. thanks for helping :)

agronomofiorentini commented 2 years ago

Dear @bevingtona, i have update the package and i have tried to download the image by using the same query reported before and now i have got a new error output

[1] "Search from yday and year ranges" Error in if (unique(permissions$permission) == "download") { : argument is of length zero

with regard to the api key, I went to the planet site and i search the image with the same parameters, and it tells me that I should buy the PSScene4Band data even though I have the 90-day trial.

Now I should find out if during the 90-day trial period I can actually download the PSScene4Band or not, but this information is hard to find on the planet website.

bevingtona commented 2 years ago

@agronomofiorentini I think the 90d trial is only for California.. not sure. If you cannot download from Planet Explorer then the API will not work either. I need to make a better error message for this.

@monsoonforest hmm not sure what this error is.. can you post the search parameters and bbox?

monsoonforest commented 2 years ago
library(planetR)
library(httr)
library(jsonlite)
library(raster)
library(stringr)
library(sf)
library(mapedit)
api_key = "" 
start_year = 2021
end_year   = 2021
start_doy  = 330 # OR FROM DATE as.numeric(format(as.Date('2000-07-15'),"%j"))
end_doy    = 365 # OR FROM DATE as.numeric(format(as.Date('2000-08-15'),"%j"))
date_start = as.Date(paste0(start_year,"-01-01"))+start_doy
date_end   = as.Date(paste0(end_year,"-01-01"))+end_doy
cloud_lim    = 0.02 # percent from 0-1
item_name    = "PSScene4Band" 
product      = "analytic_sr" 
bbox         = extent(74, 75, 23, 24)
response <- planet_search(bbox, date_end, date_start, cloud_lim, item_name)
bevingtona commented 2 years ago

@monsoonforest you'll need to specify the start and end doy in the search function. They default to NULL if not specified.

library(planetR)
library(httr)
library(jsonlite)
library(raster)
library(stringr)
library(sf)
library(mapedit)
# api_key = "" 
start_year = 2021
end_year   = 2021
start_doy  = 330 # OR FROM DATE as.numeric(format(as.Date('2000-07-15'),"%j"))
end_doy    = 365 # OR FROM DATE as.numeric(format(as.Date('2000-08-15'),"%j"))
date_start = as.Date(paste0(start_year,"-01-01"))+start_doy
date_end   = as.Date(paste0(end_year,"-01-01"))+end_doy
cloud_lim    = 0.02 # percent from 0-1
item_name    = "PSScene4Band" 
product      = "analytic_sr" 
bbox         = extent(74, 75, 23, 24)

response <- planet_search(bbox = bbox,
                          start_doy = start_doy, 
                          end_doy = end_doy, 
                          api_key = api_key, 
                          date_end = date_end, 
                          date_start = date_start, 
                          cloud_lim = cloud_lim, 
                          item_name = item_name)
monsoonforest commented 2 years ago

I'm not sure if agronomofiorentini issue is resolved. But specifying doy in the function worked for me. thank you @bevingtona

agronomofiorentini commented 2 years ago

Dear @bevingtona, I have tried to make two query:

  1. California
  2. My AOI

The first one

class : Extent xmin : -120.8426 xmax : -120.8188 ymin : 37.68396 ymax : 37.69657

The date_start is 2022-01-02 The date_end is 2022-01-03 the start_doy is 1 the end_doy is 2 the cloud_lim is 0.5 the item_name is PSScene4Band the product name is analytic_sr

and the results by using the planet_order funciton is the follow one

[1] "Search from yday and year ranges" [1] "You have DOWNLOAD permissions for these images." [1] "Found 3 suitable PSScene4Band analytic_sr images that you have permission to download." [1] "Between yday: 1 to 2" [1] "Save the Order ID: " [1] "You can restart the download with planet_order_download(order_id, order_name)" Error in while (get_content$state != "success") { : argument is of length zero

While by using the planet_search function with the same parameters i have got the follow output

[1] "You have DOWNLOAD permissions for these images." [1] "Found 3 suitable PSScene4Band analytic_sr images that you have permission to download." [1] "Between yday: 1 to 2"

While for my AOI, i have made the request with same parameters excpet for the extent

class : Extent xmin : 13.3814 xmax : 13.40294 ymin : 43.60869 ymax : 43.61789

The planet_order function give me the follow error

[1] "Search from yday and year ranges" Error in if (unique(permissions$permission) == "download") { : argument is of length zero

while the planet_search function give me the follow error

Error in if (unique(permissions$permission) == "download") { : argument is of length zero