-
Notifications
You must be signed in to change notification settings - Fork 0
/
predictions_procyon_lotor.jl
181 lines (165 loc) · 7.37 KB
/
predictions_procyon_lotor.jl
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using Distributed
using JLD2
@time @everywhere include("../BioClim/src/required.jl")
cd("/Users/kiristern/Documents/GitHub/SDM")
## Get & prepare data
@time @everywhere begin
# Load data from CSV files
df = CSV.read("/Users/kiristern/Documents/GitHub/SDM/data/pred_prey/Puma_concolor.csv", header=true)
# Prepare data (select columns, arrange values)
df = prepare_gbif_data(pred_prey)
# Separate species
taxa_occ = [df[df.species .== u,:] for u in unique(df.species)]
end
# convert year "string" to "integer"
#df.longitude = parse.(Float64, df.longitude)
# Get the worldclim data by their layer number
cd("/Users/kiristern/Documents/GitHub/BioClim/")
#prediction pred
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[1]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[1]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction1 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction1[taxa_occ[1]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction1.grid)
prediction1.grid[i] < threshold && (prediction1.grid[i] = NaN)
end
#prediction prey1
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[2]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[2]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction2 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction2[taxa_occ[2]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction2.grid)
prediction2.grid[i] < threshold && (prediction2.grid[i] = NaN)
end
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[3]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[3]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction3 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction3[taxa_occ[3]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction3.grid)
prediction3.grid[i] < threshold && (prediction3.grid[i] = NaN)
end
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[4]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[4]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction4 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction4[taxa_occ[4]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction4.grid)
prediction4.grid[i] < threshold && (prediction4.grid[i] = NaN)
end
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[5]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[5]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction5 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction5[taxa_occ[5]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction5.grid)
prediction5.grid[i] < threshold && (prediction5.grid[i] = NaN)
end
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[6]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[6]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction6 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction6[taxa_occ[6]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction6.grid)
prediction6.grid[i] < threshold && (prediction6.grid[i] = NaN)
end
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[7]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[7]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction7 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction7[taxa_occ[7]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction7.grid)
prediction7.grid[i] < threshold && (prediction7.grid[i] = NaN)
end
@info "Extract and crop bioclim variables"
@time wc_vars = [clip(worldclim(i), taxa_occ[8]) for i in 1:19];
# Make the prediction for each layer
@info "Predictions for each layer"
@time predictions = [bioclim(wc_vars[i], taxa_occ[8]) for i in 1:length(wc_vars)];
# Make the final prediction by taking the minimum
@info "Minimum-consensus aggregation"
@time prediction8 = reduce(minimum, predictions);
# Get the threshold for NaN given a percentile
@info "Threshold estimation"
@time threshold = first(quantile(prediction8[taxa_occ[8]], [0.05]))
@info "5% threshold:\t$(round(threshold; digits=3))"
# Filter the predictions based on the threshold
@info "Final prediction filtering"
@time for i in eachindex(prediction8.grid)
prediction8.grid[i] < threshold && (prediction8.grid[i] = NaN)
end
predictions = [prediction1, prediction2, prediction3, prediction4, prediction5, prediction6, prediction7, prediction8]
# ## Get the worldclim data
# @time wc_vars = map(x -> worldclim(x)[lon_range, lat_range], 1:19);
#
# ## Make predictions for all species
# @time predictions = map(x -> species_bclim(x, wc_vars), taxa_occ);
## Export predictions
@save "data/predictions_procyon_lotor.jld2" predictions
# Test import
@load "data/predictions.jld2" predictions