e-sensing / sits

Satellite image time series in R
https://e-sensing.github.io/sitsbook/
GNU General Public License v2.0
457 stars 76 forks source link

trying to read file - file not found #1215

Open etiennelalechere opened 1 week ago

etiennelalechere commented 1 week ago

Hello & thank you for this package,

I tried different minimal tests often getting a "trying to read file: /vsicurl/https://landsateuwest..." and "file not found error".

For example: MPC_cube <- sits_cube( source = "MPC", collection = "LANDSAT-C2-L2", roi = roi, bands = c("RED", "NIR08", "CLOUD"), start_date = "1982-01-01", end_date = "2024-09-09", multicores = 16 )

Then I've got the error when trying to plot: plot(MPC_cube, red = "RED", blue = "RED", green = "NIR08", date = "1991-09-04" )

However, there is no credential for MPC so I don't understand the origin of the problem for this basic example (using sits_1.5.1).

Cheers,

Etienne

M3nin0 commented 1 week ago

Dear @etiennelalechere,

Thank you for reporting this issue.

To help us reproduce the error and investigate the possible causes, could you please share the roi you are using?

Best regards, Felipe Carlos

etiennelalechere commented 1 week ago

Thanks for the fast answer, here's the roi: lon_min lat_min lon_max lat_max 5.558055 45.845646 5.784589 46.152492

OldLipe commented 1 week ago

Hi @etiennelalechere,

After running some tests, we identified that the error occurred due to the Microsoft Planetary Computer (MPC) 's time limit, which is 45 minutes by default.

To learn more about MPC data access, please refer to: https://planetarycomputer.microsoft.com/docs/concepts/sas/#rate-limits-and-access-restrictions

Since the cube for the whole Landsat collection takes time to create, the 45-minute limit sometimes expires, preventing you from accessing the data. This causes the error you've reported.

We recommend working with a data cube with a shorter time period. For example, instead of using the entire Landsat collection, work only with the desired period (e.g., annual or biannual):

roi = list(
    lon_min = 5.558055,
    lat_min = 45.845646,
    lon_max = 5.784589,
    lat_max = 46.152492
)

MPC_cube <- sits_cube(
    source = "MPC",
    collection = "LANDSAT-C2-L2",
    roi = roi,
    bands = c("RED", "NIR08", "CLOUD"),
    start_date = "1990-01-01",
    end_date = "1991-12-31"
)

plot(
    MPC_cube,
    red = "RED", blue = "RED", green = "NIR08",
    date = "1991-09-04"
)

Thank you, Felipe Carvalho

etiennelalechere commented 1 week ago

Ok thank you, any way to overcome this time limit or to create datacubes with shorter time lenght binding them after?

gilbertocamara commented 1 week ago

Dear @etiennelalechere, I suggest you download the data one year at a time to a local directory. Then you can create a multi-year data cube using local files. See the following MWE:

# set the region of interest
roi = list(
    lon_min = 5.558055,
    lat_min = 45.845646,
    lon_max = 5.784589,
    lat_max = 46.152492
)
# create a local directory to store the files
local_dir <- <my local diretory> 
# create a list of start and end dates for all years you want
start_dates <- c("2019-01-01", "2020-01-01", "2021-01-01") 
end_dates <- c("2019-12-31", "2020-12-31", "2021-12-31") 
# build a cube for each year and save it locally
for (i in 1:length(start_dates){
     MPC_cube_year <- sits_cube(
                source = "MPC",
                collection = "LANDSAT-C2-L2",
                roi = roi,
                bands = c("RED", "NIR08", "SWIR16", "CLOUD"),
               start_date = start_dates[i],
               end_date = end_dates[i]
      )
     # copy the yearly cube to a local directory
    MPC_cube_year <- sits_cube_copy( 
              cube = MPC_cube_year,
              output_dir = local_dir,
             multicores = 4
    )
} 
# after running the loop, image files for all years will be in the same directory
# create a cube from local files
MPC_cube <- sits_cube(
                source = "MPC",
                collection = "LANDSAT-C2-L2",
                data_dir = local_dir
)
# now you should have a local data cube for all years
plot(
    MPC_cube,
    red = "SWIR16", blue = "RED", green = "NIR08",
    date = "1991-09-04"
)