tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
head(tpa_data)
pixelnum=1
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
num_seasons
line_header
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
tpa_data_row
line_data
offset <- 1
raw_vec_length <- length(raw_vector)
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
file_header <- offset_readBin(raw_vector, integer(), n=6, size=4)
num_years <- file_header[1]
rowstart <- file_header[3]
rowstop <- file_header[4]
colstart <- file_header[5]
colstop <- file_header[6]
num_rows <- rowstop - rowstart + 1
num_cols <- colstop - colstart + 1
num_pixels <- num_cols * num_rows
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
# Read the data and save it in the tpa_data matrix
for (pixelnum in 1:num_pixels) {
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
if (num_seasons > max_num_seasons) {
stop(paste('pixel', pixelnum, 'has', num_seasons,
'seasons, but max_num_seasons was set to ', max_num_seasons,
'seasons'))
}
if (num_seasons == 0) {
# No seasons identified for this pixel - skip
next
}
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
}
line_header
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
offset <- 1
raw_vec_length <- length(raw_vector)
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
raw_vec_length
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
NUM_SEASONAL_INDICATORS
NUM_SEASONAL_INDICATORS <- 13
file_header <- offset_readBin(raw_vector, integer(), n=6, size=4)
num_years <- file_header[1]
rowstart <- file_header[3]
rowstop <- file_header[4]
colstart <- file_header[5]
colstop <- file_header[6]
num_rows <- rowstop - rowstart + 1
num_cols <- colstop - colstart + 1
num_pixels <- num_cols * num_rows
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
# Read the data and save it in the tpa_data matrix
for (pixelnum in 1:num_pixels) {
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
if (num_seasons > max_num_seasons) {
stop(paste('pixel', pixelnum, 'has', num_seasons,
'seasons, but max_num_seasons was set to ', max_num_seasons,
'seasons'))
}
if (num_seasons == 0) {
# No seasons identified for this pixel - skip
next
}
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
}
max_num_seasons=1
LINE_HEADER_SIZE <- 3
tpa_file_obj <- file(x, "rb")
raw_vector <- readBin(tpa_file_obj, n=file.info(x)$size, raw())
close(tpa_file_obj)
# This function is used to track the offset within the binary vector as readBin
# does not track position except for file objects
offset <- 1
raw_vec_length <- length(raw_vector)
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
# File header format is: nyears nptperyear rowstart rowstop colstart colstop
file_header <- offset_readBin(raw_vector, integer(), n=6, size=4)
num_years <- file_header[1]
rowstart <- file_header[3]
rowstop <- file_header[4]
colstart <- file_header[5]
colstop <- file_header[6]
num_rows <- rowstop - rowstart + 1
num_cols <- colstop - colstart + 1
num_pixels <- num_cols * num_rows
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
# Read the data and save it in the tpa_data matrix
for (pixelnum in 1:num_pixels) {
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
if (num_seasons > max_num_seasons) {
stop(paste('pixel', pixelnum, 'has', num_seasons,
'seasons, but max_num_seasons was set to ', max_num_seasons,
'seasons'))
}
if (num_seasons == 0) {
# No seasons identified for this pixel - skip
next
}
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
}
max_num_seasons=2
NUM_SEASONAL_INDICATORS <- 13
# Number of elements in the tpa file line header (which are normally: row,
# column, number of seasons).
LINE_HEADER_SIZE <- 3
tpa_file_obj <- file(x, "rb")
raw_vector <- readBin(tpa_file_obj, n=file.info(x)$size, raw())
close(tpa_file_obj)
# This function is used to track the offset within the binary vector as readBin
# does not track position except for file objects
offset <- 1
raw_vec_length <- length(raw_vector)
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
# File header format is: nyears nptperyear rowstart rowstop colstart colstop
file_header <- offset_readBin(raw_vector, integer(), n=6, size=4)
num_years <- file_header[1]
rowstart <- file_header[3]
rowstop <- file_header[4]
colstart <- file_header[5]
colstop <- file_header[6]
num_rows <- rowstop - rowstart + 1
num_cols <- colstop - colstart + 1
num_pixels <- num_cols * num_rows
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
# Read the data and save it in the tpa_data matrix
for (pixelnum in 1:num_pixels) {
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
if (num_seasons > max_num_seasons) {
stop(paste('pixel', pixelnum, 'has', num_seasons,
'seasons, but max_num_seasons was set to ', max_num_seasons,
'seasons'))
}
if (num_seasons == 0) {
# No seasons identified for this pixel - skip
next
}
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
}
tpa_data <- data.frame(tpa_data)
tpa_data <- tpa_data[!(rowSums(is.na(tpa_data)) == ncol(tpa_data)), ]
names(tpa_data) <- c("row", "col", "season", "start", "end", "length",
"base_value", "peak_time", "peak_value", "amp", "left_deriv",
"right_deriv", "large_integ", "small_integ")
head(tpa_data)
NUM_SEASONAL_INDICATORS <- 11
tpa_file_obj <- file(x, "rb")
raw_vector <- readBin(tpa_file_obj, n=file.info(x)$size, raw())
close(tpa_file_obj)
# This function is used to track the offset within the binary vector as readBin
# does not track position except for file objects
offset <- 1
raw_vec_length <- length(raw_vector)
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
file_header <- offset_readBin(raw_vector, integer(), n=6, size=4)
num_years <- file_header[1]
rowstart <- file_header[3]
rowstop <- file_header[4]
colstart <- file_header[5]
colstop <- file_header[6]
num_rows <- rowstop - rowstart + 1
num_cols <- colstop - colstart + 1
num_pixels <- num_cols * num_rows
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
# Read the data and save it in the tpa_data matrix
for (pixelnum in 1:num_pixels) {
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
if (num_seasons > max_num_seasons) {
stop(paste('pixel', pixelnum, 'has', num_seasons,
'seasons, but max_num_seasons was set to ', max_num_seasons,
'seasons'))
}
if (num_seasons == 0) {
# No seasons identified for this pixel - skip
next
}
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
}
# The number of seasonal indicators output by TIMESAT.
NUM_SEASONAL_INDICATORS <- 12
LINE_HEADER_SIZE <- 3
tpa_file_obj <- file(x, "rb")
raw_vector <- readBin(tpa_file_obj, n=file.info(x)$size, raw())
close(tpa_file_obj)
# This function is used to track the offset within the binary vector as readBin
# does not track position except for file objects
offset <- 1
raw_vec_length <- length(raw_vector)
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
# File header format is: nyears nptperyear rowstart rowstop colstart colstop
file_header <- offset_readBin(raw_vector, integer(), n=6, size=4)
num_years <- file_header[1]
rowstart <- file_header[3]
rowstop <- file_header[4]
colstart <- file_header[5]
colstop <- file_header[6]
num_rows <- rowstop - rowstart + 1
num_cols <- colstop - colstart + 1
num_pixels <- num_cols * num_rows
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
# Read the data and save it in the tpa_data matrix
for (pixelnum in 1:num_pixels) {
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
if (num_seasons > max_num_seasons) {
stop(paste('pixel', pixelnum, 'has', num_seasons,
'seasons, but max_num_seasons was set to ', max_num_seasons,
'seasons'))
}
if (num_seasons == 0) {
# No seasons identified for this pixel - skip
next
}
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
}
NUM_SEASONAL_INDICATORS <- 13
# Number of elements in the tpa file line header (which are normally: row,
# column, number of seasons).
LINE_HEADER_SIZE <- 3
tpa_file_obj <- file(x, "rb")
raw_vector <- readBin(tpa_file_obj, n=file.info(x)$size, raw())
close(tpa_file_obj)
offset <- 1
raw_vec_length <- length(raw_vector)
offset_readBin <- function(raw_vec, what, n=n, size=size, increment_offset=TRUE, ...) {
bin_data <- readBin(raw_vec[offset:(n * size + offset)], what, n, size, ...)
# Use a global variable to track the offset
if (increment_offset) {assign("offset", offset + (size*n), inherits=TRUE)}
return(bin_data)
}
# File header format is: nyears nptperyear rowstart rowstop colstart colstop
file_header <- offset_readBin(raw_vector, integer(), n=6, size=4)
num_years <- file_header[1]
rowstart <- file_header[3]
rowstop <- file_header[4]
colstart <- file_header[5]
colstop <- file_header[6]
num_rows <- rowstop - rowstart + 1
num_cols <- colstop - colstart + 1
num_pixels <- num_cols * num_rows
tpa_data <- matrix(nrow=num_pixels*max_num_seasons,
ncol=(LINE_HEADER_SIZE + NUM_SEASONAL_INDICATORS))
# Read the data and save it in the tpa_data matrix
for (pixelnum in 1:num_pixels) {
line_header <- offset_readBin(raw_vector, integer(), n=3, size=4)
# Line header format is: rownum colnum numseasons
num_seasons <- line_header[3]
if (num_seasons > max_num_seasons) {
stop(paste('pixel', pixelnum, 'has', num_seasons,
'seasons, but max_num_seasons was set to ', max_num_seasons,
'seasons'))
}
if (num_seasons == 0) {
# No seasons identified for this pixel - skip
next
}
for (seasonnum in 1:max_num_seasons) {
# Seasons were found for this pixel - read them
tpa_data_row <- (pixelnum - 1)*num_seasons + seasonnum
line_data <- offset_readBin(raw_vector, numeric(),
n=NUM_SEASONAL_INDICATORS, size=4)
tpa_data[tpa_data_row, ] <- c(line_header[1], line_header[2],
seasonnum, line_data)
}
}
tpa_data <- data.frame(tpa_data)
tpa_data <- tpa_data[!(rowSums(is.na(tpa_data)) == ncol(tpa_data)), ]
names(tpa_data) <- c("row", "col", "season", "start", "end", "length",
"base_value", "peak_time", "peak_value", "amp", "left_deriv",
"right_deriv", "large_integ", "small_integ","sos","eos")
head(tpa_data)
# base_raster
r=raster()
if(T){
library(sp)
library(sf)
library(raster)
library(dplyr)
library(units)
library(purrr)
library(lwgeom)
require(ShapePattern)
require(progress)
require(spatialEco)
library(geostatsp)
library(gdalUtils)
library(assist)
library(SparseM)
library(RANN)
library(nabor)
library(stringr)
library(gdalUtils)
library(nls.multstart)
library(FinCal)
library(lidR)
library(rLiDAR)
library(e1071)
require(tidyverse)
library(glue)
library(fasterize)
library(future)
library(furrr)
library(terra)
library(lubridate)
library(rTIMESAT)
}
path_otb = "C:/OTB-7.2.0-Win64/bin/"
path_gdal = "C:/OTB-7.2.0-Win64/bin/"
path_gdal_py = "C:/OSGeo4W64/OSGeo4W.bat ; python C:/OSGeo4W64/bin/"
path_gdal = "C:/OTB-6.6.1-Win64/bin/"
path_otb = "C:/OTB-6.6.1-Win64/bin/"
path0="C:/PL/03_dossiers/eliche"
hist(tpa_data$small_integ)
hist(tpa_data$large_integ)
hist(tpa_data$start)
hist(tpa_data$length)
hist(tpa_data$sos)
library(sf)
library(lidR)
library(dplyr)
path0="C:/PL/01_COURS/vivasciences/input/chassepierre/laz"
f1="C:/PL/01_COURS/vivasciences/input/chassepierre/laz/3.laz"
las1=readLAS(f1)
las1
f1="C:/PL/01_COURS/vivasciences/input/chassepierre/laz/3.laz"
las1=lidR::readLAS(f1)
las1
table(las1@data$classification)
table(las1@data$Classification)
library(raster)
library(shapefiles)
library(terra)
path0 = "C:/PL/01_COURS/vivasciences/atelier_lidar_qgis/input/mazy"
setwd(path0)
cmdline = "pitremove.exe"
system(cmdline)
# verifier que la librairie Taudem est correctement installée
cmdline = "pitremove2.exe"
system(cmdline)
f_in = paste0(path0,"/mnt_1m.tif")
f_fel = paste0(path_out,"/fel.tif")
cmdline = paste0("pitremove.exe -z ", f_in, " -fel ", f_fel)
system(cmdline)
#************************************************************
# 1.   Pitremove : combler les "puits" présents dans le MNT
#          input : -z (original DEM)
#          ouput : -fel (filled DEM)
#************************************************************
f_in = paste0(path0,"/mnt_1m.tif")
f_fel = paste0(path_out,"/fel.tif")
file.exists(f_in)
f_in
f_in = paste0(path0,"/mnt.tif")
f_fel = paste0(path_out,"/fel.tif")
cmdline = paste0("pitremove.exe -z ", f_in, " -fel ", f_fel)
system(cmdline)
file.exists(f_in)
cmdline
cmdline = paste0("pitremove.exe -z ", f_in, " -fel ", f_fel)
f_in = paste0(path0,"/mnt.tif")
f_fel = paste0(path0,"/fel.tif")
cmdline = paste0("pitremove.exe -z ", f_in, " -fel ", f_fel)
system(cmdline)
f_p = paste0(path0,"/p.tif")
f_sd8 = paste0(path0,"/sd8.tif")
cmdline=paste0("D8Flowdir.exe -p ",f_p," -sd8 ",
f_sd8, " -fel ", f_fel)
system(cmdline)
f_ad8 = paste0(path0,"/ad8.tif")
cmdline=paste0("AreaD8 -p ",f_p," -ad8 ", f_ad8)
system(cmdline)
f_gord= paste0(path0,"/gord.tif")
f_plen= paste0(path0,"/plen.tif")
f_tlen= paste0(path0,"/tlen.tif")
cmdline=paste0("Gridnet -p ",f_p, " -gord ", f_gord,
" -plen ", f_plen, " -tlen ", f_tlen)
system(cmdline)
tresh0=5000
f_src= paste0(path0,"/src.tif")
cmdline=paste0("Threshold -ssa ",f_ad8, " -src ", f_src, " -thresh ",tresh0)
system(cmdline)
f_outlet=paste0(path0,"/exutoire.shp")
f_ssa=paste0(path_out,"/ssa.tif")
cmdline=paste0("Aread8 -p ", f_p, " -o ", f_outlet, " -ad8 ", f_ssa)
system(cmdline)
tresh0=5000
f_src1= paste0(path0,"/src1.tif")
cmdline=paste0("threshold -ssa ", f_ssa,
" -src ", f_src1, " -thresh ", tresh0)
system(cmdline)
f_ord= paste0(path0,"/ord1.tif")
f_tree= paste0(path0,"/tree1.txt")
f_coord= paste0(path0,"/coord1.txt")
f_net= paste0(path0,"/net.shp")
f_w= paste0(path_out,"/w.tif")
cmdline=paste0("Streamnet -fel ", f_fel, " -p ", f_p,
" -ad8 ", f_ad8, " -src ", f_src1,
" -o ", f_outlet, " -ord ", f_ord,
" -tree ", f_tree, " -coord ", f_coord,
" -net ", f_net, " -w ", f_w)
system(cmdline)
f_ad8 = paste0(path0,"/ad8.tif")
cmdline=paste0("AreaD8 -p ",f_p," -nc -ad8 ", f_ad8)
system(cmdline)
