-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenGroupSummaries.R
78 lines (56 loc) · 2.74 KB
/
genGroupSummaries.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
library (dplyr)
library(reshape2)
source("genBirdDensity.R")
generateGroupSummaries <- function(ebd_density, col_filter, numeral_col=11) {
ebd_density <- ebd_density[ebd_density[,col_filter] != "",]
if (nrow(ebd_density) == 0) { return (NULL) }
# First numeral_col columns are metadata and not values.
ebd_density <- cbind (ebd_density["English Name"], ebd_density [numeral_col:ncol(ebd_density)])
colnames(ebd_density)[1] <- c("Species")
return (ebd_density)
}
generateIndicatorSpecies <- function (ebd, range_level_summary=FALSE) {
print(range_level_summary)
if (range_level_summary) {
ebd_density <- generateBirdDensity(ebd)
}
else {
ebd_density <- generateOverallBirdDensity (ebd) [1:ncol(generateOverallBirdDensity(ebd))-1] # Remove SlNo last column
}
ebd_Indicator_Species <- NULL
ebd_Indicator_Species$Indicator <- NULL
l_ebd_Indicator_Species <- generateGroupSummaries(ebd_density, "Raptors")
l_ebd_Indicator_Species$Indicator <- "Raptors"
if(nrow(l_ebd_Indicator_Species) > 0)
ebd_Indicator_Species <- rbind (ebd_Indicator_Species, l_ebd_Indicator_Species)
l_ebd_Indicator_Species <- generateGroupSummaries(ebd_density, "Primary Hole Nesters")
l_ebd_Indicator_Species$Indicator <- "Primary Hole Nesters"
if(nrow(l_ebd_Indicator_Species) > 0)
ebd_Indicator_Species <- rbind (ebd_Indicator_Species, l_ebd_Indicator_Species)
l_ebd_Indicator_Species <- generateGroupSummaries(ebd_density, "Woodland Understorey Birds")
l_ebd_Indicator_Species$Indicator <- "Woodland Understorey Birds"
if(nrow(l_ebd_Indicator_Species) > 0)
ebd_Indicator_Species <- rbind (ebd_Indicator_Species, l_ebd_Indicator_Species)
l_ebd_Indicator_Species <- generateGroupSummaries(ebd_density, "Parasitic Cuckoos")
l_ebd_Indicator_Species$Indicator <- "Parasitic Cuckoos"
ebd_Indicator_Species <- rbind (ebd_Indicator_Species, l_ebd_Indicator_Species)
# Split dataframes per range
chartdatasplit <- split(ebd_Indicator_Species[1:ncol(ebd_Indicator_Species)-1], ebd_Indicator_Species$Indicator, drop=FALSE)
return (chartdatasplit)
}
# Test Code
testHarness_generateEndemicDensity <- function () {
unzip('..\\data\\ebird_1489816770850.zip')
ebd <- read.csv('MyEBirdData.csv', header = TRUE, sep = ",")
species <- read.csv('Species.csv', header = TRUE, sep = ",")
# Obtain details of birds by joining with species file
ebd <- left_join (ebd, species, by = 'Scientific.Name')
ebd$RANGE <- 'Vazhachal'
ebd$RANGE [100:500] <- 'Sholayar'
output <- generateIndicatorSpecies (ebd, TRUE)
write.csv(output$Raptors, 'testout.csv')
output <- generateIndicatorSpecies (ebd, FALSE)
write.csv(output$Raptors, 'testout.csv')
print (nrow(output))
}
#testHarness_generateEndemicDensity()