e-sensing / sits

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

angles for Sentinel-2 #1153

Closed safalabolo closed 2 weeks ago

safalabolo commented 4 weeks ago

Hi, Is it possible to download not only the bands but also the following angles for Sentinel-2?

view_zenith_mean view_azimuth_mean sun_zenith sun_azimuth

Thank you.

rolfsimoes commented 2 weeks ago

Hi @safalabolo,

The sits package is specifically designed to work with band layers from satellite imagery. Unfortunately, it does not support downloading additional layers such as view_zenith_mean, view_azimuth_mean, sun_zenith, and sun_azimuth.

However, you can use the rstac package to achieve this. The rstac package is capable of accessing a broader range of metadata and properties from STAC (SpatioTemporal Asset Catalog) APIs, including other documents besides images (e.g. XML, ZIP).

Here’s an example of how you can use the rstac package to download an asset from Sentinel-2 AWS (https://earth-search.aws.element84.com/v1):

library("rstac")

# STAC endpoint
stac_endpoint <- stac("https://earth-search.aws.element84.com/v1")

# Do a search query
items <- stac_endpoint |>
    stac_search(
        collections = "sentinel-2-l2a",
        bbox = c(22, 51, 23, 52),
        datetime = "2023-01-01T00:00:00Z/2023-01-02T00:00:00Z"
    ) |>
    post_request()

# Show all available assets
items_assets(items)
#>  [1] "aot"               "aot-jp2"           "blue"             
#>  [4] "blue-jp2"          "coastal"           "coastal-jp2"      
#>  [7] "granule_metadata"  "green"             "green-jp2"        
#> [10] "nir"               "nir-jp2"           "nir08"            
#> [13] "nir08-jp2"         "nir09"             "nir09-jp2"        
#> [16] "red"               "red-jp2"           "rededge1"         
#> [19] "rededge1-jp2"      "rededge2"          "rededge2-jp2"     
#> [22] "rededge3"          "rededge3-jp2"      "scl"              
#> [25] "scl-jp2"           "swir16"            "swir16-jp2"       
#> [28] "swir22"            "swir22-jp2"        "thumbnail"        
#> [31] "tileinfo_metadata" "visual"            "visual-jp2"       
#> [34] "wvp"               "wvp-jp2"

# Example: select and download an XML asset
assets_select(items, asset_names = c("granule_metadata")) |> 
    assets_download(output_dir = tempdir()) -> local_items
#>   |======================================================================| 100%

local_items |> 
    assets_url()
#> [1] "/tmp/Rtmp6bXitf/sentinel-s2-l2a-cogs/34/U/EB/2023/1/S2A_34UEB_20230101_0_L2A/granule_metadata.xml"
#> [2] "/tmp/Rtmp6bXitf/sentinel-s2-l2a-cogs/34/U/FB/2023/1/S2A_34UFB_20230101_0_L2A/granule_metadata.xml"
#> [3] "/tmp/Rtmp6bXitf/sentinel-s2-l2a-cogs/34/U/EC/2023/1/S2A_34UEC_20230101_0_L2A/granule_metadata.xml"
#> [4] "/tmp/Rtmp6bXitf/sentinel-s2-l2a-cogs/34/U/FC/2023/1/S2A_34UFC_20230101_0_L2A/granule_metadata.xml"

This example demonstrates how to use rstac to download any available asset from a collection. If the collection you have access provide angles assets you can just replace the name of those assets in assets_select() function.

safalabolo commented 2 weeks ago

@rolfsimoes Thank you! Very useful!