-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean #9
Open
hsonne
wants to merge
16
commits into
dev
Choose a base branch
from
clean
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Clean #9
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
050fb6a
Clean create_ad4gd_env()
hsonne 6805413
Clean flatten_results
hsonne be4c6d9
Clean get_metadata_gee.R
hsonne 0d8cd73
Clean import_rds()
hsonne cd10903
Rename file according to contained function
hsonne 1773e63
Fix merge conflict
hsonne cff07e4
Standardise indentation and spacing in vignette
hsonne 378de90
Improve create_periods_in_year()
hsonne cffba18
Normalise indentation and spacing
hsonne 920f9ed
Use inherits()
hsonne bebc06c
Create metadata directly in a pipe
hsonne fd98ab5
Compose message string within catAndRun()
hsonne 206e440
Improve gee_get_data_for_years_parallel()
hsonne e56dec3
Improve gee_get_data_for_years_parallel()
hsonne fcf9398
Merge branch 'clean' of https://github.com/kwb-r/kwb.satellite into c…
hsonne 6cc6e07
Add utils.R with is_this_year(), this_year()
hsonne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,72 @@ | ||
#' Helper function: convert to list | ||
#' | ||
#' @param coords column with satellite metadata coordinates (system:footprint`$coordinates) | ||
#' | ||
#' @param coords column with satellite metadata coordinates | ||
#' (system:footprint`$coordinates) | ||
#' @return list of coordinates | ||
#' @keywords internal | ||
#' | ||
convert_to_list <- function(coords) { | ||
|
||
tmp_mat <- lapply(seq_along(coords), | ||
FUN = function(idx) { | ||
|
||
t(as.matrix(coords[[idx]])) | ||
}) | ||
|
||
list(do.call(rbind, tmp_mat)) | ||
convert_to_list <- function(coords) | ||
{ | ||
lapply(coords, function(x) t(as.matrix(x))) %>% | ||
do.call(what = rbind) %>% | ||
list() | ||
} | ||
|
||
|
||
#' Google Earth Engine: get metadata for collection | ||
#' | ||
#' @param collection collection | ||
#' | ||
#' @return tibble with metadata. In addition also the complex column | ||
#' "geometry_meta_org" is simplified and stored in the new column "geometry_meta_cleaned" | ||
#' "geometry_meta_org" is simplified and stored in the new column | ||
#' "geometry_meta_cleaned" | ||
#' @export | ||
#' @importFrom tibble as_tibble tibble | ||
#' @importFrom dplyr bind_cols bind_rows | ||
#' @importFrom kwb.utils removeColumns | ||
#' @importFrom tidyr nest | ||
#' @importFrom tidyselect matches all_of | ||
gee_get_metadata <- function(collection) { | ||
|
||
nImages <- collection$size()$getInfo() | ||
#' @importFrom tidyselect matches | ||
gee_get_metadata <- function(collection) | ||
{ | ||
metadata_list <- collection$size()$getInfo() %>% | ||
collection$toList() %>% | ||
collection$fromImages() | ||
|
||
collectionList <- collection$toList(nImages) | ||
|
||
metadata_list <- collection$fromImages(collectionList) | ||
metadata_list <- metadata_list$getInfo() | ||
|
||
|
||
metadata_features_df <- lapply(seq_along(metadata_list$features), function(idx) { | ||
tibble::as_tibble(metadata_list$features[[idx]]$properties) | ||
}) %>% dplyr::bind_rows() %>% | ||
metadata_features_df <- metadata_list$features %>% | ||
lapply(function(x) tibble::as_tibble(x$properties)) %>% | ||
dplyr::bind_rows() %>% | ||
tidyr::nest(geometry_meta_org = tidyselect::matches("system:footprint")) | ||
|
||
geometries <- metadata_features_df$geometry_meta_org | ||
|
||
coords <- lapply(seq_len(nrow(metadata_features_df)), function(idx) { | ||
convert_to_list(metadata_features_df$geometry_meta_org[[idx]]$`system:footprint`$coordinates) %>% | ||
coords <- lapply(seq_len(nrow(metadata_features_df)), function(i) { | ||
geometries[[i]]$`system:footprint`$coordinates %>% | ||
convert_to_list() %>% | ||
sf::st_polygon() %>% | ||
sf::st_sfc() %>% | ||
sf::st_set_crs(value = 4326) | ||
}) | ||
|
||
metadata_features_df$geometry_meta_cleaned <- coords | ||
|
||
metadata_ids <- tibble::tibble( | ||
id = sapply(seq_along(metadata_list$features), function(idx) metadata_list$features[[idx]]$id) | ||
) | ||
|
||
dplyr::bind_cols(metadata_ids, metadata_features_df) %>% | ||
tidyr::separate(col = "id", | ||
into = c("provider_name", "provider_collection", "id_short"), | ||
sep = "/", | ||
remove = FALSE) %>% | ||
tibble::tibble( | ||
id = sapply(metadata_list$features, function(x) x$id) | ||
) %>% | ||
dplyr::bind_cols(metadata_features_df) %>% | ||
tidyr::separate( | ||
col = "id", | ||
into = c("provider_name", "provider_collection", "id_short"), | ||
sep = "/", | ||
remove = FALSE | ||
) %>% | ||
tidyr::separate( | ||
col = "id_short", | ||
into = c("datetime_start", | ||
"datetime_end", | ||
"tile_id"), | ||
into = c("datetime_start", "datetime_end", "tile_id"), | ||
sep = "_" | ||
) %>% | ||
dplyr::mutate( | ||
datetime_start = lubridate::ymd_hms(datetime_start), | ||
datetime_end = lubridate::ymd_hms(datetime_end) | ||
) %>% | ||
dplyr::select(- tidyselect::all_of(c("provider_name","provider_collection"))) | ||
|
||
kwb.utils::removeColumns(c("provider_name", "provider_collection")) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
metadata_list$getInfo()$features
dametadata_list <- metadata_list$getInfo()
gelöscht wurdeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Steht das nicht in Zeile 33?