Error arises from simple query from sen2r R package

93 views Asked by At

I am trying to load some Sentinel satellite imagery using the sen2r R package and am having trouble. In short, even the simplest example from the documentation does not work. This example goes as follows:

json_path <- build_example_param_file()

if (is_gcloud_configured()) {
  out_paths_2 <- sen2r(json_path)
} else {
  out_paths_2 <- character(0)
}

This is the output I receive; some of it is messaging that appears to be nonimpactful to the outcome, and the error is a bit vague and seems to arise from a little big within some function the package is using.

[2023-12-04 17:59:26] #### Starting sen2r execution. ####
Spherical geometry (s2) switched off
[2023-12-04 17:59:27] Searching for available SAFE products...
old-style crs object detected; please recreate object with a recent sf::st_crs()
old-style crs object detected; please recreate object with a recent sf::st_crs()
[2023-12-04 17:59:28] Querying Google Cloud (this can take a very long time)...
  |==========================================================================================| 100%Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘saveXML’ for signature ‘"NULL"’
Spherical geometry (s2) switched on

The example code makes up a default .json file with arguments for the function. The contents of this file are as follows:

{
  "preprocess": [true],
  "s2_levels": ["l1c", "l2a"],
  "sel_sensor": ["s2a", "s2b"],
  "online": [true],
  "server": ["gcloud"],
  "order_lta": [true],
  "downloader": ["builtin"],
  "overwrite_safe": [false],
  "rm_safe": ["no"],
  "max_cloud_safe": [100],
  "step_atmcorr": ["l2a"],
  "sen2cor_use_dem": [null],
  "sen2cor_gipp": [null],
  "timewindow": ["2020-08-01", "2020-08-01"],
  "timeperiod": ["full"],
  "extent": ["C:/Users/pthom/AppData/Local/R/win-library/4.3/sen2r/extdata/vector/barbellino.geojson"],
  "s2tiles_selected": [null],
  "s2orbits_selected": [null],
  "list_prods": ["BOA", "SCL"],
  "list_indices": ["MSAVI2", "NDVI"],
  "list_rgb": ["RGB432B", "RGB843B"],
  "rgb_ranges": [
    [0, 2500],
    [
      [0, 7500],
      [0, 2500],
      [0, 2500]
    ]
  ],
  "index_source": ["BOA"],
  "mask_type": [null],
  "max_mask": [100],
  "mask_smooth": [0],
  "mask_buffer": [0],
  "clip_on_extent": [true],
  "extent_as_mask": [false],
  "extent_name": ["sen2r"],
  "reference_path": [null],
  "res": [null],
  "res_s2": ["10m"],
  "unit": ["Meter"],
  "proj": [null],
  "resampling": ["near"],
  "resampling_scl": ["near"],
  "outformat": ["GTiff"],
  "rgb_outformat": ["GTiff"],
  "index_datatype": ["Int16"],
  "compression": ["DEFLATE"],
  "rgb_compression": ["DEFLATE"],
  "overwrite": [false],
  "path_l1c": ["C:/Users/pthom/DOCUME~1/SEN2R~1/safe"],
  "path_l2a": ["C:/Users/pthom/DOCUME~1/SEN2R~1/safe"],
  "path_tiles": [null],
  "path_merged": [null],
  "path_out": ["C:\\Users\\pthom\\AppData\\Local\\Temp\\RtmpyAjAd3\\sen2r_out_120814e04eb2"],
  "path_rgb": [""],
  "path_indices": [""],
  "path_subdirs": [true],
  "thumbnails": [true],
  "log": [null],
  "parallel": [false],
  "processing_order": ["by_groups"],
  "pkg_version": ["1.6.0"]
}

To identify a spatial extent for the query this file calls on a geoJSON file provided by the sen2r package. The contents of this file are displayed here.

{
"type": "FeatureCollection",
"name": "barbellino",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::32632" } },
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 580560.0, 5101700.0 ], [ 580680.0, 5101700.0 ], [ 580800.0, 5101820.0 ], [ 580800.0, 5102120.0 ], [ 580660.0, 5102120.0 ], [ 580560.0, 5102020.0 ], [ 580560.0, 5101700.0 ] ] ] } }
]
}

I am using R 4.3.2 and sen2r version 1.6.0. I have tried updating all installed R packages on my device, installing sen2r using install_github, and looking through lots of other similar issues online. It may be just that the issue cannot be fixed unless the creator of the package is able to restore something; I'm not sure. It appears that the package has been updated recently to reflect some non-R software changes, so most of the questions about sen2r online come from older versions. Let me know if there's any other information you would find helpful, or if you have any suggestions for me here.

Thanks!

1

There are 1 answers

4
Micha On

You have only one single date in your time range: "2022-08-01".

Set to something like:

"timewindow": ["2020-07-01", "2020-09-01"]

and try again.

Edits...

I copied your config.json, and the geojson extent file from above, into a directory on my computer, and ran the sen2r command as follows (overwriting some of the config options, to simplify):

library(sen2r)    
sen2r(param_list = "~/work/tmp/PeterThompson/config.json", gui = FALSE, timewindow = c('2020-07-01', '2020-09-01'), rm_safe = "no", extent = "~/work/tmp/PeterThompson/aoi.geojson", extent_name = "barbellino", path_l1c = "~/work/tmp/PeterThompson/", path_l2a = "~/work/tmp/PeterThompson/", path_out = "~/work/tmp/PeterThompson/", overwrite_safe = FALSE, list_prods = "BOA", list_indices = "SAVI")
list.files("~/work/tmp/PeterThompson/BOA", pattern = ".*tif")
 [1] "S2A2A_20200707_022_barbellino_BOA_10.tif" "S2A2A_20200710_065_barbellino_BOA_10.tif"
 [3] "S2A2A_20200717_022_barbellino_BOA_10.tif" "S2A2A_20200720_065_barbellino_BOA_10.tif"
 [5] "S2A2A_20200727_022_barbellino_BOA_10.tif" "S2A2A_20200730_065_barbellino_BOA_10.tif"
 [7] "S2A2A_20200806_022_barbellino_BOA_10.tif" "S2A2A_20200809_065_barbellino_BOA_10.tif"
 [9] "S2A2A_20200816_022_barbellino_BOA_10.tif" "S2A2A_20200819_065_barbellino_BOA_10.tif"
[11] "S2A2A_20200826_022_barbellino_BOA_10.tif" "S2A2A_20200829_065_barbellino_BOA_10.tif"
[13] "S2B2A_20200702_022_barbellino_BOA_10.tif" "S2B2A_20200705_065_barbellino_BOA_10.tif"
[15] "S2B2A_20200712_022_barbellino_BOA_10.tif" "S2B2A_20200715_065_barbellino_BOA_10.tif"
[17] "S2B2A_20200722_022_barbellino_BOA_10.tif" "S2B2A_20200725_065_barbellino_BOA_10.tif"
[19] "S2B2A_20200801_022_barbellino_BOA_10.tif" "S2B2A_20200804_065_barbellino_BOA_10.tif"
[21] "S2B2A_20200811_022_barbellino_BOA_10.tif" "S2B2A_20200814_065_barbellino_BOA_10.tif"
[23] "S2B2A_20200821_022_barbellino_BOA_10.tif" "S2B2A_20200824_065_barbellino_BOA_10.tif"
[25] "S2B2A_20200831_022_barbellino_BOA_10.tif"

This code successfully downloaded 25 SAFE directories, and created the BOA and SAVI products.

Perhaps you can start with something simple, then if it works, try adding other products.