Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Feret Jean-Baptiste
biodivMapR
Commits
647bed48
Commit
647bed48
authored
Nov 07, 2019
by
Feret Jean-Baptiste
Browse files
fixed the vignette for tutorial
parent
729ad162
Changes
2
Hide whitespace changes
Inline
Side-by-side
R/Lib_ImageProcess.R
View file @
647bed48
...
...
@@ -291,15 +291,17 @@ extract_samples_from_image <- function(ImPath, coordPix, MaxRAM = FALSE, Already
HDR
<-
read_ENVI_header
(
ImPathHDR
)
# compute the ranking of initial pixel list compared to index ranking
if
(
typeof
(
coordPix
)
==
"double"
&
dim
(
coordPix
)[
2
]
==
2
)
{
if
(
dim
(
coordPix
)[
1
]
>=
2
)
{
coordPix_tmp
<-
list
()
coordPix_tmp
$
Row
<-
coordPix
[,
1
]
coordPix_tmp
$
Column
<-
coordPix
[,
2
]
}
else
if
(
dim
(
coordPix
)[
1
]
==
1
)
{
coordPix_tmp
<-
list
()
coordPix_tmp
$
Row
<-
coordPix
[
1
]
coordPix_tmp
$
Column
<-
coordPix
[
2
]
if
(
typeof
(
coordPix
)
==
"double"
){
if
(
dim
(
coordPix
)[
2
]
==
2
)
{
if
(
dim
(
coordPix
)[
1
]
>=
2
)
{
coordPix_tmp
<-
list
()
coordPix_tmp
$
Row
<-
coordPix
[,
1
]
coordPix_tmp
$
Column
<-
coordPix
[,
2
]
}
else
if
(
dim
(
coordPix
)[
1
]
==
1
)
{
coordPix_tmp
<-
list
()
coordPix_tmp
$
Row
<-
coordPix
[
1
]
coordPix_tmp
$
Column
<-
coordPix
[
2
]
}
}
}
else
if
(
typeof
(
coordPix
)
==
"list"
&
length
(
grep
(
"Row"
,
names
(
coordPix
)))
>
0
&
length
(
grep
(
"Column"
,
names
(
coordPix
)))
>
0
)
{
coordPix_tmp
<-
coordPix
...
...
vignettes/biodivMapR.Rmd
View file @
647bed48
...
...
@@ -56,12 +56,13 @@ The output directory defined with `Output_Dir` will contain all the results. For
```{r Input / Output files}
library(biodivMapR)
Input_Image_File = system.file('extdata', 'RASTER', 'S2A_T33NUD_20180104_Subset', package = 'biodivMapR')
# Input
.
Image
.
File = raster2BIL(Raster
.
Path = Input
.
Image
.
File,
# Input
_
Image
_
File = raster2BIL(Raster
_
Path = Input
_
Image
_
File,
# Sensor = 'SENTINEL_2A',
# Convert
.
Integer = TRUE,
# Output
.
Dir
ectory
= '~/test')
# Convert
_
Integer = TRUE,
# Output
_
Dir = '~/test')
Input_Mask_File = FALSE
...
...
@@ -90,7 +91,7 @@ Set FilterPCA to `TRUE` if a second filtering based on PCA outliers is required.
```{r PCA method and filtering}
TypePCA = 'SPCA'
FilterPCA =
FALS
E
FilterPCA =
TRU
E
```
## Computing options
...
...
@@ -149,7 +150,7 @@ Here is the code to perform PCA and select PCA bands:
```{r PCA}
print("PERFORM PCA ON RASTER")
PCA_Output = perform_PCA(Input_Image_File, Input_Mask_File, Output_Dir,
TypePCA = TypePCA, FilterPCA =
TRUE
, nbCPU = nbCPU,MaxRAM = MaxRAM)
TypePCA = TypePCA, FilterPCA =
FilterPCA
, nbCPU = nbCPU,MaxRAM = MaxRAM)
# path for the PCA raster
PCA_Files = PCA_Output$PCA_Files
# number of pixels used for each partition used for k-means clustering
...
...
@@ -217,23 +218,23 @@ The following code computes $\alpha$ and $\beta$ diversity from field plots and
```{r alpha and beta diversity indices from vector layer}
# location of the spectral species raster needed for validation
Dir
.
Raster = file.path(Output
.
Dir,basename(Input
.
Image
.
File),TypePCA,'SpectralSpecies')
Name
.
Raster = 'SpectralSpecies'
Path
.
Raster = file.path(Dir
.
Raster,Name
.
Raster)
Dir
_
Raster = file.path(Output
_
Dir,basename(Input
_
Image
_
File),TypePCA,'SpectralSpecies')
Name
_
Raster = 'SpectralSpecies'
Path
_
Raster = file.path(Dir
_
Raster,Name
_
Raster)
# location of the directory where shapefiles used for validation are saved
vect = system.file('extdata', 'VECTOR', package = 'biodivMapR')
Shannon.All = list() # ??
# list vector data
Path
.
Vector = list_shp(vect)
Name
.
Vector = tools::file_path_sans_ext(basename(Path
.
Vector))
Path
_
Vector = list_shp(vect)
Name
_
Vector = tools::file_path_sans_ext(basename(Path
_
Vector))
# get alpha and beta diversity indicators corresponding to shapefiles
Biodiv
.
Indicators = diversity_from_plots(Raster = Path
.
Raster, Plots = Path
.
Vector,NbClusters = nbclusters)
Biodiv
_
Indicators = diversity_from_plots(Raster = Path
_
Raster, Plots = Path
_
Vector,NbClusters = nbclusters)
# if no name
Biodiv
.
Indicators$Name
.
Plot = seq(1,length(Biodiv
.
Indicators$Shannon[[1]]),by = 1)
Shannon
.
RS = c(Biodiv
.
Indicators$Shannon)[[1]]
Biodiv
_
Indicators$Name
_
Plot = seq(1,length(Biodiv
_
Indicators$Shannon[[1]]),by = 1)
Shannon
_
RS = c(Biodiv
_
Indicators$Shannon)[[1]]
```
The tables are then written to tab-seperated files.
...
...
@@ -242,20 +243,20 @@ The tables are then written to tab-seperated files.
# write RS indicators
####################################################
# write indicators for alpha diversity
Path
.
Results = file.path(Output
.
Dir, basename(Input
.
Image
.
File), TypePCA, 'VALIDATION')
dir.create(Path
.
Results, showWarnings = FALSE, recursive = TRUE)
ShannonIndexFile <- file.path(Path
.
Results, "ShannonIndex.tab")
write.table(Shannon
.
RS, file = ShannonIndexFile, sep = "\t", dec = ".", na = " ",
row.names = Biodiv
.
Indicators$Name
.
Plot, col.names= F, quote=FALSE)
Path
_
Results = file.path(Output
_
Dir, basename(Input
_
Image
_
File), TypePCA, 'VALIDATION')
dir.create(Path
_
Results, showWarnings = FALSE, recursive = TRUE)
ShannonIndexFile <- file.path(Path
_
Results, "ShannonIndex.tab")
write.table(Shannon
_
RS, file = ShannonIndexFile, sep = "\t", dec = ".", na = " ",
row.names = Biodiv
_
Indicators$Name
_
Plot, col.names= F, quote=FALSE)
Results = data.frame(Name
.
Vector, Biodiv
.
Indicators$Richness, Biodiv
.
Indicators$Fisher, Biodiv
.
Indicators$Shannon, Biodiv
.
Indicators$Simpson)
Results = data.frame(Name
_
Vector, Biodiv
_
Indicators$Richness, Biodiv
_
Indicators$Fisher, Biodiv
_
Indicators$Shannon, Biodiv
_
Indicators$Simpson)
names(Results) = c("ID_Plot", "Species_Richness", "Fisher", "Shannon", "Simpson")
write.table(Results, file =
paste
(Path
.
Results,"AlphaDiversity.tab"
,sep=''
), sep="\t", dec=".",
na=" ", row.names = F, col.names= T,quote=FALSE)
write.table(Results, file =
file.path
(Path
_
Results,"AlphaDiversity.tab"), sep="\t", dec=".",na=" ", row.names = F, col.names= T,quote=FALSE)
# write indicators for beta diversity
BC_mean = Biodiv
.
Indicators$BCdiss
colnames(BC_mean) = rownames(BC_mean) = Biodiv
.
Indicators$Name
.
Plot
write.table(BC_mean, file =
paste
(Path
.
Results,"BrayCurtis.csv"
,sep=''
), sep="\t", dec=".", na=" ", row.names = F, col.names= T,quote=FALSE)
BC_mean = Biodiv
_
Indicators$BCdiss
colnames(BC_mean) = rownames(BC_mean) = Biodiv
_
Indicators$Name
_
Plot
write.table(BC_mean, file =
file.path
(Path
_
Results,"BrayCurtis.csv"), sep="\t", dec=".", na=" ", row.names = F, col.names= T,quote=FALSE)
```
...
...
@@ -289,13 +290,13 @@ for (i in 1: length(nbSamples)){
# create data frame including alpha and beta diversity
library(ggplot2)
Results = data.frame('vgtype'=Type_Vegetation,'pco1'= BetaPCO$points[,1],'pco2'= BetaPCO$points[,2],'pco3' = BetaPCO$points[,3],'shannon'=Shannon
.
RS)
Results = data.frame('vgtype'=Type_Vegetation,'pco1'= BetaPCO$points[,1],'pco2'= BetaPCO$points[,2],'pco3' = BetaPCO$points[,3],'shannon'=Shannon
_
RS)
# plot field data in the PCoA space, with size corresponding to shannon index
ggplot(Results, aes(x=pco1, y=pco2, color=vgtype,size=shannon)) +
geom_point(alpha=0.6) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path
.
Results,'BetaDiversity_PcoA1_vs_PcoA2.png')
filename = file.path(Path
_
Results,'BetaDiversity_PcoA1_vs_PcoA2.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
...
...
@@ -304,7 +305,7 @@ ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
ggplot(Results, aes(x=pco1, y=pco3, color=vgtype,size=shannon)) +
geom_point(alpha=0.6) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path
.
Results,'BetaDiversity_PcoA1_vs_PcoA3.png')
filename = file.path(Path
_
Results,'BetaDiversity_PcoA1_vs_PcoA3.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
...
...
@@ -312,7 +313,7 @@ ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
ggplot(Results, aes(x=pco2, y=pco3, color=vgtype,size=shannon)) +
geom_point(alpha=0.6) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path
.
Results,'BetaDiversity_PcoA2_vs_PcoA3.png')
filename = file.path(Path
_
Results,'BetaDiversity_PcoA2_vs_PcoA3.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment