|
707 | 707 | msg = .conf("messages", ".conf_new_collection_metadata")
|
708 | 708 | )
|
709 | 709 | }
|
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 |
751 | 711 | dots <- list(...)
|
752 | 712 | .check_lst(dots,
|
753 | 713 | msg = .conf("messages", ".conf_new_collection_metadata_args")
|
754 | 714 | )
|
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), |
757 | 745 | "satellite" = satellite,
|
758 | 746 | "sensor" = sensor,
|
759 | 747 | "metadata_search" = metadata_search, dots
|
|
896 | 884 | # return a cloud band object
|
897 | 885 | return(cloud_band_params)
|
898 | 886 | }
|
| 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 | +} |
899 | 947 | #' @title Retrieve the rstac pagination limit
|
900 | 948 | #' @name .conf_rstac_limit
|
901 | 949 | #' @keywords internal
|
|
0 commit comments