Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This function downloads the studies you provide in a list:
- # library('skimr')
- library('tidyverse')
- library(ggmap)
- library(move)
- library(ggplot2)
- loginStored <- movebankLogin(username = "Diego_Ellis", password = "")
- login = loginStored
- getMovebank("tag_type", loginStored)
- # Show me all studies
- # all_studies <- getMovebank(entity_type = "study", login=loginStored)
- # Look at MPIO studies:
- MPIO_studies = searchMovebankStudies(x="MPIO", login=loginStored)
- # For eobs function need to find out who the PIs are
- # Martin -> Can I ask Movebnak folks to run a query -> All studies with eobs tags of MPIO
- # Ask for access for these to Martin:
- eobs_studies = searchMovebankStudies(x="eobs", login=loginStored)
- e_obs_studies = searchMovebankStudies(x="e-obs", login=loginStored)
- e_Obs_studies = searchMovebankStudies(x="e-Obs", login=loginStored)
- extra_studies <- c('High-altitude flights of Himalayan vultures (data from Sherub et al. 2016)',
- 'Corvus splendens Translocation BHUTAN', 'Livestock Movement in Bhutan', 'Steppe Eagle Bhutan',
- 'Takin Sangay Bhutan', 'Tragopans in Bhutan')
- studies_to_check <- c(MPIO_studies, eobs_studies, e_Obs_studies, extra_studies)
- # Is there a way to see what studies have e-obs temperature as a column? Or to see privacy
- # studies_to_check <- studies_to_check[1:3]
- ind_studies_with_eobs_temperature <- function(login, studylist, plot_this_data = NULL){
- # Check which of the MPIO studies has e-obs data:
- df_out <- data.frame(matrix(NA, length(studylist), 9))
- names(df_out) <- c('study_name', 'has_eobs_temperature',
- 'private_data', 'number_of_fixes', 'has_acc', "movebank_id",
- "license_terms", "main_location_long", "main_location_lat")
- all_studies <- getMovebank(entity_type = "study", login=loginStored)
- # as.data.frame(t(sapply(studylist, function(x){
- for(x in 1:length(unique(studylist))){
- # x <- studylist[1]
- # x <- studylist[10]
- x <- studylist[x]
- studyID <- x
- # study_index_id <- which(studyID %in% studylist)
- study_index_id <- which(studylist %in% studyID)
- print(study_index_id)
- df_out[study_index_id,]$study_name <- studylist[study_index_id]
- ## get GPS and accelerometer data within a time period
- ## create a vector with attributes for all sensors included in the study
- attrib <- unique(c(as.character(getMovebankSensorsAttributes(studyID,
- login=loginStored)$short_name),
- 'sensor_type_id', 'deployment_id', 'event_id',
- 'individual_id', 'tag_id'))
- # indID <- getMovebank("individual", login=login, study_id=studyID)$id[50]
- # ## get a summary of information about the two studies
- # getMovebank("study", login=login, study_id=c(studyID,studyID2))
- # Check e-obs temp
- if(length(grep("eobs_temperature", attrib)) > 0){
- df_out[study_index_id,]$has_eobs_temperature <- 1
- print(paste0('study ', studyID, ' has e-obs temperature'))
- }else{
- df_out[study_index_id,]$has_eobs_temperature <- 0
- print(paste0('study ', studyID, ' has no e-obs temperature'))
- }
- # Check if has ACC
- if( any(getMovebankSensorsAttributes(study=studyID,login=loginStored)$sensor_type_id == "2365683") ){
- print(paste0('study ', studyID, ' has accelerometers'))
- df_out[study_index_id,]$has_acc <- 1
- }else{
- print(paste0('study ', studyID, ' has no accelerometers'))
- df_out[study_index_id,]$has_acc <- 0
- }
- # Data privacy:
- if( length(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]) > 0 ){
- df_out[study_index_id,]$private_data <- as.character(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]$there_are_data_which_i_cannot_see)
- }else{df_out[study_index_id,]$private_data <- NA}
- ## return(df_out)
- # Get the Movebank ID
- if( length(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]) > 0 ){
- df_out[study_index_id,]$movebank_id <- as.numeric(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]$id)
- }else{df_out[study_index_id,]$movebank_id <- NA}
- # main_location_long
- if( length(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]) > 0 ){
- df_out[study_index_id,]$main_location_long <- as.numeric(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]$main_location_long)
- }else{df_out[study_index_id,]$main_location_long <- NA}
- # main_location_lat
- if( length(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]) > 0 ){
- df_out[study_index_id,]$main_location_lat <- as.numeric(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]$main_location_lat)
- }else{df_out[study_index_id,]$main_location_lat <- NA}
- # license_terms
- if( length(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]) > 0 ){
- df_out[study_index_id,]$license_terms <- as.character(all_studies[all_studies$name %in% df_out[study_index_id,]$study_name,]$license_terms)
- }else{df_out[study_index_id,]$license_terms <- NA}
- # return(df_out)
- # Check permission status
- } # End of for loop
- rownames(df_out) <- NULL
- if(!is.null(plot_this_data)){
- # Subset all studies by the ones I found that have e-obs temperature:
- all_studies_I_want <- all_studies[all_studies$name %in% df_out[df_out$has_eobs_temperature == 1,]$study_name,]
- world <- map_data("world")
- # Blue means there are private data and restricitons.
- print( ggplot() +
- geom_polygon(data = world,
- fill = "grey38",
- aes(x = long, y = lat, group = group)) +
- geom_point(data = all_studies_I_want,
- aes(x = main_location_long, y = main_location_lat, color = as.factor(there_are_data_which_i_cannot_see))) +
- scale_color_discrete(guide = guide_legend(title = "Data Restrictions"))
- )
- }
- print(paste0('A total of ', sum(df_out[df_out$has_eobs_temperature == 1,]$has_eobs_temperature, na.rm = TRUE), ' out of ', nrow(df_out), ' studies has e-obs temperature data'))
- return(df_out)
- # Sarah: Ask them to do a query:
- # ))) # End of sapply
- } # End of function
- # ind_studies_with_eobs_temperature(login = login, studylist = MPIO_studies)
- study_info <- ind_studies_with_eobs_temperature(login = login, studylist = studies_to_check, plot_this_data = TRUE)
- # Function:
- # Things to add: Need permision!!!
- ## get deployments reference information from the study
- #getMovebank(entity_type='deployment' , login= login,studyID = studyID )
- ## get a summary of information about the two studies
- #getMovebank(entity_type="study", login=login, study_id=studyID)
- ## get animal reference information from the study
- # head(getMovebank("individual", login=login, study_id=studyID))
- all_studies <- getMovebank(entity_type = "study", login=loginStored)
- # Subset all studies by the ones I found that have e-obs temperature:
- all_studies_I_want <- all_studies[all_studies$name %in% study_info[study_info$has_eobs_temperature == 1,]$study_name,]
- write.csv(all_studies_I_want, file = '/Users/diegoellis/Dropbox/Wikelski_Temperature/all_studies_I_want.csv')
- # Use recursive? -> microhabitats?
- # Get temperature, extract SRTM, get elevation above ellipsoid, get wind direction
- #
- # Extract from this guy: 'High-altitude flights of Himalayan vultures (data from Sherub et al. 2016)'
- # Elephants Java FZG MPIO DAMN
- # e-Obs GPRS Himalayan Griffon, Sherub, Bhutan
Add Comment
Please, Sign In to add comment