if (!require("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("rhdf5") library(rhdf5) #----------------------------------------------------------------------------------------------------------------------- # Q1 #----------------------------------------------------------------------------------------------------------------------- setwd("D:/data_GEDI/export") files <- list.files(path="D:\data_GEDI\unzip", full.names = T, recursive = T, pattern = ".h5", include.dirs = T) beams = c("BEAM0000", "BEAM0001", "BEAM0010", "BEAM0011", "BEAM0101", "BEAM0110", "BEAM1000", "BEAM1011") #----------------------------------------------------------------------------------------------------------------------- # file:///F:/__UK_GEDI_DATA_Czechia/_00_GEDI_L2B_DATA_Czechia/gedi_l2b_dictionary_P001_v1.html #----------------------------------------------------------------------------------------------------------------------- for (b in beams) { # The L2B algorithm is run if this flag is set to 1 indicating data have sufficient waveform fidelity for L2B to run algorithmrun_flag = vector() # Beam identifier beam = vector() FLY = vector() lat_lowestmode = vector() #Latitude of center of lowest mode lon_lowestmode = vector() #Longitude of center of lowest mode shot_number = vector() #Unique shot ID. for (x in files) { # b = "BEAM0101" #x="F:/__UK_GEDI_DATA/_02_KRNAP_DATA/GEDI_L2A_Downloaded_20210903/2432362146/processed_GEDI02_A_2019112075017_O02026_02_T00059_02_003_01_V002.h5" #----------------------------------------------------------------------- # OPEN AND READ CONTENTES OF H5 FILE #----------------------------------------------------------------------- h5f = H5Fopen(x) value <- tryCatch( as.vector(h5read(h5f, paste(b, "/geolocation/lat_lowestmode", sep=""))), error = function(c) {NA} ) lat_lowestmode <- c(lat_lowestmode, value) value <- tryCatch( as.vector(h5read(h5f, paste(b, "/geolocation/lon_lowestmode", sep=""))), error = function(c) {NA} ) LENGTH=length(value) #Pocet radku, abych v dalsim kroku tusil kolik jich je treba vytahat lon_lowestmode <- c(lon_lowestmode, value) print(length(lon_lowestmode)) value <- tryCatch( as.vector(replicate(n = LENGTH, b)), error = function(c) {NA} ) beam <- c(beam, value) #beam = c(beam, as.vector(replicate(n = length(lon_lowestmode), b))) #Priradi kazdemu radku kterej je to BEAM #value <- tryCatch( # as.vector(h5read(h5f, paste(b, "/shot_number", sep=""), bit64conversion='double')), # error = function(c) {NA} #) #shot_number <- c(shot_number, value) file_name = strsplit(basename(x), "\\.")[[1]][1] # odst?ihnu koncovku fly_id = strsplit(file_name, "_")[[1]][4] # vyt?hnu ?as value <- tryCatch( as.vector(replicate(n = LENGTH, fly_id)), error = function(c) {NA} ) FLY <- c(FLY, value) #SHOT_NUMBER = c(SHOT_NUMBER, as.vector(h5read(h5f, paste(b, "/shot_number", sep=""), bit64conversion='double'))) # BACHA Pouziva 64 bitovej integer a muze dojit ke ztrate dat, vic zde: https://www.bioconductor.org/packages/release/bioc/vignettes/rhdf5/inst/doc/rhdf5.html } #----------------------------------------------------------------------- # Export CSV / SHAPEFILE #----------------------------------------------------------------------- #55555 #print(length(LAT), length(LON), length(CANOPY)) TEMP <- data.frame( lat_lowestmode, lon_lowestmode, beam, FLY) target <- paste(basename(b), ".csv", sep = "") print(target) write.csv(TEMP, target) H5Fclose(h5f) } #z toho jedno velk? csv #https://stackoverflow.com/questions/30242065/trying-to-merge-multiple-csv-files-in-r setwd("F:/__UK_GEDI_DATA_Czechia_L2B/_02_Czechia_L2B_CSV/Q4") library(dplyr) library(readr) toutou <- list.files(full.names = TRUE) %>% lapply(read_csv) %>% bind_rows #http://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/R/R-Manual/R-Manual5.html write.csv(toutou, 'csvelky.csv')