-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new functions for LCZ compare article
- Loading branch information
Showing
6 changed files
with
141 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' In a given list of directories the function looks for LCZ datafiles, return a datasets LCZ values for each geom and workflow | ||
#' @param dirList the list of directories for which the different LCZ files will be intersected | ||
#' @param workflowNames sets the names of workflows and define the name of the files which will be loaded and intersected | ||
#' @param for each diretory from dirList, a location name must be fed to the function | ||
#' @importFrom ggplot2 geom_sf guides ggtitle aes | ||
#' @import sf dplyr cowplot forcats units tidyr RColorBrewer utils grDevices rlang | ||
#' @return returns graphics of comparison and an object called matConfOut which contains : | ||
#' matConfLong, a confusion matrix in a longer form, | ||
#' matConfPlot is a ggplot2 object showing the confusion matrix. | ||
#' percAgg is the general agreement between the two sets of LCZ, expressed as a percentage of the total area of the study zone | ||
#' pseudoK is a heuristic estimate of a Cohen's kappa coefficient of agreement between classifications | ||
#' If saveG is not an empty string, graphics are saved under "saveG.png" | ||
#' @export | ||
#' @examples | ||
#' | ||
concatIntersectedLocations<-function(dirList, locations, workflowNames = c("osm","bdt","iau","wudapt")){ | ||
allLocAllWfSf<-matrix(ncol = 5, nrow = 0) | ||
allLocAllWfSf<-as.data.frame(allLocAllWfSf) | ||
names(allLocAllWfSf)<- c("lcz_primary", "location", "wf", "area", "geometry") | ||
for( i in 1:length(dirList)){ | ||
dirPath<-dirList[1] | ||
aLocation<-locations[i] | ||
sfList<-loadMultipleSf(dirPath = dirPath, | ||
workflowNames = workflowNames , location = aLocation ) | ||
if(substr(dirPath, nchar(dirPath), nchar(dirPath))!="/"){dirPath<-paste0(dirPath, "/")} | ||
zoneSfPath<-paste0(dirPath,"zone.fgb") | ||
zoneSf<-read_sf(zoneSfPath) | ||
sfList<-repairRoadsIAU(sfList = sfList, zoneSf = zoneSf, location = location) | ||
concatSf<-concatAlocationWorkflows(sfList = sfList, | ||
location = location, refCrs = 1) | ||
allLocAllWfSf<-rbind(allLocAllWfSf, concatSf) | ||
} | ||
|
||
allLocAllWfSf<- st_as_sf(allLocAllWfSf) | ||
} | ||
|
||
rootDir<-"/home/gousseff/Documents/3_data/data_article_LCZ_diff_algos/newDataTree" | ||
setwd(rootDir) | ||
allLCZDirNames <- list.dirs()[-1] | ||
allLCZDirNames <- substr(allLCZDirNames, start = 2, stop = 1000) | ||
allLocationsNames<-substr(allLCZDirNames, start = 2, stop = 1000) | ||
allLCZDirNames<-paste0(rootDir, allLCZDirNames, "/") | ||
allLocallWfs<-concatIntersectedLocations( | ||
dirList = allLCZDirNames, locations = allLocationsNames , workflowNames = c("osm","bdt","iau","wudapt")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' in a given directory, if several LCZ files are present, it plots the repartition of LCZ regarding of their source (workflow) | ||
#' NOTE: to represent the map of LCZ for a given fil, use `showLCZ` function instead | ||
#' @param workflownames is a vector of prefixes. The LCZ files must benames workflow_rsu.fgb | ||
#' @param plotNow. If TRUE, the boxplot of the repartition will be printed | ||
#' @param plotSave. If TRUE, the plot will be saved in the directory pointed by dirPath | ||
#' @importFrom ggplot2 geom_sf guides ggtitle aes | ||
#' @importFrom caret dummyVars | ||
#' @import sf dplyr cowplot forcats units tidyr RColorBrewer utils grDevices rlang | ||
#' @return Cramer's V between pairs of levels, in a matrix (cramerMatrix) or long form (cramerLong), | ||
#' and a dataframe with the nbOutAssociation most significant association | ||
#' @export | ||
#' @examples | ||
plotLCZaLocation<-function(dirPath, location, workflowNames = c("osm","bdt","iau","wudapt"), | ||
plotNow = FALSE, plotSave = TRUE){ | ||
colorMap<-c("#8b0101","#cc0200","#fc0001","#be4c03","#ff6602","#ff9856", | ||
"#fbed08","#bcbcba","#ffcca7","#57555a","#006700","#05aa05", | ||
"#648423","#bbdb7a","#010101","#fdf6ae","#6d67fd") | ||
names(colorMap)<-c(1:10,101:107) | ||
etiquettes<-c("LCZ 1: Compact high-rise","LCZ 2: Compact mid-rise","LCZ 3: Compact low-rise", | ||
"LCZ 4: Open high-rise","LCZ 5: Open mid-rise","LCZ 6: Open low-rise", | ||
"LCZ 7: Lightweight low-rise","LCZ 8: Large low-rise", | ||
"LCZ 9: Sparsely built","LCZ 10: Heavy industry", | ||
"LCZ A: Dense trees", "LCZ B: Scattered trees", | ||
"LCZ C: Bush,scrub","LCZ D: Low plants", | ||
"LCZ E: Bare rock or paved","LCZ F: Bare soil or sand","LCZ G: Water") | ||
|
||
sfList<-loadMultipleSf(dirPath = dirPath, | ||
workflowNames = workflowNames , location = location ) | ||
if(substr(dirPath, nchar(dirPath), nchar(dirPath))!="/"){dirPath<-paste0(dirPath, "/")} | ||
zoneSfPath<-paste0(dirPath,"zone.fgb") | ||
zoneSf<-read_sf(zoneSfPath) | ||
sfList<-repairRoadsIAU(sfList = sfList, zoneSf = zoneSf, location = location) | ||
concatSf<-concatAlocationWorkflows(sfList = sfList, | ||
location = location, refCrs = 1) | ||
|
||
surfaces<-concatSf %>% | ||
mutate(wf = factor(wf, levels = c("bdt", "osm", "wudapt", "iau"))) %>% | ||
group_by(wf, lcz_primary) %>% summarise(area=sum(area), location=unique(location)) | ||
|
||
location<-unique(surfaces$location) | ||
outPlot<-ggplot(surfaces, aes(fill=lcz_primary, y=area, x=wf)) + | ||
geom_col() + | ||
# scale_fill_viridis(discrete = T) + | ||
scale_fill_manual(values=colorMap, breaks = names(colorMap), labels = etiquettes) + | ||
ggtitle(paste0("LCZ repartition by workflow for ", location)) | ||
|
||
plotName<-paste0(dirPath, "LCZbyWfBoxplot.png") | ||
if(plotSave){ggsave(plotName, outPlot)} | ||
if (plotNow){print(outPlot)} | ||
|
||
return(outPlot) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters