Skip to content

Commit d0f5b4a

Browse files
Merge pull request #1069 from rolfsimoes/dev2
Add support to Sentinel-1-RTC on Planetary Computer
2 parents d2bcf21 + 3170394 commit d0f5b4a

File tree

7 files changed

+167
-13
lines changed

7 files changed

+167
-13
lines changed

NAMESPACE

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ S3method(.band_rename,sits)
1616
S3method(.check_samples,default)
1717
S3method(.check_samples,sits)
1818
S3method(.check_samples,tbl_df)
19+
S3method(.cube_adjust_crs,"mpc_cube_sentinel-1-grd")
20+
S3method(.cube_adjust_crs,default)
1921
S3method(.cube_as_sf,default)
2022
S3method(.cube_as_sf,raster_cube)
2123
S3method(.cube_bands,default)
@@ -304,6 +306,7 @@ S3method(sits_combine_predictions,average)
304306
S3method(sits_combine_predictions,default)
305307
S3method(sits_combine_predictions,uncertainty)
306308
S3method(sits_cube,"mpc_cube_sentinel-1-grd")
309+
S3method(sits_cube,"mpc_cube_sentinel-1-rtc")
307310
S3method(sits_cube,default)
308311
S3method(sits_cube,local_cube)
309312
S3method(sits_cube,stac_cube)

R/api_cube.R

+18
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ NULL
277277
crs <- .cube_crs(cube)
278278
return(crs)
279279
}
280+
#' @title Adjust crs of a data cube
281+
#' @keywords internal
282+
#' @noRd
283+
#' @name .cube_adjust_crs
284+
#' @param cube data cube
285+
#' @return data cube with adjusted crs
286+
.cube_adjust_crs <- function(cube) {
287+
UseMethod(".cube_adjust_crs", cube)
288+
}
289+
#' @export
290+
`.cube_adjust_crs.mpc_cube_sentinel-1-grd` <- function(cube) {
291+
cube$crs <- NA
292+
return(cube)
293+
}
294+
#' @export
295+
.cube_adjust_crs.default <- function(cube) {
296+
return(cube)
297+
}
280298
#' @title Return the S3 class of the cube
281299
#' @name .cube_s3class
282300
#' @keywords internal

R/api_plot_raster.R

+14-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,20 @@
5151
tile = tile,
5252
tmap_options = tmap_options
5353
)
54-
54+
if (!.has(.crs(tile))) {
55+
temp <- tempfile(fileext = ".tif")
56+
.gdal_warp(
57+
file = temp,
58+
base_files = bw_file,
59+
params = list(
60+
"-ts" = list(size[["xsize"]], size[["ysize"]]),
61+
"-multi" = TRUE,
62+
"-q" = TRUE,
63+
"-overwrite" = FALSE
64+
),
65+
quiet = TRUE)
66+
bw_file <- temp
67+
}
5568
# read file
5669
stars_obj <- stars::read_stars(
5770
bw_file,

R/api_source_mpc.R

+54-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
#' @param stac_query Query that follows the STAC protocol
100100
#' @param bands Names of the bands to filter
101101
#' @param ... Other parameters to be passed for specific types.
102-
#' @param orbit Name of the orbit (e.g. "Ascending" or "Descending")
102+
#' @param orbit Name of the orbit (e.g. "ascending" or "descending")
103103
#' @param tiles Selected tiles (optional)
104104
#' @param platform Satellite platform (optional).
105105
#' @return An object referring the images of a sits cube.
@@ -108,7 +108,7 @@
108108
source,
109109
collection,
110110
bands, ...,
111-
orbit = "Descending",
111+
orbit = "descending",
112112
start_date = NULL,
113113
end_date = NULL,
114114
dry_run = TRUE) {
@@ -130,7 +130,7 @@
130130
"ymin" = -10.1973,
131131
"xmax" = -50.410,
132132
"ymax" = -10.1510,
133-
"crs" = "EPSG:4386"
133+
"crs" = "EPSG:4326"
134134
),
135135
start_date = start_date,
136136
end_date = end_date,
@@ -201,6 +201,26 @@
201201
}
202202
return(invisible(NULL))
203203
}
204+
205+
`.source_collection_access_test.mpc_cube_sentinel-1-rtc` <- function(
206+
source,
207+
collection,
208+
bands, ...,
209+
orbit = "descending",
210+
start_date = NULL,
211+
end_date = NULL,
212+
dry_run = TRUE) {
213+
214+
`.source_collection_access_test.mpc_cube_sentinel-1-grd`(
215+
source = source,
216+
collection = collection,
217+
bands = bands, ...,
218+
orbit = orbit,
219+
start_date = start_date,
220+
end_date = end_date,
221+
dry_run = dry_run
222+
)
223+
}
204224
#' @title Get bbox from file info
205225
#' @keywords internal
206226
#' @noRd
@@ -237,6 +257,15 @@
237257
bbox <- c(xmin = xmin, ymin = ymin, xmax = xmax, ymax = ymax)
238258
return(bbox)
239259
}
260+
`.source_tile_get_bbox.mpc_cube_sentinel-1-rtc` <- function(source,
261+
file_info, ...,
262+
collection = NULL) {
263+
`.source_tile_get_bbox.mpc_cube_sentinel-1-grd`(
264+
source = source,
265+
file_info = file_info, ...,
266+
collection = collection
267+
)
268+
}
240269
#' @keywords internal
241270
#' @noRd
242271
#' @export
@@ -304,7 +333,19 @@
304333
)
305334
return(items_info)
306335
}
307-
336+
`.source_items_new.mpc_cube_sentinel-1-rtc` <- function(source,
337+
collection,
338+
stac_query, ...,
339+
tiles = NULL,
340+
orbit = "ascending") {
341+
`.source_items_new.mpc_cube_sentinel-1-grd`(
342+
source = source,
343+
collection = collection,
344+
stac_query = stac_query, ...,
345+
tiles = tiles,
346+
orbit = orbit
347+
)
348+
}
308349
#' @keywords internal
309350
#' @noRd
310351
#' @export
@@ -313,6 +354,15 @@
313354
collection = NULL) {
314355
rep("NoTilingSystem", rstac::items_length(items))
315356
}
357+
`.source_items_tile.mpc_cube_sentinel-1-rtc` <- function(source,
358+
items, ...,
359+
collection = NULL) {
360+
`.source_items_tile.mpc_cube_sentinel-1-grd`(
361+
source = source,
362+
items = items, ...,
363+
collection = collection
364+
)
365+
}
316366

317367
#' @keywords internal
318368
#' @noRd

R/sits_cube.R

+30-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
#' source = "MPC",
255255
#' collection = "SENTINEL-1-GRD",
256256
#' bands = c("VV", "VH"),
257-
#' orbit = "ascending",
257+
#' orbit = "descending",
258258
#' roi = roi_sar,
259259
#' start_date = "2020-06-01",
260260
#' end_date = "2020-09-28"
@@ -309,6 +309,32 @@ sits_cube <- function(source, collection, ...) {
309309
orbit = orbit
310310
)
311311
}
312+
#' @rdname sits_cube
313+
#'
314+
#' @export
315+
`sits_cube.mpc_cube_sentinel-1-rtc` <- function(source,
316+
collection, ...,
317+
orbit = "ascending",
318+
bands = NULL,
319+
tiles = NULL,
320+
roi = NULL,
321+
start_date = NULL,
322+
end_date = NULL,
323+
platform = NULL,
324+
progress = TRUE) {
325+
sits_cube.stac_cube(
326+
source = source,
327+
collection = collection,
328+
bands = bands,
329+
tiles = tiles,
330+
roi = roi,
331+
start_date = start_date,
332+
end_date = end_date,
333+
platform = platform,
334+
progress = progress,
335+
orbit = orbit
336+
)
337+
}
312338

313339
#' @rdname sits_cube
314340
#'
@@ -379,7 +405,7 @@ sits_cube.stac_cube <- function(source,
379405
end_date = end_date
380406
)
381407
# builds a sits data cube
382-
.source_cube(
408+
cube <- .source_cube(
383409
source = source,
384410
collection = collection,
385411
bands = bands,
@@ -390,6 +416,8 @@ sits_cube.stac_cube <- function(source,
390416
platform = platform,
391417
progress = progress, ...
392418
)
419+
# adjust crs of the cube before return
420+
.cube_adjust_crs(cube)
393421
}
394422
#' @rdname sits_cube
395423
#'

inst/extdata/config.yml

+31-4
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ sources:
455455
service : "STAC"
456456
url : "https://earth-search.aws.element84.com/v1/"
457457
collections :
458-
SENTINEL-2-L2A :
458+
SENTINEL-2-L2A :
459459
bands :
460460
B01 : &aws_msi_60m
461461
missing_value: -9999
@@ -1234,15 +1234,15 @@ sources:
12341234
metadata_search : "tile"
12351235
ext_tolerance: 0
12361236
grid_system : "MGRS"
1237-
SENTINEL-1-GRD : &mspc_msi
1237+
SENTINEL-1-GRD : &mspc_s1_grd
12381238
bands :
12391239
VV : &mspc_grd_10m
12401240
missing_value : 0
12411241
minimum_value : 1
12421242
maximum_value : 65534
1243-
scale_factor : 0.0001
1243+
scale_factor : 0.001
12441244
offset_value : 0
1245-
resolution : 10
1245+
resolution : 10
12461246
band_name : "vv"
12471247
data_type : "INT2U"
12481248
VH :
@@ -1260,6 +1260,33 @@ sources:
12601260
metadata_search: "feature"
12611261
ext_tolerance: 0
12621262
grid_system : "MGRS"
1263+
SENTINEL-1-RTC : &mspc_s1_rtc
1264+
bands :
1265+
VV : &mspc_rtc_10m
1266+
missing_value : -32768.0
1267+
minimum_value : 0
1268+
maximum_value : 65534
1269+
scale_factor : 1
1270+
offset_value : 0
1271+
resolution : 10
1272+
band_name : "vv"
1273+
data_type : "FLT4S"
1274+
VH :
1275+
<<: *mspc_rtc_10m
1276+
band_name : "vh"
1277+
satellite : "SENTINEL-1"
1278+
sensor : "RTC"
1279+
orbits : ["ascending", "descending"]
1280+
platforms :
1281+
SENTINEL-1A: "Sentinel-1A"
1282+
SENTINEL-1B: "Sentinel-1B"
1283+
collection_name: "sentinel-1-rtc"
1284+
open_data: false
1285+
open_data_token: false
1286+
metadata_search: "feature"
1287+
ext_tolerance: 0
1288+
grid_system : "MGRS"
1289+
token_vars : ["MPC_TOKEN"]
12631290
HLS :
12641291
s3_class : ["hls_cube", "stac_cube", "eo_cube",
12651292
"raster_cube"]

man/sits_cube.Rd

+17-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)