Commit 17afd760 authored by Poulet Camille's avatar Poulet Camille
Browse files

Merge branch 'develop' of gitlab-ssh.irstea.fr:SimAquaLife/GR3D into exploration_GR3D_process

parents cb06d07d 38575a86
......@@ -280,8 +280,8 @@
<mortalityRateInOffshore>0.4</mortalityRateInOffshore>
</species.Survive>
<!--<species.WriteEffectiveAndBiomassImportFluxes> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> <exportSeason>SPRING</exportSeason>
<fileNameOutput>effectiveBiomassFluxesBeforeReproduction</fileNameOutput> </species.WriteEffectiveAndBiomassImportFluxes> -->
<!--<analysis.WriteEffectiveAndBiomassImportFluxes> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> <exportSeason>SPRING</exportSeason>
<fileNameOutput>effectiveBiomassFluxesBeforeReproduction</fileNameOutput> </anaysis.WriteEffectiveAndBiomassImportFluxes> -->
<species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
......@@ -328,15 +328,15 @@
</processesEachStep>
<processesAtEnd>
<species.WriteNutrientImportFluxes>
<analysis.WriteNutrientImportFluxes>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<fileName>nutrientImportfFluxes</fileName>
</species.WriteNutrientImportFluxes>
</analysis.WriteNutrientImportFluxes>
<species.WriteNutrientExportFluxes>
<analysis.WriteNutrientExportFluxes>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<fileName>nutrientExportFluxes</fileName>
</species.WriteNutrientExportFluxes>
</analysis.WriteNutrientExportFluxes>
</processesAtEnd>
</processes>
......
library(rJava) # see J4R
#library(yaml)
library(tidyverse)
library(jdx)
rm(list = ls())
......@@ -26,18 +27,18 @@ setwd("../..")
# path to outputs
#outputDir = "simus/"
outputFileName = paste0("SA/",seed)
#outputFileName = paste0("SA/",seed)
jarfile = "target/GR3D-3.2-SNAPSHOT.jar"
simDuration = 48
simDuration = 150
simBegin = 1
timeStepDuration = 1
seed = 1
arguments = c('-simDuration',simDuration, '-simBegin',simBegin,
'-timeStepDuration',timeStepDuration,
arguments = c('-q','-simDuration', simDuration, '-simBegin',simBegin,
'-timeStepDuration', timeStepDuration,
'-RNGStatusIndex', format(seed,scientific = FALSE),
'-groups',"data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml",
'-env',"data/input/northeastamerica/RIOBNneaBasins_Rjava.xml",
......@@ -46,6 +47,7 @@ arguments = c('-simDuration',simDuration, '-simBegin',simBegin,
# initializes the Java Virtual Machine -------------------------------------
.jinit(classpath ="", force.init = TRUE)
.jinit(classpath = jarfile, force.init = TRUE)
# modification of xlm parameters -----------------------
......@@ -53,9 +55,9 @@ parametersNames = c("processes.processesEachStep.10.tempMinRep",
"processes.processesEachStep.10.ratioS95_S50",
"processes.processesEachStep.6.pHomingAfterEquil")
thetas = c(10, 2, 0.7)
# run the GR3D with update xlm parameters --------------------------------------------
.jcall("analysis.EasyRun","V","runSimulation", arguments, outputFileName, .jarray(parametersNames), .jarray(thetas))
# run the GR3D with updated parameter values in processes --------------------------------------------
.jclassPath()
.jcall("analysis.EasyRun", "V", "runSimulation", arguments, .jarray(parametersNames), .jarray(thetas))
# call GR3D method to get model outputs ----------------------------------------------
......@@ -70,17 +72,17 @@ thetas = c(10, 2, 0.7)
# range[1] = latitude of the median distribution ( 50 % of effectives are northern)
# range[2] = southern limit latitude of the fish distribution
#range = .jcall("miscellaneous.EasyRun","[D","getValuesFromAquaNismsGroup","getRangeDistribution")
.jcall("analysis.EasyRun", "D", "getSingleValueFromAquanismGroupProcess", "processes.processesAtEnd.0.getLogLikelihood");
out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.9.exportToR")
range <- data.frame(matrix(convertToR(out[[2]]), nrow = 1, dimnames = list(NULL, convertToR(out[[1]])))) %>% type_convert()
# ------------------------------------------------------------ #
# 2. log-likelihood ----
# the proportion of reproductions leading to a recruitment > 50 over the 1920-1950 period was used
# as a proxy of predicted probability of presecen in a basin.
# as a proxy of predicted probability of presence in a basin.
# Then a log-likelihood of a binomial distribution is computed
# access through computeLikelihood in DiadromousFishGroup
# see getProbOfNonNulRecruitmentDuringLastYears in BasinNetwork
.jcall("analysis.EasyRun", "D", "getSingleValueFromAquanismGroupProcess", "processes.processesAtEnd.0.getLogLikelihood");
# ------------------------------------------------------------ #
# 3. proportion of first-time spawners
# annual % of first-time spawners according to latitude (or basin_id)
......@@ -88,16 +90,21 @@ thetas = c(10, 2, 0.7)
# then in R: annual slope of the linear regression
# and average over the period
# mean (+sd) and slpe after
# access through AnalyseSpawnerRun in [processesAtEnd]
# ------------------------------------------------------------ #
# 4. Mean age of the spawner for male and female ----
# annual mean age in each basin,
# then in R: average per year,
# and average over the period (1920 and 1950)
# mean (+sd) and slope after
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()
# ------------------------------------------------------------ #
# ------------------------------------------------------------ #
# 5. number of metapopulation based on the exchange matrix ----
......@@ -107,12 +114,16 @@ thetas = c(10, 2, 0.7)
# moyenne sur les bassins versants des moyennes sur la peride des moyennes des flux
# access through species.IdentifyPopulation in processesAtEnd
#TODO A FAIRE !!!
# =================================================================================
toto <- .jcall("analysis.EasyRun","Ljava/util/List;",
"getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords")
as.list(toto)
.jcall("miscellaneous.EasyRun","[D","getValuesFromEnvironment","getMeanLastPercOfAut")
# truc = .jcall("analysis.EasyRun","Ljava/util/List;",
# "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords")
......
......@@ -101,20 +101,22 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
}
public double[][] exportToR() {
public String[][] exportToR() {
// initialise the distribution range
double southernEdge = northernLimit;
double northernEdge = southernLimit;
int southernId = -1;
int northernId = -1;
String southernName = "";
String northernName = "";
// String southernName = "";
// String northernName = "";
// initialise for centroid
TreeMapForCentile latitudeEffective = new TreeMapForCentile();
TreeMapForCentile latitudePresence = new TreeMapForCentile();
double[][] export = new double[1][4];
String[][] export = new String[2][6];
int i = 0;
for (Entry<RiverBasin, QueueMemory<Double>> entry : lastSpawnerNumbersMemory.entrySet()) {
......@@ -129,7 +131,7 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
// the basin is the new southern edge
southernEdge = entry.getKey().getLatitude();
southernId = entry.getKey().getBasin_id();
// southernName = entry.getKey().getName();
southernName = entry.getKey().getName();
}
// northern edge
......@@ -137,7 +139,7 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
// the basin is the new northern edge
northernEdge = entry.getKey().getLatitude();
northernId = entry.getKey().getBasin_id();
// northernName = entry.getKey().getName();
northernName = entry.getKey().getName();
}
// for distribution centroide computation
......@@ -157,10 +159,19 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
double basinCentroid = latitudePresence.calculateMedian();
double effectiveCentroid = latitudeEffective.calculateMedian();
export[0][0] = southernId;
export[0][1] = northernId;
export[0][2] = basinCentroid;
export[0][3] = effectiveCentroid;
export[0][0] = "southern_basin_id";
export[0][1] = "southern_basin_name";
export[0][2] = "northern_basin_id";
export[0][3] = "northern_basin_name";
export[0][4] = "basin_centroid_latitude";
export[0][5] = "effective_centroid_latitude";
export[1][0] = String.valueOf(southernId);
export[1][1] = southernName;
export[1][2] = String.valueOf(northernId);
export[1][3] = northernName;
export[1][4] = String.valueOf(basinCentroid);
export[1][5] = String.valueOf(effectiveCentroid);
return export;
}
......
......@@ -110,11 +110,11 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
if (nbAgeForMale > 0.)
maleAgeMemories.get(riverBasin).push(meanAgeForMale / nbAgeForMale);
else
maleAgeMemories.get(riverBasin.getBasin_id()).push(Double.NaN);
maleAgeMemories.get(riverBasin).push(Double.NaN);
if (nbOfSpawners > 0.)
primiparousMemories.get(riverBasin.getBasin_id()).push(nbOfPrimiparous / nbOfSpawners);
primiparousMemories.get(riverBasin).push(nbOfPrimiparous / nbOfSpawners);
else
primiparousMemories.get(riverBasin.getBasin_id()).push(Double.NaN);
primiparousMemories.get(riverBasin).push(Double.NaN);
}
}
}
......@@ -124,7 +124,7 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
public String[][] exportToR() {
int nbBasin = femaleAgeMemories.size();
String[][] result = new String[nbBasin + 1][4];
String[][] result = new String[nbBasin + 1][5];
// headers
result[0][0] = "basin_id";
result[0][1] = "basin_name";
......
......@@ -16,7 +16,6 @@
*/
package analysis;
import java.util.Arrays;
import java.util.List;
import fr.cemagref.simaqualife.extensions.pilot.BatchRunner;
......@@ -27,8 +26,7 @@ public class EasyRun {
static Pilot pilot;
public static void runSimulation(String[] batchArgs, String outputfilename, String[] paramNames, double[] paramValues)
throws Exception {
public static void runSimulation(String[] batchArgs, String[] paramNames, double[] paramValues) throws Exception {
try {
pilot = new Pilot();
......@@ -97,25 +95,25 @@ public class EasyRun {
double[] parameterValues = new double[] { 10, 2, 0.7 };
runSimulation(batchArguments, "tsointsoin", parameterNames, parameterValues);
runSimulation(batchArguments, parameterNames, parameterValues);
System.out.println("\nAnalyseSpawnerFeatures");
System.out.println("basin_id, female_mean_age, male_mean_age, percent_primiparous");
System.out.println("\n== AnalyseSpawnerFeatures ==");
String[][] spawnerRunResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.8.exportToR");
for (String[] result : spawnerRunResults) {
System.out.println(Arrays.toString(result));
for (String[] record : spawnerRunResults) {
for (String value : record)
System.out.print(value + "\t");
System.out.println();
}
// System.out.println("\nAnalyseFishDistribution");
// System.out.println("southern_basin_id, northern_basin_id, basin_centroid_latitude,
// effective_centroid_latitude");
// double[][] distributionResults =
// getValuesFromAquanismGroupProcess("processes.processesEachStep.9.exportToR");
// for (double[] result : distributionResults) {
// System.out.println(Arrays.toString(result));
// }
System.out.println("\n== AnalyseFishDistribution ==");
String[][] distributionResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.9.exportToR");
for (String[] record : distributionResults) {
for (String value : record)
System.out.print(value + "\t");
System.out.println();
}
System.out.println("\nAnalyseLikelihoodOfPresence");
System.out.println("\n== AnalyseLikelihoodOfPresence ==");
System.out.println(getSingleValueFromAquanismGroupProcess("processes.processesAtEnd.0.getLogLikelihood"));
// List truc = getAListFromAquanismGroupProcess("processes.processesAtEnd.0.getRecords");
......
/**
* patrick
* @author Patrick Lambert
* @copyright Copyright (c) 2022, INRAE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*
*/
package analysis;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment