Skip to content

Commit

Permalink
Reinstall R et renv avant test Rix Nix
Browse files Browse the repository at this point in the history
  • Loading branch information
MGousseff committed Sep 16, 2024
1 parent c6a90df commit 874d2ee
Show file tree
Hide file tree
Showing 22 changed files with 1,188 additions and 311 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: This lczexplore package automatize the comparison of sets of local
License: LGPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports: RColorBrewer,
cowplot,
dplyr,
Expand All @@ -31,7 +31,6 @@ Suggests:
png,
markdown
Config/testthat/edition: 3
VignetteBuilder: knitr
LazyData: true
Depends:
R (>= 2.10)
Binary file added GeneralUniquenessSensib.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions R/createIntersect.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
createIntersec<-function(sfList, columns, refCrs=NULL, sfWf=NULL){
echInt<-sfList[[1]] %>% select(columns[1])
if (is.null(refCrs)){refCrs<-st_crs(echInt)}
for (i in 2:length(sfList)){
sfProv<-sfList[[i]] %>% select(columns[i])
if (st_crs(sfProv) != refCrs ) {sfProv<-st_transform(sfProv, crs=refCrs)}
echInt<-st_intersection(echInt,sfProv)
}
if (!is.null(sfWf) & length(sfWf) == length(sfList)){
names(echInt)[1:(ncol(echInt)-1)]<-paste0("LCZ",sfWf)
} else { names(echInt)[1:(ncol(echInt)-1)]<-paste0("LCZ",1:length(sfList)) }
echInt
}

# sfBDT_11_78030<-importLCZvect(dirPath="/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS/BDT/2011/bdtopo_2_78030",
# file="rsu_lcz.fgb", column="LCZ_PRIMARY")
# class(sfBDT_11_78030)
# sfBDT_22_78030<-importLCZvect(dirPath="/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS/BDT/2022/bdtopo_3_78030",
# file="rsu_lcz.fgb", column="LCZ_PRIMARY")
# sf_OSM_11_Auffargis<-importLCZvect(dirPath="/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS/OSM/2011/osm_Auffargis/",
# file="rsu_lcz.fgb", column="LCZ_PRIMARY")
# sf_OSM_22_Auffargis<-importLCZvect(dirPath="/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS/OSM/2022/osm_Auffargis/",
# file="rsu_lcz.fgb", column="LCZ_PRIMARY")
# sf_WUDAPT_78030<-importLCZvect("/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS/WUDAPT",
# file ="wudapt_78030.geojson", column="lcz_primary")
#
# sfList<-list(BDT11 = sfBDT_11_78030, BDT22 = sfBDT_22_78030, OSM11= sf_OSM_11_Auffargis, OSM22 = sf_OSM_22_Auffargis,
# WUDAPT = sf_WUDAPT_78030)
# showLCZ(sfList[[1]])
#
#
#
# intersected<-createIntersec(sfList = sfList, columns = c(rep("LCZ_PRIMARY",4),"lcz_primary"),
# sfWf = c("BDT11","BDT22","OSM11","OSM22","WUDAPT"))
#
#
# test_list<-list(a=c(1,2),b="top",c=TRUE)
# length(test_list)
# for (i in test_list[2:3]) print(str(i))
97 changes: 97 additions & 0 deletions R/shinyGC/BDTproduction.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Villes à produire
# # 78
# nom de commune, insee
# Conflans-Sainte-Honorine, 78172
# Saint-Rémy-lès-Chevreuse, 78575
# Les Mureaux, 78440
# Freneuse, 78255
# Auffargis, 78030
# Les Essarts-le-Roi, 78220
# Orgeval, 78466
# Rosny-sur-Seine, 78531
# Saint-Léger-en-Yvelines, 78562
# Poigny-la-Forêt, 78497
# Blaru, 78068
# Paray-Douaville, 78478
# Le Tartre-Gaudran, 78606

# Test conflans 2011 : OK

test<-geoClimateConfigFile(wf = "BDT",
date="2011",
BDTinFolder="/home/gousseff/Documents/3_data/BDTOPO/2011/",
locations="78172",
outConfigFile="",
outConfigDir = "/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS",
outFolder = "/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS",
rsuIndics = c("LCZ"),
writeNow = TRUE,
forceSRID=TRUE)

geoClimateCall(
jarFilePath= "/home/gousseff/Documents/2_CodesSources/GeoClimate/Release1.0/geoclimate-1.0.0.jar",
configFilePath="/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS/78172BDT2011.json",
wf="BDTOPO_V2")

# Test conflans 2022 :

test<-geoClimateConfigFile(wf = "BDT",
date="2022",
BDTinFolder="/home/gousseff/Documents/3_data/BDTOPO/2022/",
locations="78172",
outConfigFile="",
outConfigDir = "/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS",
outFolder = "/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS",
rsuIndics = c("LCZ"),
writeNow = TRUE,
forceSRID=TRUE)

geoClimateCall(
jarFilePath= "/home/gousseff/Documents/2_CodesSources/GeoClimate/Release1.0/geoclimate-1.0.0.jar",
configFilePath="/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS/78172BDT2022.json",
wf="BDTOPO_V3")

city_code_78_93<-c("78172", "78575", "78440", "78255", "78030", "78220", "78466",
"78531", "78562", "78497", "78068", "78478", "78606", "93029", "93066", "93048")

configDir<-"/home/gousseff/Documents/0_DocBiblioTutosPublis/0_ArticlesScientEtThèses/ArticleComparaisonLCZGCWUDAPTEXPERTS"
for (i in city_code_78){
# 2011
geoClimateConfigFile(wf = "BDT",
date="2011",
BDTinFolder="/home/gousseff/Documents/3_data/BDTOPO/2011/78/",
locations=i,
outConfigFile="",
outConfigDir = configDir,
outFolder = configDir,
rsuIndics = c("LCZ"),
writeNow = TRUE,
forceSRID=TRUE)

confFile<-paste0(configDir, "/", i, "BDT2011.json")

geoClimateCall(
jarFilePath= "/home/gousseff/Documents/2_CodesSources/GeoClimate/Release1.0/geoclimate-1.0.0.jar",
configFilePath=confFile,
wf="BDTOPO_V2")


# 2022
geoClimateConfigFile(wf = "BDT",
date="2022",
BDTinFolder="/home/gousseff/Documents/3_data/BDTOPO/2022/78/",
locations=i,
outConfigFile="",
outConfigDir = configDir,
outFolder = configDir,
rsuIndics = c("LCZ"),
writeNow = TRUE,
forceSRID=TRUE)

confFile<-paste0(configDir, "/", i, "BDT2022.json")

geoClimateCall(
jarFilePath= "/home/gousseff/Documents/2_CodesSources/GeoClimate/Release1.0/geoclimate-1.0.0.jar",
configFilePath=confFile,
wf="BDTOPO_V3")
}
43 changes: 43 additions & 0 deletions R/shinyGC/geoClimateCall.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' Calls GeoClimate and feeds it a configuration file by building a command an using system (only tested on linux)
#' @param jarFilePath tells where the geoclimate jar file is, default points to the embedded jar file,
#' i.e. the latest snapshot version when the package was built.
#' Versions can be downloaded from https://github.com/orbisgis/geoclimate/wiki/Download
#' @param configFilePath points to the configuration JSON file for GeoClimate, typically a file created with the
#' geoClimateConfigFile function
#' @param wf is the workflow to use with GeoClimate, the default is OSM for OpenStreetMap.
#' The other possible value is "BDTOPO_V2". Other values will be added (e.g. for BDTOPO_V3) when tested.
#' @return returns nothing but files will be created by GeoClimate in the folder specified in the
#' JSON configuration file.
#' @export
#' @examples
#' test<-geoClimateConfigFile(outFile="", wf="osm",outFolder="/tmp",locations="Redon",
#' rsuIndics = c("LCZ","TEB","UTRF"),
#' gridIndics = c("BUILDING_FRACTION","BUILDING_HEIGHT","WATER_FRACTION","VEGETATION_FRACTION","ROAD_FRACTION",
#' "IMPERVIOUS_FRACTION","LCZ_PRIMARY","LCZ_FRACTION","UTRF"))
#' geoClimateCall(
#' jarFilePath= "/home/gousseff/Documents/2_CodesSources/GeoClimate/GeoClimateDefaultCaseV2/geoclimate-0.0.2-SNAPSHOT.jar",
#' configFilePath="/tmp/Redonosm.json",w="osm")
#' test
geoClimateCall<-function(jarFilePath, configFilePath, wf="OSM") {
command<-paste0(
"java -jar ", jarFilePath, " -f ", configFilePath, " -w ", toupper(wf))
print(command)
system(command)
}

# test<-geoClimateConfigFile(outFile="", wf="osm",outFolder="/tmp",locations="Allaire",
# rsuIndics = c("LCZ","TEB","UTRF"),
# gridIndics = c("BUILDING_FRACTION",
# "BUILDING_HEIGHT",
# "WATER_FRACTION",
# "VEGETATION_FRACTION",
# "ROAD_FRACTION",
# "IMPERVIOUS_FRACTION",
# "LCZ_PRIMARY",
# "LCZ_FRACTION",
# "UTRF"))
#
# geoClimateCall(
# jarFilePath= "/home/gousseff/Documents/2_CodesSources/GeoClimate/GeoClimateDefaultCaseV2/geoclimate-0.0.2-SNAPSHOT.jar",
# configFilePath="/tmp/Redonosm.json", wf="osm")
# test
145 changes: 145 additions & 0 deletions R/shinyGC/geoClimateConfigFile.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#' Builds a JSON configuration file for GeoClimate workflow
#' @param locations is either the town or the coordinates of the bounding box of the area on which GeoClimate will run.
#' If a town name, it will be fed to the Nominoe API, through the overpass API of OpenStreetMap.
#' @param wf is the workflow used by GeoClimate. For now, only OSM" is available, for OpenStreetMap, but "BDT" for
#' BDTOPO of IGN should be added when an online database is available.
#' @param date is the date of the data we extract from OpenStreetMap. The format is "yyyy:mm:ddThh:mm:ssZ"
#' (for BDTOPO the version depends from the input data folder)
#' @param outFolder indicates where the results of GeoClimate will be put
#' @param rsuIndics is a vector with the indicators one wants to compute at the RSU scale. The default is c("LCZ","TEB","UTRF"),
#' @param svfSimplified uses the simplified method to calculate skyview factor, default = TRUE
#' @param estimatedHeight uses an algorithm to estimate the missing building height, default = TRUE
#' @param grid_x_size is the x size for the grid if some grid indicators are to be computed, default=100
#' @param grid_y_size is the x size for the grid if some grid indicators are to be computed, default=100
#' @param rowCol if grid_x_size and grid_y_size are not set, one cal set the number of rows and cols throug rowCol,
#' but the recommended and default is FALSE
#' @param outputType is the format of GeoClimate outputs, default="geojson",
#' @param gridIndics is a vector containing the indicators to compute at the grid scale. Default is
#' c("BUILDING_FRACTION",
#' "BUILDING_HEIGHT",
#' "WATER_FRACTION",
#' "VEGETATION_FRACTION",
#' "ROAD_FRACTION",
#' "IMPERVIOUS_FRACTION","LCZ_PRIMARY","LCZ_FRACTION","UTRF")
#' @param outConfigDir is the folder were the resulting JSON file will be put, the folder where GeoClimate will read it from
#' (different from out outFolder, where GeoClimates will put its geoJSON ouputs), default is "/tmp"
#' @param outConfigFile is the name of your configuration file, if and empty string, a name will be created from location
#' and workflow parameters.
#' @param forceSRID some BD TOPO input file may not have an srid, this forces srid to be 2154
#' @importFrom jsonlite unbox toJSON
#' @return returns a JSON configuration file to be fed to GeoClimate
#' @export
#' @examples
#' test<-geoClimateConfigFile(outConfigFile="", wf="osm",outFolder="/tmp",locations="Redon",
#' rsuIndics = c("LCZ","TEB","UTRF"),
#' gridIndics = c("BUILDING_FRACTION","BUILDING_HEIGHT","WATER_FRACTION","VEGETATION_FRACTION","ROAD_FRACTION",
#' "IMPERVIOUS_FRACTION","LCZ_PRIMARY","LCZ_FRACTION","UTRF"))
#' test
geoClimateConfigFile<-function(wf, locations, forceSRID=FALSE,
outFolder="/tmp",
date,
rsuIndics=c("LCZ","TEB","UTRF"),
svfSimplified = TRUE,
estimatedHeight = TRUE,
grid_x_size=0,
grid_y_size=0,
rowCol = FALSE,
outputType = "geojson",
gridIndics="",
outConfigDir = "/tmp",
outConfigFile = "configFile",
BDTinFolder = "", BDTinseeCode=29301,
writeNow = FALSE) {
# description<-"Test de description unique"

if (wf=="OSM"){description<-"Processing OSM data"} else {
if (wf=="BDTOPO_V2") {description<-"Processing BDTopo v2 data"} else {
if (wf=="BDTOPO_V3") {
description<-"Processing BDTopo v3 data"}
else { description<-paste0("Processing on an unrecognized workflow: ", wf)
}
}
}

outFolder<-tryCatch( # This hideous tryCatch deals with weird shinyDirChoose behavior
{
list(folder=jsonlite::unbox(paste0(jsonlite::unbox(outFolder),
"/",wf,"/", substr(date,1,4)))) },
error=function(e){
list(folder="\tmp")
}
)


if (wf == "OSM"){
input<-list(locations=locations, date=jsonlite::unbox(date))
} else { if (grep("BDT",wf)==1) {
if (forceSRID==FALSE){
input<-
list(
folder= tryCatch(
jsonlite::unbox(BDTinFolder),
error=function(e){
list(folder="\tmp")
}),
locations=locations
)
} else { if (forceSRID==TRUE) {
input<-
list(
folder= tryCatch(
jsonlite::unbox(BDTinFolder),
error=function(e){
list(folder="\tmp")
})
,
locations=locations,
srid=jsonlite::unbox(2154))
}}
}}


if(grid_x_size!=0 & grid_y_size!=0){
parameters<-list(
rsu_indicators = list(
indicatorUse = rsuIndics,
svSimplified = jsonlite::unbox(svfSimplified),
estimatedHeight = jsonlite::unbox(estimatedHeight)),
grid_indicators = list(
x_size = jsonlite::unbox(grid_x_size), y_size = jsonlite::unbox(grid_y_size),
rowCol = jsonlite::unbox(rowCol),
output = jsonlite::unbox(outputType),
indicators = gridIndics
)
)
} else {
parameters<-list(
rsu_indicators = list(
indicatorUse = rsuIndics,
svSimplified = jsonlite::unbox(svfSimplified),
estimatedHeight = jsonlite::unbox(estimatedHeight)))
}

listJSON <- list(description=jsonlite::unbox(description), input=input, output=outFolder, parameters=parameters)

output<-toJSON(x=listJSON,
pretty=TRUE)



if (outConfigFile=="") { outConfigFile<-paste0(locations,wf) }

if (writeNow == TRUE){
write(output,file=paste0(outConfigDir,"/",outConfigFile,substr(date,1,4),".json"))
}

return(output)

}
#
# library(jsonlite)
# test<-geoClimateConfigFile(outConfigFile="", wf="BDTOPO_V2.2",outFolder=list(folder="/tmp",srid=2154),locations="Allaire",
# rsuIndics = c("LCZ","TEB","UTRF"),
# gridIndics = c("BUILDING_FRACTION","BUILDING_HEIGHT","WATER_FRACTION","VEGETATION_FRACTION","ROAD_FRACTION",
# "IMPERVIOUS_FRACTION","LCZ_PRIMARY","LCZ_FRACTION","UTRF"))
# test
Loading

0 comments on commit 874d2ee

Please sign in to comment.