diff --git a/exploration/NEA_sensitivity_analysis/extractNumeroProcess.R b/exploration/NEA_sensitivity_analysis/extractNumeroProcess.R new file mode 100644 index 0000000000000000000000000000000000000000..6d6e57d9e7678f890b6bbc00a1c1384ad50c6485 --- /dev/null +++ b/exploration/NEA_sensitivity_analysis/extractNumeroProcess.R @@ -0,0 +1,21 @@ +library(tidyverse) +#source("../GR3D_Rdescription/GR3D_NEA_XML_parameters.R") + +setwd("~/Documents/workspace/GR3D/exploration/NEA_sensitivity_analysis") +fishXML <- xmlToList(xmlParse("../../data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml")) + + fishXML[["species.DiadromousFishGroup"]][["processes"]] + + +no_processesEachStep = tibble( process = names(fishXML[["species.DiadromousFishGroup"]][["processes"]][["processesEachStep"]][])) %>% + mutate(no_R = row_number()) %>% + filter(process != "comment") %>% + mutate(no_java = row_number()-1) %>% + select(no_R, no_java, process) + +no_processesAtEnd = tibble( process = names(fishXML[["species.DiadromousFishGroup"]][["processes"]][["processesAtEnd"]][])) %>% + mutate(no_R = row_number()) %>% + filter(process != "comment") %>% + mutate(no_java = row_number()-1) %>% + select(no_R, no_java, process) + \ No newline at end of file diff --git a/exploration/NEA_sensitivity_analysis/tryFromJava.R b/exploration/NEA_sensitivity_analysis/tryFromJava.R index c30bc9627cc772d29f0441359c35ba9afc2af6e5..b9b08357503ca3829046238f2bb18a0bf37446c9 100644 --- a/exploration/NEA_sensitivity_analysis/tryFromJava.R +++ b/exploration/NEA_sensitivity_analysis/tryFromJava.R @@ -23,6 +23,7 @@ rm(list = ls()) # GR3D arguments ----------------------------------------- ## to have the same working directory as GR3D +#setwd("~/Documents/workspace/GR3D/exploration/NEA_sensitivity_analysis") setwd("../..") # path to outputs @@ -51,13 +52,41 @@ arguments = c('-q','-simDuration', simDuration, '-simBegin',simBegin, .jinit(classpath = jarfile, force.init = TRUE) # modification of xlm parameters ----------------------- -parametersNames = c("processes.processesEachStep.10.tempMinRep", - "processes.processesEachStep.10.ratioS95_S50", - "processes.processesEachStep.6.pHomingAfterEquil") -thetas = c(10, 2, 0.7) + + + +parametersNamesANG = c("processes.processesEachStep.11.Soffset") +thetasANG = c(0) + +parametersNamesENV = c("simulationName") +thetasENV = c("noAllee") + + + + + +runEasyRun = function(arguments, parametersNamesANG,thetasANG, parametersNamesENV, thetasENV ){ + # run the GR3D with updated parameter values in processes -------------------------------------------- + .jclassPath() + .jcall("analysis.EasyRun", "V", "runSimulation", arguments, + .jarray(parametersNamesANG), .jarray(thetasANG), + .jarray(parametersNamesENV), .jarray(thetasENV)) + # call GR3D method to get model outputs ---------------------------------------------- + #1. northern limit and distribution centroid ---- + out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.10.exportToR") + range <- data.frame(matrix(convertToR(out[[2]]), nrow = 1, dimnames = list(NULL, convertToR(out[[1]])))) %>% type_convert() + + return(list(range = range)) +} + +runEasyRun(arguments, parametersNamesANG,thetasANG, parametersNamesENV, thetasENV ) + + # run the GR3D with updated parameter values in processes -------------------------------------------- .jclassPath() -.jcall("analysis.EasyRun", "V", "runSimulation", arguments, .jarray(parametersNames), .jarray(thetas)) +.jcall("analysis.EasyRun", "V", "runSimulation", arguments, + .jarray(parametersNamesANG), .jarray(thetasANG), + .jarray(parametersNamesENV), .jarray(thetasENV)) # call GR3D method to get model outputs ---------------------------------------------- @@ -65,14 +94,14 @@ thetas = c(10, 2, 0.7) #TODO export [char] and then data.frame(toto) %>% type_convert() # ----------------------------------------------------------------------------------# # 1. northern limit and distribution centroid ---- -# only basins with more than 50 recruits in average in the last 10 years (colonised basins) +# only basins with more than 50 recruits in average in the last 50 years (colonised basins) # compute only in SPRING # access through getRangeDistribution in DiadromousFishGroup ==== NOT CORRECT # range[1] = latitude of the median distribution ( 50 % of effectives are northern) # range[2] = southern limit latitude of the fish distribution -out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.9.exportToR") +out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.10.exportToR") range <- data.frame(matrix(convertToR(out[[2]]), nrow = 1, dimnames = list(NULL, convertToR(out[[1]])))) %>% type_convert() @@ -98,11 +127,16 @@ range <- data.frame(matrix(convertToR(out[[2]]), nrow = 1, dimnames = list(NULL out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.8.exportToR") -out2 = matrix(unlist(lapply(out, convertToR)), nrow = length(out) , byrow = TRUE) -out3 <- out2[-1,] -colnames(out3) <- unlist(out2[1,]) -as.data.frame(out3) %>% type_convert() +convertFromSALtoR = function(java_out){ + require(jdx) + out2 = matrix(unlist(lapply(java_out, convertToR)), nrow = length(java_out) , byrow = TRUE) + out3 <- out2[-1,] + colnames(out3) <- unlist(out2[1,]) + R_out <- as.data.frame(out3) %>% type_convert() + return(R_out) +} +convertFromSALtoR(java_out = out) # ------------------------------------------------------------ # @@ -118,23 +152,6 @@ as.data.frame(out3) %>% type_convert() #TODO A FAIRE !!! # ================================================================================= -toto <- .jcall("analysis.EasyRun","Ljava/util/List;", - "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords") -as.list(toto) - -# truc = .jcall("analysis.EasyRun","Ljava/util/List;", -# "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords") -# -# trucMieux = .jcast(truc, "ljava/util/ArrayList", convert.array = FALSE) -# -# i <- .jnew("java/lang/Integer", as.integer(10)) -# print(i) -# print(.jsimplify(i)) -# .jcall(trucMieux, "java/lang/Object", "get", i) -# -# with(trucMieux, {get(0)}) -# ArrayList = J("java.util.ArrayList") -# .jclassPath()