-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cluster Size distributions.R
79 lines (63 loc) · 3 KB
/
Cluster Size distributions.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
76
77
78
79
library(raster)
library(spatialwarnings)
library(poweRlaw)
library(ggplot2)
################ Spatialwarnings ################
## Select the raster
setwd("A:/Work")
r <- raster('Threshold/Sn12_NDVI_N.tif') # Selecting a Raster File
s <- as.matrix(r) # Converting the raster into a matrix
dups<-s # Making it binary such that
s[dups<=0.68]<-1 # any value above a threshold is 1
s[dups>0.68]<-0 # and below is zero
t<-matrix(as.logical(s), dim(s)) # Converting the binary matrix to a logical matrix
cs<-patchsizes(t, nbmask = "moore") # To produce a list of cluster sizes , use 'nbmask="moore"' to specify use of moore neighbourhood to define cluster
c_xmin<-xmin_estim(cs) # Estimate Xmin
c_xmin
##summary(c_xmin)
## Produce a inverse-cdf of cluster size
cdist<- patchdistr_sews(t,xmin=c_xmin, fit_lnorm=TRUE, nbmask = "moore") ##Merge=TRUE uses all possible fits
## Plot the function
cdistplot<- plot_distr(cdist, best_only = FALSE)
svg(filename = "PLD/Moore/Individual/Sn/Sn12_NDVI_sw.svg", width = 950, height = 950, units = "px", pointsize = 55, res = 125)
cdistplot
dev.off()
################ poweRlaw ################
## Use the list of cluster sizes to produce a cluster size distribution
cd=conpl$new(cs)
## Estimate parameters of distribution
par_cd<-estimate_pars(cd)
xmin_cd<-estimate_xmin(cd, xmax = max(cs))
cd$setXmin(xmin_cd)
xmin_cd
## Plot the distribution
x.name=c("Patchsize")
y.name=c("P(X<x)")
svg(filename = "PLD/Moore/Individual/Sn/Sn12_NDVI_sw.svg", width = 950, height = 950, units = "px", pointsize = 15, res = 125)
plotcd<-plot(cd, xlim=c(1,1000000), ylim=c(0.000001,1),main="Ts12", xlab=x.name, ylab=y.name)
lnpl<-lines(cd,col=3)
legend("topright", legend=c("PlXmin = 1296", "PlExpo = 3.54"), cex=1)
dev.off()
################ Von neumann ################
## Same as above, but did not specify the moore function, to produce cluster size distribution using Von Neumann neighbourhood
t<-matrix(as.logical(s), dim(s))
cs<-patchsizes(t)
c_xmin<-xmin_estim(cs)
c_xmin
cdist<- patchdistr_sews(t,xmin=c_xmin, fit_lnorm=TRUE, nbmask = "moore") ##Merge=TRUE uses all possible fits
cdistplot<- plot_distr(cdist, best_only = FALSE)
svg(filename = "PLD/VonNeumann/Individual/Sn/Sn12_NDVI_sw.svg", width = 950, height = 950, units = "px", pointsize = 15, res = 125)
cdistplot
dev.off()
cd=conpl$new(cs)
par_cd<-estimate_pars(cd)
xmin_cd<-estimate_xmin(cd, xmax = max(cs))
cd$setXmin(xmin_cd)
xmin_cd
x.name=c("Patchsize")
y.name=c("P(X<x)")
svg(filename = "PLD/VonNeumann/Individual/Sn/Sn12_NDVI_.svg", width = 950, height = 950, units = "px", pointsize = 15, quality = 125)
plotcd<-plot(cd, xlim=c(1,1000000), ylim=c(0.000001,1),main="Ts12", xlab=x.name, ylab=y.name)
lnpl<-lines(cd,col=3)
legend("topright", legend=c("PlXmin = 880", "PlExpo = 4.89"), cex=1)
dev.off()