Skip to content

Commit 85adc5f

Browse files
Merge pull request #1170 from M3nin0/feat/deaustralia
2 parents 11b943d + 3b34ed7 commit 85adc5f

37 files changed

+2407
-172
lines changed

DESCRIPTION

+2
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ Collate:
181181
'api_source_bdc.R'
182182
'api_source_cdse.R'
183183
'api_source_deafrica.R'
184+
'api_source_deaustralia.R'
184185
'api_source_hls.R'
185186
'api_source_local.R'
186187
'api_source_mpc.R'
187188
'api_source_sdc.R'
188189
'api_source_stac.R'
190+
'api_source_terrascope.R'
189191
'api_source_usgs.R'
190192
'api_space_time_operations.R'
191193
'api_stac.R'

NAMESPACE

+6
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,19 @@ S3method(.source_items_fid,stac_cube)
175175
S3method(.source_items_new,"aws_cube_landsat-c2-l2")
176176
S3method(.source_items_new,"deafrica_cube_sentinel-1-rtc")
177177
S3method(.source_items_new,"deafrica_cube_sentinel-2-l2a")
178+
S3method(.source_items_new,"deaustralia_cube_sentinel-2a")
179+
S3method(.source_items_new,"deaustralia_cube_sentinel-2b")
178180
S3method(.source_items_new,"mpc_cube_cop-dem-glo-30")
179181
S3method(.source_items_new,"mpc_cube_landsat-c2-l2")
180182
S3method(.source_items_new,"mpc_cube_sentinel-1-grd")
181183
S3method(.source_items_new,"mpc_cube_sentinel-1-rtc")
182184
S3method(.source_items_new,"mpc_cube_sentinel-2-l2a")
185+
S3method(.source_items_new,"terrascope_cube_world-cover-2021")
183186
S3method(.source_items_new,aws_cube)
184187
S3method(.source_items_new,bdc_cube)
185188
S3method(.source_items_new,cdse_cube)
186189
S3method(.source_items_new,deafrica_cube)
190+
S3method(.source_items_new,deaustralia_cube)
187191
S3method(.source_items_new,hls_cube)
188192
S3method(.source_items_new,mpc_cube)
189193
S3method(.source_items_new,sdc_cube)
@@ -200,10 +204,12 @@ S3method(.source_items_tile,"mpc_cube_mod13q1-6.1")
200204
S3method(.source_items_tile,"mpc_cube_sentinel-1-grd")
201205
S3method(.source_items_tile,"mpc_cube_sentinel-1-rtc")
202206
S3method(.source_items_tile,"mpc_cube_sentinel-2-l2a")
207+
S3method(.source_items_tile,"terrascope_cube_world-cover-2021")
203208
S3method(.source_items_tile,aws_cube)
204209
S3method(.source_items_tile,bdc_cube)
205210
S3method(.source_items_tile,cdse_cube)
206211
S3method(.source_items_tile,deafrica_cube)
212+
S3method(.source_items_tile,deaustralia_cube)
207213
S3method(.source_items_tile,hls_cube)
208214
S3method(.source_items_tile,sdc_cube)
209215
S3method(.source_items_tile,usgs_cube)

R/api_check.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@
18591859
})
18601860
classes_num <- unique(unlist(classes_list))
18611861
classes_num <- classes_num[!is.na(classes_num)]
1862-
labels_num <- names(.cube_labels(cube))
1862+
labels_num <- names(unlist(.cube_labels(cube, dissolve = FALSE)))
18631863
# do the labels and raster numbers match?
18641864
.check_that(all(classes_num %in% labels_num))
18651865
return(invisible(cube))

R/api_conf.R

+91-43
Original file line numberDiff line numberDiff line change
@@ -707,53 +707,41 @@
707707
msg = .conf("messages", ".conf_new_collection_metadata")
708708
)
709709
}
710-
# bands names is upper case
711-
names(bands) <- toupper(names(bands))
712-
# separate cloud and non-cloud bands
713-
non_cloud_bands <- bands[!names(bands) %in% .source_cloud()]
714-
cloud_band <- bands[names(bands) %in% .source_cloud()]
715-
716-
non_cloud_bands <- lapply(non_cloud_bands, function(band) {
717-
# pre-condition
718-
.check_lst(bands,
719-
len_min = 1,
720-
msg = .conf("messages", ".conf_new_collection_bands")
721-
)
722-
# bands' members are lower case
723-
names(band) <- tolower(names(band))
724-
band <- .check_error(
725-
{
726-
do.call(.conf_new_band, args = band)
727-
},
728-
msg = .conf("messages", ".conf_new_collection_bands")
729-
)
730-
return(band)
731-
})
732-
733-
cloud_band <- lapply(cloud_band, function(cloud_band) {
734-
# pre-condition
735-
.check_lst(bands,
736-
len_min = 1,
737-
msg = .conf("messages", ".conf_new_collection_bands")
738-
)
739-
# bands' members are lower case
740-
names(cloud_band) <- tolower(names(cloud_band))
741-
cloud_band <- .check_error(
742-
{
743-
do.call(.conf_new_cloud_band, args = cloud_band)
744-
},
745-
msg = .conf("messages", ".conf_new_collection_bands")
746-
)
747-
return(cloud_band)
748-
})
749-
750-
# extra parameters
710+
# check extra parameters
751711
dots <- list(...)
752712
.check_lst(dots,
753713
msg = .conf("messages", ".conf_new_collection_metadata_args")
754714
)
755-
756-
res <- c(list(bands = c(non_cloud_bands, cloud_band)),
715+
# bands names is upper case
716+
names(bands) <- toupper(names(bands))
717+
# pre-condition
718+
.check_lst(bands,
719+
len_min = 1,
720+
msg = .conf("messages", ".conf_new_collection_bands")
721+
)
722+
# define collection bands
723+
collection_bands <- c()
724+
# handle class bands
725+
is_class_cube <- dots[["class_cube"]]
726+
is_class_cube <- all(!is.null(is_class_cube))
727+
if (is_class_cube) {
728+
# configure class bands (assuming there is no cloud band in class cubes)
729+
class_bands <- .conf_new_bands(bands, .conf_new_class_band)
730+
# save band configuration object
731+
collection_bands <- c(class_bands)
732+
} else {
733+
# handle cloud and non-cloud bands
734+
cloud_band <- bands[names(bands) %in% .source_cloud()]
735+
non_cloud_bands <- bands[!names(bands) %in% .source_cloud()]
736+
# cloud bands
737+
cloud_band <- .conf_new_bands(cloud_band, .conf_new_cloud_band)
738+
# non-cloud bands
739+
non_cloud_bands <- .conf_new_bands(non_cloud_bands, .conf_new_band)
740+
# save bands configuration object
741+
collection_bands <- c(non_cloud_bands, cloud_band)
742+
}
743+
# merge metadata properties
744+
res <- c(list(bands = collection_bands),
757745
"satellite" = satellite,
758746
"sensor" = sensor,
759747
"metadata_search" = metadata_search, dots
@@ -896,6 +884,66 @@
896884
# return a cloud band object
897885
return(cloud_band_params)
898886
}
887+
#' @title Include a new class band in the configuration
888+
#' @name .conf_new_class_band
889+
#' @description creates a description associated to a new cloud band
890+
#' @param bit_mask bit mask to describe clouds (if applicable)
891+
#' @param values values of the class band
892+
#' @param resolution spatial resolution (in meters)
893+
#' @param band_name name of the band
894+
#' @param ... other relevant parameters
895+
#' @keywords internal
896+
#' @noRd
897+
#' @return list with the configuration associated to the new class band
898+
.conf_new_class_band <- function(bit_mask, values, resolution, band_name, ...) {
899+
# set caller to show in errors
900+
.check_set_caller(".conf_new_class_band")
901+
# pre-condition
902+
.check_lgl_parameter(bit_mask)
903+
.check_lst_parameter(values, fn_check = .check_chr)
904+
.check_chr_parameter(band_name, len_min = 1, len_max = 1)
905+
906+
# check extra parameters
907+
dots <- list(...)
908+
.check_lst(dots, msg = .conf("messages",
909+
".check_new_class_band_dots"))
910+
911+
# build band
912+
class_band_params <- c(list(
913+
bit_mask = bit_mask,
914+
values = values,
915+
resolution = resolution,
916+
band_name = band_name
917+
), dots)
918+
919+
# post-condition
920+
.check_lst_parameter(class_band_params, len_min = 4)
921+
922+
# return a class band object
923+
return(class_band_params)
924+
}
925+
#' @title Configure bands
926+
#' @name .conf_new_bands
927+
#' @description creates a description of multiple bands based on a user-defined
928+
#' strategy.
929+
#' @param bands bands to be configured
930+
#' @param config_fnc band configuration strategy function
931+
#' @keywords internal
932+
#' @noRd
933+
#' @return list of configurations associated with the given bands
934+
.conf_new_bands <- function(bands, config_fnc) {
935+
lapply(bands, function(band) {
936+
# lower case bands
937+
names(band) <- tolower(names(band))
938+
# configure band
939+
.check_error(
940+
{
941+
do.call(config_fnc, args = band)
942+
},
943+
msg = .conf("messages", ".conf_new_collection_bands")
944+
)
945+
})
946+
}
899947
#' @title Retrieve the rstac pagination limit
900948
#' @name .conf_rstac_limit
901949
#' @keywords internal

0 commit comments

Comments
 (0)