The function safe_getMetadata()
scans a Sentinel2 product
(main path or granule xml file) to retrieve information about the product.
The accessory function rm_invalid_safe()
remove a SAFE archive in the case
it is not recognised by safe_getMetadata()
.
The accessory function safe_isvalid()
scan the SAFE name to understand
if it is a valid SAFE.
safe_getMetadata( s2, info = "all", format = "default", simplify = TRUE, abort = TRUE, allow_oldnames = FALSE ) rm_invalid_safe(s2, req_res = c("10m", "20m", "60m"), allow_oldnames = FALSE) safe_isvalid( s2, allow_oldnames = FALSE, check_file = TRUE, req_res = c("10m", "20m", "60m") )
s2 | Sentinel-2 products, which can be:
|
---|---|
info | (optional) A character vector with the list of the metadata which should be provided. Accepted values are:
|
format | Output format, being one of the followings:
|
simplify | Logical parameter, which applies in case |
abort | Logical parameter: if TRUE (default), the function aborts
in case some inputs are not recognised, or if some files do not exists
(in case some |
allow_oldnames | Logical parameter: if TRUE, old (long) name products are managed (metadata are returned, and they are considered valid; if FALSE (default), they are considered as non-supported files. Note that, from sen2r version 1.1.0, oldname products are no more supported within processing chains, so this function is deprecated and no more supported; moreover, it will be removed in next releases. |
req_res | Character: vector of variable length (0 to 3)
containing the names of the spatial resolution to be checked
(one or more among |
check_file | Logical: if TRUE (default), the content of the provided paths is checked; if FALSE, only the validity of SAFE names is tested. |
safe_getMetadata()
returns a data.table, a data.frame or a list
(depending on argument format
) with the output metadata;
rm_invalid_safe()
returns a named vector (with the length of s2
) with
TRUE if the s2
product was removed, FALSE elsewhere.
safe_isvalid()
returns a named vector (with the length of s2
) with
TRUE if the product is a valid SAFE, FALSE if not.
License: GPL 3.0
L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020). "sen2r": An R toolbox for automatically downloading and preprocessing Sentinel-2 satellite data. Computers & Geosciences, 139, 104473. doi: 10.1016/j.cageo.2020.104473 , URL: http://sen2r.ranghetti.info/.
Luigi Ranghetti, phD (2019) luigi@ranghetti.info
# Define product name s2_examplenames <- c( "S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE", "S2A_MSIL1C_20190723T101031_N0208_R022_T32TNR_20190723T121220.SAFE" ) # Return the information retrievable from the file names (files are not scanned) safe_getMetadata(s2_examplenames, info="nameinfo")#> name validname #> 1: S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE TRUE #> 2: S2A_MSIL1C_20190723T101031_N0208_R022_T32TNR_20190723T121220.SAFE TRUE #> prod_type version mission level sensing_datetime id_baseline id_orbit #> 1: product compact 2A 1C 2019-07-23 10:10:31 UTC 0208 022 #> 2: product compact 2A 1C 2019-07-23 10:10:31 UTC 0208 022 #> id_tile creation_datetime #> 1: 32TNS 2019-07-23 12:12:20 UTC #> 2: 32TNR 2019-07-23 12:12:20 UTC# Return some specific information without scanning files safe_getMetadata(s2_examplenames, info=c("level", "id_tile"))#> name level #> 1: S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE 1C #> 2: S2A_MSIL1C_20190723T101031_N0208_R022_T32TNR_20190723T121220.SAFE 1C #> id_tile #> 1: 32TNS #> 2: 32TNR# Return a single information without scanning files # (in this case, the default output is a vector instead than a data.table) safe_getMetadata(s2_examplenames, info="level")#> S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE #> "1C" #> S2A_MSIL1C_20190723T101031_N0208_R022_T32TNR_20190723T121220.SAFE #> "1C"# Check if the products are valid existing SAFE archives safe_isvalid(s2_examplenames)#> S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE #> FALSE #> S2A_MSIL1C_20190723T101031_N0208_R022_T32TNR_20190723T121220.SAFE #> FALSE# Check if the product names are valid SAFE names safe_isvalid(s2_examplenames, check_file = FALSE)#> S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE #> TRUE #> S2A_MSIL1C_20190723T101031_N0208_R022_T32TNR_20190723T121220.SAFE #> TRUEsafe_isvalid("invalid_safe_name.SAFE", check_file = FALSE)#> invalid_safe_name.SAFE #> FALSEif (FALSE) { # Download a sample SAFE archive (this can take a while) s2_exampleurl <- c( "S2A_MSIL1C_20190723T101031_N0208_R022_T32TNS_20190723T121220.SAFE" = paste0("https://scihub.copernicus.eu/apihub/odata/v1/", "Products('19bbde60-992b-423d-8dea-a5e0ac7715fc')/$value") ) s2_download(s2_exampleurl, outdir=tempdir()) s2_examplepath <- file.path(tempdir(), names(s2_exampleurl)) # Return all the available information safe_getMetadata(s2_examplepath) # Return some specific information safe_getMetadata(s2_examplepath, info=c("clouds", "direction")) # Return a single information safe_getMetadata(s2_examplepath, info="nodata_value") # Check if the downloaded SAFE is valid safe_isvalid(s2_examplepath) # Delete it if it is not recognised rm_invalid_safe(s2_examplepath) }