Skip to content
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

Update vignette #25

Merged
merged 19 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
56a371d
Bug fix raster time index
rolfsimoes Nov 16, 2017
88ddc2c
Merge branch 'master' of http:https://github.com/e-sensing/sits
rolfsimoes Nov 17, 2017
974d693
Merge branch 'master' of https://github.com/e-sensing/sits
rolfsimoes Nov 23, 2017
9fe48b8
Merge branch 'master' of http:https://github.com/rolfsimoes/sits
rolfsimoes Nov 23, 2017
9096840
Merge branch 'master' of https://github.com/e-sensing/sits
rolfsimoes Nov 27, 2017
3506ca5
Introduce Namespace verification for dtw, dtwclust, and dtwSat packages.
rolfsimoes Nov 30, 2017
7c11a4c
Merge branch 'master' of https://github.com/e-sensing/sits
rolfsimoes Nov 30, 2017
51e6ed6
Remove warnings on check procedure
rolfsimoes Dec 1, 2017
77c99d8
Merge branch 'master' of https://github.com/e-sensing/sits
rolfsimoes Dec 1, 2017
528f127
Remove data adjustment of sits_getdate() function
rolfsimoes Dec 1, 2017
41f3521
Improve `sits_apply()` function
rolfsimoes Dec 14, 2017
f209352
Merge upstream master
rolfsimoes Dec 14, 2017
69de64e
Merge upstream master
rolfsimoes Dec 14, 2017
ba47dfa
Merge branch 'master' of https://github.com/e-sensing/sits
rolfsimoes Dec 17, 2017
8a5cf8b
Small fix and improvements
rolfsimoes Jan 7, 2018
9395e41
Merge upstream master
rolfsimoes Jan 7, 2018
85a2ea5
Update Vignette, and some clustering functions
rolfsimoes Jan 8, 2018
975a6f1
Vignette update
rolfsimoes Jan 8, 2018
fcf6add
Merge branch 'master' of https://github.com/e-sensing/sits
rolfsimoes Jan 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve sits_apply() function
  • Loading branch information
rolfsimoes committed Dec 14, 2017
commit 41f35218c51847b08b89cd0355f74c81cdc027fd
3 changes: 2 additions & 1 deletion R/sits_classification.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ sits_classify_raster <- function (file = NULL, raster.tb, samples.tb, ml_method

# ensure metadata tibble exists
.sits_test_tibble (raster.tb)

# ensure patterns tibble exits
.sits_test_tibble (samples.tb)

# ensure that file name and prediction model are provided
ensurer::ensure_that(file, !purrr::is_null(.), err_desc = "sits-classify-raster: please provide name of output file")
ensurer::ensure_that(file, !purrr::is_null(.), err_desc = "sits-classify-raster: please provide name of output file")

# set up the ML model
distances.tb <- sits_distances (samples.tb)
Expand Down
76 changes: 54 additions & 22 deletions R/sits_tibble_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,61 @@ sits_apply <- function(data.tb, fun, fun_index = function(index){ return(index)
# verify if data.tb has values
.sits_test_tibble (data.tb)

# computes fun and fun_index for all time series and substitutes the original time series data
data.tb$time_series <- data.tb$time_series %>%
purrr::map(function(ts.tb) {
ts_computed.lst <- dplyr::select(ts.tb, -Index) %>%
purrr::map(fun)

# append bands names' suffixes
if (nchar(bands_suffix) != 0)
names(ts_computed.lst) <- paste0(names(ts_computed.lst), ".", bands_suffix)

# unlist if there are more than one result from `fun`
if (is.recursive(ts_computed.lst[[1]]))
ts_computed.lst <- unlist(ts_computed.lst, recursive = FALSE)

# convert to tibble
ts_computed.tb <- tibble::as_tibble(ts_computed.lst)

# compute Index column
ts_computed.tb <- dplyr::mutate(ts_computed.tb, Index = fun_index(ts.tb$Index))
# save columns name from the first time series tibble
ts_cols <- names(data.tb$time_series[[1]])

# unnest tibble
data.tb <-
data.tb %>%
tidyr::unnest()

# computes fun for all time series fields and substitutes the original time series data
data.tb[,ts_cols] <-
data.tb[,ts_cols[-1:0]] %>%
purrr::map(fun) %>%
dplyr::bind_cols()

# computes fun_index for all time series fields and substitutes the original time series data
data.tb[,ts_cols[1]] <-
data.tb[,ts_cols[1]] %>%
purrr::map(fun_index) %>%
dplyr::bind_cols()

# verifies if there is a suffix and updates the columns names
if (nchar(bands_suffix) != 0)
ts_cols[-1:0] <- paste0(ts_cols[-1:0], ".", bands_suffix)

# reorganizes time series tibble
return(dplyr::select(ts_computed.tb, Index, dplyr::everything()))
})
# append bands names' suffixes
names(data.tb) <- c(names(data.tb)[1:(length(names(data.tb))-length(ts_cols))], ts_cols)

# nest result and return
data.tb <-
data.tb %>%
tidyr::nest(ts_cols, .key = "time_series")
#
# # computes fun and fun_index for all time series and substitutes the original time series data
# data.tb$time_series <- data.tb$time_series %>%
# purrr::map(function(ts.tb) {
# ts_computed.lst <- dplyr::select(ts.tb, -Index) %>%
# purrr::map(fun)
#
# # append bands names' suffixes
# if (nchar(bands_suffix) != 0)
# names(ts_computed.lst) <- paste0(names(ts_computed.lst), ".", bands_suffix)
#
# # unlist if there are more than one result from `fun`
# if (is.recursive(ts_computed.lst[[1]]))
# ts_computed.lst <- unlist(ts_computed.lst, recursive = FALSE)
#
# # convert to tibble
# ts_computed.tb <- tibble::as_tibble(ts_computed.lst)
#
# # compute Index column
# ts_computed.tb <- dplyr::mutate(ts_computed.tb, Index = fun_index(ts.tb$Index))
#
# # reorganizes time series tibble
# return(dplyr::select(ts_computed.tb, Index, dplyr::everything()))
# })
return(data.tb)
}
#' @title Apply a function on each SITS tibble column element
Expand Down
4 changes: 2 additions & 2 deletions inst/extdata/markdown/sits_description.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ author:
- name: Gilberto Camara
affiliation: National Institute for Space Reseach, INPE, Brazil
- name: Alexandre Iwata
affiliation: Institute for Applied Economics Research (IPEA), Brazil
affiliation: Institute for Applied Economics Research, IPEA, Brazil
- name: Victor Maus
affiliation: International Institute for Applied System Analysis (IIASA)
affiliation: International Institute for Applied System Analysis, IIASA,
abstract: "Using time series derived from big Earth Observation data sets is one of the leading research trends in Land Use Science and Remote Sensing. One of the more promising uses of satellite time series is its application for classification of land use and land cover, since our growing demand for natural resources has caused major environmental impacts. The SITS package provides support on how to use statistical learning techniques with image time series. These methods include linear and quadratic discrimination analysis, support vector machines, random forests and neural networks."
date: "`r format(Sys.time(), '%B %d, %Y')`"
fontfamily: mathdesign
Expand Down