-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2219a11
commit 50737c4
Showing
4 changed files
with
122 additions
and
115 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
# Morning Report pdf Attribute Plots | ||
# Morning Report Attribute Plots PDF | ||
MoveApps | ||
|
||
Github repository: *github.com/movestore/MorningRep_AttrPlots* | ||
|
||
## Description | ||
This App creates a multipage pdf downloadable file with time-plots of up to five selected data attributes for each individual track. A reference time and (back) time duration have to be provided. So that you can get an overview of how your animals (and tags) were doing. | ||
This App creates a multipage PDF downloadable file with time-plots of selected data attributes for each individual track. A reference time and (back) time duration have to be provided. So that you can get an overview of how your animals (and tags) were doing. | ||
|
||
## Documentation | ||
A multipage pdf is created of up to 5 user-defined data attributes across time. The plotted time window is defined by the reference timestamp (either user-defined or by default NOW) and the time duration that defines how long before the reference timestamp the x-axis of the plots shall start. | ||
A multipage PDF is created of user-defined data attributes across time. The plotted time window is defined by the reference timestamp (either user-defined or by default NOW) and the time duration that defines how long before the reference timestamp the x-axis of the plots shall start. | ||
|
||
### Input data | ||
moveStack in Movebank format | ||
### Application scope | ||
#### Generality of App usability | ||
This App was developed for any taxonomic group. | ||
|
||
### Output data | ||
moveStack in Movebank format | ||
#### Required data properties | ||
The App should work for any kind of (location) data. | ||
|
||
### Input type | ||
`move2::move2_loc` | ||
|
||
### Output type | ||
`move2::move2_loc` | ||
|
||
### Artefacts | ||
`MorningReport_attribPlots.pdf`: Artefact pdf with a multiple attribute plots on each page showing the time series of the selected attributes for one animal. | ||
`MorningReport_attribPlots.pdf`: PDF with attribute plots per track on each page, showing the time series of the selected attributes for each track. | ||
|
||
### Settings | ||
### Settings | ||
**Reference time (`time_now`):** reference timestamp towards which all analyses are performed. Generally (and by default) this is NOW, especially if in the field and looking for one or the other animal or wanting to make sure that it is still doing fine. When analysing older data sets, this parameter can be set to other timestamps so that the to be plotted data fall into a selected back-time window. | ||
|
||
**Track time duration. (`time_dur`):** time duration into the past that the attributes have to be plotted for. So, if the time duration is selected as 7 days then the x-axis ranges from the reference timestamp to 7 days before it. Unit: days | ||
|
||
**Data attributes to plot (max. of 5 attributes allowed) (`attribs`):** the user has to provide the data attributes that shall be plotted for the defined time window. They have to be correctly spelled and comma-separated. Example: "tag_voltage, location_lat". | ||
**Track time duration. (`time_dur`):** time duration into the past that the track has to be plotted for. So, if the time duration is selected as 5 days then the plotted track consists of all location from the reference timestamp to 5 days before it. Values can be also decimals, e.g. 0.25 for the last 6 hours. Unit: days | ||
|
||
### Null or error handling: | ||
**Setting `time_now`:** If this parameter is left empty (NULL) the reference time is set to NOW. The present timestamp is extracted in UTC from the MoveApps server system. | ||
**Data attributes to plot (max. of 5 attributes allowed) (`attribs`):** the user has to provide the data attributes that shall be plotted for the defined time window. They have to be correctly spelled and comma-separated. Example: "battery_voltage, location_lat". | ||
|
||
**Setting `time_dur`:** If this parameter is left empty (NULL) then by default 10 days is used. A respective warning is given. | ||
|
||
**Setting `attribs`:** If no attributes are defined (NULL) or none of the given attributes relate to any column names of the data set, then no pdf artefact is created. If more than 5 valid attributes are listed a warning is given, but the plotting is still done; the plots might be cut off on the pdf pages. | ||
### Changes in output data | ||
The input data remains unchanged. | ||
|
||
**Artefact:** If there are no locations of any animals in the defined time window, a warning is given and no pdf artefact created. | ||
### Most common errors | ||
|
||
**Data:** The data are not manipulated in this App, but plotted in a downloadable pdf. So that a possible Workflow can be continued after this App, the input data set is returned. | ||
### Null or error handling | ||
*Very small plots*: the more attributes are selected, the smaller the plots. If many attributes need to be plotted, consider adding this App several times to the Workflow, each time with different attributes. |
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,77 +1,80 @@ | ||
library('move') | ||
library('foreach') | ||
library('move2') | ||
library('ggplot2') | ||
library('sf') | ||
library("dplyr") | ||
library('reshape2') | ||
library('grid') | ||
library('gridExtra') | ||
library("units") | ||
library("scales") | ||
library("randomcoloR") | ||
library("grid") | ||
|
||
# data <- readRDS("./data/raw/input2_move2loc_Mollweide.rds") | ||
# time_now <- max(mt_time(data)) | ||
# time_dur <- 10 | ||
# attribs <- paste(names(data)[c(2:16)], collapse = " ,") | ||
# attribs <- paste(c("eobs_temperature" ,"height_above_ellipsoid","eobs_fix_battery_voltage"), collapse = " ,") | ||
|
||
Sys.setenv(tz="UTC") | ||
|
||
rFunction = function(time_now=NULL, attribs=NULL, time_dur=NULL, data, ...) { #dont give id selection option, but decide that only plot those with data in the time_dur window | ||
|
||
if (is.null(time_now)) time_now <- Sys.time() else time_now <- as.POSIXct(time_now,format="%Y-%m-%dT%H:%M:%OSZ",tz="UTC") | ||
rFunction = function(time_now=NULL, attribs=NULL, time_dur=NULL, data) { | ||
|
||
if (is.null(attribs)) | ||
{ | ||
if (is.null(attribs)) { | ||
logger.info("Warning! You did not provide any attribute names to be plotted. The function returns the input data set. No plots will be generated.") | ||
} else | ||
{ | ||
attribs_list <- strsplit(attribs,",")[[1]] | ||
for (i in seq(along=attribs_list)) attribs_list[i] <- gsub(" ","",attribs_list[i],fixed=TRUE) | ||
} else{ | ||
|
||
if (is.null(time_now)) {time_now <- Sys.time()} else {time_now <- as.POSIXct(time_now,format="%Y-%m-%dT%H:%M:%OSZ",tz="UTC")} | ||
|
||
data_spl <- move::split(data) | ||
ids <- namesIndiv((data)) | ||
if (is.null(time_dur)) | ||
{ | ||
time_dur <- 10 | ||
logger.info("You did not provide a time duration for your plot. It is defaulted by 10 days.") | ||
} #else time_dur <- as.numeric(time_dur) | ||
time0 <- time_now - as.difftime(time_dur,units="days") | ||
|
||
attribs_ok <- attribs_list[attribs_list %in% names(data)] | ||
len <- length(attribs_ok) | ||
attribs_error <- attribs_list[!attribs_list %in% names(data)] | ||
if (length(attribs_error)>0) logger.info(paste0("Warning! Your defined attributes: ",paste(attribs_error,collapse=", ")," do not exist in the data set. They will not be plotted.")) | ||
dataPlot <- data %>% | ||
group_by(mt_track_id()) %>% | ||
filter(mt_time() >= time0) | ||
|
||
if (len>5) logger.info("Warning! You have selected more than 5 valid attributes to plot. This might lead to strange cutoffs on your pdf pages.") | ||
if (len>0) | ||
{ | ||
logger.info(paste0("Your defined attributes: ",paste(attribs_ok,collapse=", ")," exist in the data set and will be plotted.")) | ||
g <- list() | ||
ids_g <- character() | ||
k <- 1 | ||
for (i in seq(along=ids)) | ||
{ | ||
datai <- data_spl[[i]] | ||
datai_t <- datai[timestamps(datai)>time0 & timestamps(datai)<time_now] | ||
if (length(datai_t)>0) | ||
{ | ||
datai_t_a <- datai_t@data[,c("timestamp",attribs_ok)] | ||
datai.df <- melt(datai_t_a, measure.vars = attribs_ok) | ||
|
||
g[[k]] <- ggplot(datai.df, aes(x = timestamp, y = value)) + | ||
geom_line(aes(color = variable),show.legend=FALSE) + | ||
facet_grid(variable ~ ., scales = "free_y") + | ||
labs(title = paste("individual:",ids[i])) + | ||
theme(plot.margin=grid::unit(c(2,2,2+3*(5-len),2), "cm")) #max 5 attributes to plot | ||
ids_g <- c(ids_g,ids[i]) | ||
k <- k+1 | ||
|
||
} else logger.info(paste0("There are no locations available in the requested time window for individual ",ids[i])) | ||
} | ||
if(nrow(dataPlot)>0){ | ||
idall <- unique(mt_track_id(data)) | ||
idsel <- unique(mt_track_id(dataPlot)) | ||
if(!identical(idall, idsel)){logger.info(paste0("There are no locations available in the requested time window for track(s): ",paste0(idall[!idall%in%idsel], collapse = ", ")))} | ||
|
||
attribs_list <- strsplit(attribs,",")[[1]] | ||
for(i in seq(along=attribs_list)) {attribs_list[i] <- gsub(" ","",attribs_list[i],fixed=TRUE)} | ||
|
||
if (length(ids_g)>0) | ||
{ | ||
logger.info(paste0("Maps are produced for the individuals ",paste(ids_g,collapse=", "),", which have data in the requested time window.")) | ||
gp <- marrangeGrob(g, nrow = 1, ncol = 1) | ||
ggsave(paste0(Sys.getenv(x = "APP_ARTIFACTS_DIR", "/tmp/"),"MorningReport_attribPlots.pdf"), gp, width = 21, height = 29.7, units = "cm") | ||
#ggsave("MorningReport_attribPlots.pdf",gp, width = 21, height = 29.7, units = "cm") | ||
} else logger.info ("None of the individuals have data in the requested time window. Thus, no plots (pdf artefact) is generated.") | ||
attribs_ok <- attribs_list[attribs_list %in% names(data)] | ||
len <- length(attribs_ok) | ||
attribs_error <- attribs_list[!attribs_list %in% names(data)] | ||
if(length(attribs_error)>0) logger.info(paste0("Warning! Your defined attributes: ",paste(attribs_error,collapse=", ")," do not exist in the data set. They will not be plotted.")) | ||
|
||
|
||
if (len>0){ | ||
logger.info(paste0("Your defined attributes: ",paste(attribs_ok,collapse=", ")," exist in the data set and will be plotted.")) | ||
|
||
n <- length(attribs_ok) | ||
if(n < 10){colspt <- brewer_pal(palette = "Set1")(n)}else{colspt <- distinctColorPalette(n)} | ||
|
||
} else logger.info("The provided attributes are not available in the given data set, thus no plots (pdf artefact) can be generated.") | ||
dataPlotTr <- split(dataPlot, mt_track_id(dataPlot)) | ||
ggall <- lapply(dataPlotTr, function(trk){ | ||
trk_df <- data.frame(timestamps=mt_time(trk),as.data.frame(trk)[,attribs_ok]) | ||
# trk_df$dummy <- NA | ||
ggtrk <- lapply(seq_along(attribs_ok), function(x){ | ||
atr <- attribs_ok[x] | ||
clr <- colspt[x] | ||
ggplot(trk_df) + | ||
geom_line(aes(x = timestamps , y = !!sym(atr)), color=clr, show.legend=FALSE) + | ||
# facet_grid( ~ dummy, labeller=labeller(dummy=atr))+ | ||
ggtitle(atr)+ | ||
xlab("")+ylab("")+ | ||
theme_bw() | ||
}) | ||
if(len<=5){ | ||
ggtrkpg <- grid.arrange(grobs=ggtrk,ncol=1,top = textGrob(paste("Track:",unique(mt_track_id(trk))))) | ||
} | ||
if(len>5){ | ||
ggtrkpg <- grid.arrange(grobs=ggtrk,ncol=2,top = textGrob(paste("Track:",unique(mt_track_id(trk))))) | ||
} | ||
return(ggtrkpg) | ||
}) | ||
if(len>5){logger.info("Warning! You have selected more than 5 valid attributes to plot. This might lead to very small plots.")} | ||
gp <- marrangeGrob(ggall, nrow = 1, ncol = 1) | ||
ggsave(file=appArtifactPath("MorningReport_attribPlots.pdf"), plot = gp, width = 21, height = 29.7, units = "cm") | ||
} | ||
}else{logger.info("None of the individuals have data in the requested time window. Thus, no pdf artefact is generated.")} | ||
} | ||
|
||
return(data) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"time_now": "2014-08-14T20:51:07Z", | ||
"time_dur": 10, | ||
"attribs": "eobs_activity_samples ,eobs_battery_voltage ,eobs_fix_battery_voltage ,eobs_horizontal_accuracy_estimate" | ||
} |
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,6 +1,7 @@ | ||
{ | ||
"version": "1.2", | ||
"settings": [ | ||
{ | ||
{ | ||
"id": "time_now", | ||
"name": "Reference time", | ||
"description": "Select a reference time towards which your data are evaluated. Default is NOW.", | ||
|
@@ -9,46 +10,32 @@ | |
}, | ||
{ | ||
"id": "time_dur", | ||
"name": "Track time duration.", | ||
"description": "Provide a time duration (in days) of how far in the past you want to plot your track(s).", | ||
"defaultValue": null, | ||
"name": "Track time duration (days).", | ||
"description": "Provide a time duration (in days) of how far in the past you want to plot your track(s). Decimals(with '.') are allowed.", | ||
"defaultValue": 10, | ||
"type": "DOUBLE" | ||
}, | ||
{ | ||
"id": "attribs", | ||
"name": "Data attributes to plot (max. of 5 attributes allowed)", | ||
"description": "Provide the exact names of up to five data attributes that you want to plot (must be comma-separated!). If unsure of attribute names or spelling, please run the first App in your workflow and check the Track Attributes in the Output Details overview. For definitions of Movebank attributes please refer to the Movebank Attribute Dictionary (https://www.movebank.org/cms/movebank-content/movebank-attribute-dictionary).", | ||
"name": "Data attributes to plot", | ||
"description": "Provide the exact names of the data attributes that you want to plot (must be comma-separated!). If unsure of attribute names or spelling, please run the first App in your workflow and check the 'track_attributes' in the 'App Output Details' (green 'i'). For definitions of Movebank attributes please refer to the Movebank Attribute Dictionary (https://www.movebank.org/cms/movebank-content/movebank-attribute-dictionary).", | ||
"defaultValue": null, | ||
"type": "STRING" | ||
} | ||
|
||
], | ||
"dependencies": { | ||
"R": [ | ||
{ | ||
"name": "move" | ||
}, | ||
{ | ||
"name": "foreach" | ||
}, | ||
{ | ||
"name": "sf" | ||
}, | ||
{ | ||
"name": "ggplot2" | ||
}, | ||
{ | ||
"name": "reshape2" | ||
}, | ||
{ | ||
"name": "grid" | ||
}, | ||
{ | ||
"name": "gridExtra" | ||
} | ||
{"name": "move2"}, | ||
{"name": "ggplot2"}, | ||
{"name": "dplyr"}, | ||
{"name": "reshape2"}, | ||
{"name": "gridExtra"}, | ||
{"name": "units"}, | ||
{"name": "scales"}, | ||
{"name": "randomcoloR"}, | ||
{"name": "grid"} | ||
] | ||
}, | ||
"createsArtifacts": true, | ||
"license": { | ||
"key": "MIT" | ||
}, | ||
|
@@ -60,19 +47,26 @@ | |
"attribute", | ||
"plot" | ||
], | ||
"people": [ | ||
"people": [ | ||
{ | ||
"firstName": "Anne", | ||
"middleInitials": "K", | ||
"lastName": "Scharf", | ||
"email": "[email protected]", | ||
"roles": ["author", "creator"], | ||
"orcid": "0000-0002-3357-8533", | ||
"affiliation": "Max-Planck-Institute of Animal Behavior", | ||
"affiliationRor": "https://ror.org/026stee22" | ||
}, | ||
{ | ||
"firstName": "Andrea", | ||
"middleInitials": null, | ||
"lastName": "Kölzsch", | ||
"email": "[email protected]", | ||
"roles": ["author", "creator"], | ||
"roles": ["contributor"], | ||
"orcid": "0000-0003-0193-1563", | ||
"affiliation": "Max-Planck-Institute of Animal Behavior", | ||
"affiliationRor": "https://ror.org/026stee22" | ||
} | ||
], | ||
"documentation" : { | ||
"url": "https://github.com/movestore/MorningRep_AttrPlots/blob/master/README.md" | ||
} | ||
} | ||
] | ||
} |