Commit c9600350 authored by jbferet's avatar jbferet
Browse files

final corrections (replacements dots with underscores...)

parent cd8f86c3
......@@ -534,7 +534,7 @@ mean_filter <- function(ImageInit, nbi, nbj, SizeFilt) {
# reads a subset from a binary image
#
# @param Byte.Start location of byte where to start reading in the image
# @param Byte_Start location of byte where to start reading in the image
# @param nbLines number of lines to read
# @param lenBin number of elements to read
# @param ImPath path for the image
......@@ -544,7 +544,7 @@ mean_filter <- function(ImageInit, nbi, nbj, SizeFilt) {
# @param Image_Format type of data (INT/FLOAT)
#
# @return data corresponding to the subset in original 3D format
read_bin_subset <- function(Byte.Start, nbLines, lenBin, ImPath, ImBand, jpix, nbChannels, Image_Format) {
read_bin_subset <- function(Byte_Start, nbLines, lenBin, ImPath, ImBand, jpix, nbChannels, Image_Format) {
# number of bands to be kept
nbSubset <- length(ImBand)
# open file
......@@ -552,9 +552,9 @@ read_bin_subset <- function(Byte.Start, nbLines, lenBin, ImPath, ImBand, jpix, n
description = ImPath, open = "rb", blocking = TRUE,
encoding = getOption("encoding"), raw = FALSE
)
if (!Byte.Start == 1) {
if (!Byte_Start == 1) {
# skip the beginning of the file of not wanted
seek(fid, where = as.double(Image_Format$Bytes * (Byte.Start - 1)), origin = "start", rw = "read")
seek(fid, where = as.double(Image_Format$Bytes * (Byte_Start - 1)), origin = "start", rw = "read")
}
if (Image_Format$Type == "INT") {
linetmp <- readBin(fid, integer(), n = lenBin, size = Image_Format$Bytes, endian = Image_Format$ByteOrder)
......@@ -666,10 +666,10 @@ read_image_bands <- function(ImPath, Header, ImBand) {
Image_Subsets <- list()
for (i in 1:nbPieces) {
# number of elements to be read
Byte.Start <- SeqRead.Image$ReadByte_Start[i]
nbLines <- SeqRead.Image$Lines.Per.Chunk[i]
Byte_Start <- SeqRead.Image$ReadByte_Start[i]
nbLines <- SeqRead.Image$Lines_Per_Chunk[i]
lenBin <- SeqRead.Image$ReadByte_End[i] - SeqRead.Image$ReadByte_Start[i] + 1
Image_Subsets[[i]] <- read_bin_subset(Byte.Start, nbLines, lenBin, ImPath, ImBand, jpix, nbChannels, Image_Format)
Image_Subsets[[i]] <- read_bin_subset(Byte_Start, nbLines, lenBin, ImPath, ImBand, jpix, nbChannels, Image_Format)
}
# reshape image with original size and selected bands
Image.Subset <- build_image_from_list(Image_Subsets, ipix, jpix, nbSubset)
......@@ -682,23 +682,23 @@ read_image_bands <- function(ImPath, Header, ImBand) {
#
# @param ImPath path for the image
# @param HDR header information corresponding to the image
# @param Byte.Start location of byte where to start reading in the image
# @param Byte_Start location of byte where to start reading in the image
# @param lenBin number of elements to read
# @param nbLines number of lines to read
# @param Image_Format type of data (INT/FLOAT)
# @param ImgFormat should output be 2D or 3D (original image format)?
#
# @return data corresponding to the subset in original 3D format
read_image_subset <- function(ImPath, HDR, Byte.Start, lenBin, nbLines, Image_Format, ImgFormat) {
read_image_subset <- function(ImPath, HDR, Byte_Start, lenBin, nbLines, Image_Format, ImgFormat) {
fidIm <- file(
description = ImPath, open = "rb", blocking = TRUE,
encoding = getOption("encoding"), raw = FALSE
)
# read relevant portion
if (!Byte.Start == 1) {
if (!Byte_Start == 1) {
# skip the beginning of the file of not wanted
seek(fidIm, where = Image_Format$Bytes * (Byte.Start - 1), origin = "start", rw = "read")
seek(fidIm, where = Image_Format$Bytes * (Byte_Start - 1), origin = "start", rw = "read")
}
if (Image_Format$Type == "INT") {
if (HDR$`data type` == 1) {
......@@ -854,14 +854,14 @@ where_to_read <- function(HDR, nbPieces) {
Data.Per.Line <- as.double(HDR$samples) * as.double(HDR$bands)
lenTot <- as.double(HDR$lines) * Data.Per.Line
# starting line for each chunk
Start.Per.Chunk <- ceiling(seq(1, (HDR$lines + 1), length.out = nbPieces + 1))
Start_Per_Chunk <- ceiling(seq(1, (HDR$lines + 1), length.out = nbPieces + 1))
# elements in input data
lb <- 1 + ((Start.Per.Chunk - 1) * Data.Per.Line)
lb <- 1 + ((Start_Per_Chunk - 1) * Data.Per.Line)
ub <- lb - 1
ReadByte_Start <- lb[1:nbPieces]
ReadByte_End <- ub[2:(nbPieces + 1)]
Lines.Per.Chunk <- diff(Start.Per.Chunk)
my_list <- list("ReadByte_Start" = ReadByte_Start, "ReadByte_End" = ReadByte_End, "Lines.Per.Chunk" = Lines.Per.Chunk)
Lines_Per_Chunk <- diff(Start_Per_Chunk)
my_list <- list("ReadByte_Start" = ReadByte_Start, "ReadByte_End" = ReadByte_End, "Lines_Per_Chunk" = Lines_Per_Chunk)
return(my_list)
}
......@@ -874,15 +874,15 @@ where_to_read_kernel <- function(HDR, nbPieces, SE.Size) {
Data.Per.Line <- as.double(HDR$samples) * as.double(HDR$bands)
lenTot <- as.double(HDR$lines) * Data.Per.Line
# starting line for each chunk
Start.Per.Chunk <- ceiling(seq(1, (HDR$lines + 1), length.out = nbPieces + 1))
Start.Per.Chunk <- Start.Per.Chunk - Start.Per.Chunk %% SE.Size + 1
Start_Per_Chunk <- ceiling(seq(1, (HDR$lines + 1), length.out = nbPieces + 1))
Start_Per_Chunk <- Start_Per_Chunk - Start_Per_Chunk %% SE.Size + 1
# elements in input data
lb <- 1 + ((Start.Per.Chunk - 1) * Data.Per.Line)
lb <- 1 + ((Start_Per_Chunk - 1) * Data.Per.Line)
ub <- lb - 1
ReadByte_Start <- lb[1:nbPieces]
ReadByte_End <- ub[2:(nbPieces + 1)]
Lines.Per.Chunk <- diff(Start.Per.Chunk)
my_list <- list("ReadByte_Start" = ReadByte_Start, "ReadByte_End" = ReadByte_End, "Lines.Per.Chunk" = Lines.Per.Chunk)
Lines_Per_Chunk <- diff(Start_Per_Chunk)
my_list <- list("ReadByte_Start" = ReadByte_Start, "ReadByte_End" = ReadByte_End, "Lines_Per_Chunk" = Lines_Per_Chunk)
return(my_list)
}
......@@ -899,19 +899,19 @@ where_to_write_kernel <- function(HDR_SS, HDR_SSD, nbPieces, SE.Size) {
Data.Per.Line_SSD <- as.double(HDR_SSD$samples) * as.double(HDR_SSD$bands)
# starting line for each chunk of spectral species
Start.Per.Chunk <- ceiling(seq(1, (HDR_SS$lines + 1), length.out = nbPieces + 1))
Start.Per.Chunk <- Start.Per.Chunk - Start.Per.Chunk %% SE.Size
Start.Per.Chunk.SSD <- (Start.Per.Chunk / SE.Size) + 1
Start_Per_Chunk <- ceiling(seq(1, (HDR_SS$lines + 1), length.out = nbPieces + 1))
Start_Per_Chunk <- Start_Per_Chunk - Start_Per_Chunk %% SE.Size
Start_Per_Chunk.SSD <- (Start_Per_Chunk / SE.Size) + 1
# elements in input data
Image_Format <- ENVI_type2bytes(HDR_SSD)
lb_SSD <- 1 + (((Start.Per.Chunk.SSD - 1) * Data.Per.Line_SSD) * Image_Format$Bytes)
lb_SSD <- 1 + (((Start_Per_Chunk.SSD - 1) * Data.Per.Line_SSD) * Image_Format$Bytes)
ub_SSD <- lb_SSD - 1
ReadByte_Start.SSD <- lb_SSD[1:nbPieces]
ReadByte_End.SSD <- ub_SSD[2:(nbPieces + 1)]
Lines.Per.Chunk.SSD <- diff(Start.Per.Chunk.SSD)
Lines_Per_Chunk.SSD <- diff(Start_Per_Chunk.SSD)
my_list <- list("ReadByte_Start" = ReadByte_Start.SSD, "ReadByte_End" = ReadByte_End.SSD, "Lines.Per.Chunk" = Lines.Per.Chunk.SSD)
my_list <- list("ReadByte_Start" = ReadByte_Start.SSD, "ReadByte_End" = ReadByte_End.SSD, "Lines_Per_Chunk" = Lines_Per_Chunk.SSD)
return(my_list)
}
......
......@@ -157,17 +157,17 @@ compute_alpha_metrics <- function(Spectral_Species_Path, window_size, nbclusters
for (i in 1:nbPieces_Min) {
ReadWrite[[i]] <- list()
ReadWrite[[i]]$RW.SS <- ReadWrite[[i]]$RW.SSD <- ReadWrite[[i]]$RW.Sunlit <- list()
ReadWrite[[i]]$RW.SS$Byte.Start <- SeqRead.SS$ReadByte.Start[i]
ReadWrite[[i]]$RW.SS$nbLines <- SeqRead.SS$Lines.Per.Chunk[i]
ReadWrite[[i]]$RW.SS$lenBin <- SeqRead.SS$ReadByte.End[i] - SeqRead.SS$ReadByte.Start[i] + 1
ReadWrite[[i]]$RW.SS$Byte_Start <- SeqRead.SS$ReadByte_Start[i]
ReadWrite[[i]]$RW.SS$nbLines <- SeqRead.SS$Lines_Per_Chunk[i]
ReadWrite[[i]]$RW.SS$lenBin <- SeqRead.SS$ReadByte_End[i] - SeqRead.SS$ReadByte_Start[i] + 1
ReadWrite[[i]]$RW.SSD$Byte.Start <- SeqWrite.SSD$ReadByte.Start[i]
ReadWrite[[i]]$RW.SSD$nbLines <- SeqWrite.SSD$Lines.Per.Chunk[i]
ReadWrite[[i]]$RW.SSD$lenBin <- SeqWrite.SSD$ReadByte.End[i] - SeqWrite.SSD$ReadByte.Start[i] + 1
ReadWrite[[i]]$RW.SSD$Byte_Start <- SeqWrite.SSD$ReadByte_Start[i]
ReadWrite[[i]]$RW.SSD$nbLines <- SeqWrite.SSD$Lines_Per_Chunk[i]
ReadWrite[[i]]$RW.SSD$lenBin <- SeqWrite.SSD$ReadByte_End[i] - SeqWrite.SSD$ReadByte_Start[i] + 1
ReadWrite[[i]]$RW.Sunlit$Byte.Start <- SeqWrite.Sunlit$ReadByte.Start[i]
ReadWrite[[i]]$RW.Sunlit$nbLines <- SeqWrite.Sunlit$Lines.Per.Chunk[i]
ReadWrite[[i]]$RW.Sunlit$lenBin <- SeqWrite.Sunlit$ReadByte.End[i] - SeqWrite.Sunlit$ReadByte.Start[i] + 1
ReadWrite[[i]]$RW.Sunlit$Byte_Start <- SeqWrite.Sunlit$ReadByte_Start[i]
ReadWrite[[i]]$RW.Sunlit$nbLines <- SeqWrite.Sunlit$Lines_Per_Chunk[i]
ReadWrite[[i]]$RW.Sunlit$lenBin <- SeqWrite.Sunlit$ReadByte_End[i] - SeqWrite.Sunlit$ReadByte_Start[i] + 1
}
ImgFormat <- "3D"
SSD_Format <- ENVI_type2bytes(HDR_SSD)
......@@ -235,7 +235,7 @@ convert_PCA_to_SSD <- function(ReadWrite, Spectral_Species_Path, HDR_SS, HDR_SSD
MinSun, pcelim, Index_Alpha, SSD_Path, Sunlit_Path, Sunlit_Format) {
SS_Chunk <- read_image_subset(
Spectral_Species_Path, HDR_SS,
ReadWrite$RW.SS$Byte.Start, ReadWrite$RW.SS$lenBin,
ReadWrite$RW.SS$Byte_Start, ReadWrite$RW.SS$lenBin,
ReadWrite$RW.SS$nbLines, SS_Format, ImgFormat
)
SSD_Alpha <- compute_SSD(SS_Chunk, window_size, nbclusters, MinSun, pcelim, Index_Alpha = Index_Alpha)
......@@ -244,8 +244,8 @@ convert_PCA_to_SSD <- function(ReadWrite, Spectral_Species_Path, HDR_SS, HDR_SSD
description = SSD_Path, open = "r+b", blocking = TRUE,
encoding = getOption("encoding"), raw = FALSE
)
if (!ReadWrite$RW.SSD$Byte.Start == 1) {
seek(fidSSD, where = ReadWrite$RW.SSD$Byte.Start - 1, origin = "start", rw = "write")
if (!ReadWrite$RW.SSD$Byte_Start == 1) {
seek(fidSSD, where = ReadWrite$RW.SSD$Byte_Start - 1, origin = "start", rw = "write")
}
SSD_Chunk <- aperm(array(SSD_Alpha$SSD, c(ReadWrite$RW.SSD$nbLines, HDR_SSD$samples, HDR_SSD$bands)), c(2, 3, 1))
writeBin(c(SSD_Chunk), fidSSD, size = SSD_Format$Bytes, endian = .Platform$endian, useBytes = FALSE)
......@@ -256,8 +256,8 @@ convert_PCA_to_SSD <- function(ReadWrite, Spectral_Species_Path, HDR_SS, HDR_SSD
description = Sunlit_Path, open = "r+b", blocking = TRUE,
encoding = getOption("encoding"), raw = FALSE
)
if (!ReadWrite$RW.Sunlit$Byte.Start == 1) {
seek(fidSunlit, where = ReadWrite$RW.Sunlit$Byte.Start - 1, origin = "start", rw = "write")
if (!ReadWrite$RW.Sunlit$Byte_Start == 1) {
seek(fidSunlit, where = ReadWrite$RW.Sunlit$Byte_Start - 1, origin = "start", rw = "write")
}
Sunlit.Chunk <- t(SSD_Alpha$PCsun)
writeBin(c(Sunlit.Chunk), fidSunlit, size = Sunlit_Format$Bytes, endian = .Platform$endian, useBytes = FALSE)
......
......@@ -49,7 +49,7 @@ map_spectral_species <- function(Input_Image_File, Output_Dir, PCA_Files,ImPathS
PC_Select_Path <- paste(Output_Dir_PCA, "Selected_Components.txt", sep = "")
if (file.exists(PC_Select_Path)) {
PC_Select <- read.table(PC_Select_Path)[[1]]
dataPCA <- PCA.model$dataPCA[, PC_Select]
dataPCA <- PCA_model$dataPCA[, PC_Select]
if (length(PC_Select) == 1) {
dataPCA <- matrix(dataPCA, ncol = 1)
}
......@@ -156,7 +156,7 @@ apply_kmeans <- function(PCA_Path, PC_Select, ImPathShade, Kmeans_info, Spectral
for (i in 1:nbPieces) {
print(paste("Spectral Species Piece #", i, "/", nbPieces))
Location_RW <- list()
Location_RW$nbLines <- SeqRead_PCA$Lines.Per.Chunk[i]
Location_RW$nbLines <- SeqRead_PCA$Lines_Per_Chunk[i]
Location_RW$Byte_Start_PCA <- SeqRead_PCA$ReadByte_Start[i]
Location_RW$lenBin_PCA <- SeqRead_PCA$ReadByte_End[i] - SeqRead_PCA$ReadByte_Start[i] + 1
Location_RW$Byte_Start_Shade <- SeqRead_Shade$ReadByte_Start[i]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment