diff --git a/data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml b/data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml index 09400c58e601c4fd04d96c0c69a19638d1266c97..177e4b4fd382c5953d1e1f31ba78c3474ed47433 100644 --- a/data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml +++ b/data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml @@ -283,6 +283,12 @@ <!--<species.WriteEffectiveAndBiomassImportFluxes> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> <exportSeason>SPRING</exportSeason> <fileNameOutput>effectiveBiomassFluxesBeforeReproduction</fileNameOutput> </species.WriteEffectiveAndBiomassImportFluxes> --> + <species.AnalyseSpawnerFeatures> + <synchronisationMode>ASYNCHRONOUS</synchronisationMode> + <analysisSeason>SPRING</analysisSeason> + <memorySize>30</memorySize> + </species.AnalyseSpawnerFeatures> + <species.ReproduceAndSurviveAfterReproductionWithDiagnose> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> <reproductionSeason>SPRING</reproductionSeason> @@ -307,12 +313,10 @@ <species.AnalyseFishDistribution> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> - <fishDistributionAnalysisSeason>SPRING</fishDistributionAnalysisSeason> - <fishDistributionAnalysisStartYear>1820</fishDistributionAnalysisStartYear> - <fishDistributionAnalysisEndYear>1850</fishDistributionAnalysisEndYear> + <analysisSeason>SPRING</analysisSeason> <minimumRecruitsForPopulatedBasin>50</minimumRecruitsForPopulatedBasin> </species.AnalyseFishDistribution> - + <species.MigrateFromRiverToInshore> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> <migrationSeasonToReachInshore>SPRING</migrationSeasonToReachInshore> diff --git a/src/main/java/miscellaneous/EasyRun.java b/src/main/java/miscellaneous/EasyRun.java index 3a889a14eb9b898be5eced2d2e25e3ae5c25d535..2993abe42980a0ab5807bf23603179f67000d4fc 100644 --- a/src/main/java/miscellaneous/EasyRun.java +++ b/src/main/java/miscellaneous/EasyRun.java @@ -81,14 +81,19 @@ public class EasyRun { + "-env data/input/northeastamerica/RIOBNneaBasins_Rjava.xml " + "-observers data/input/northeastamerica/RIO_obs_empty.xml").split("\\ "); - String[] parameterNames = new String[] { "processes.processesEachStep.8.tempMinRep", - "processes.processesEachStep.8.ratioS95_S50", "processes.processesEachStep.6.pHomingAfterEquil" }; + String[] parameterNames = new String[] { "processes.processesEachStep.9.tempMinRep", + "processes.processesEachStep.9.ratioS95_S50", "processes.processesEachStep.6.pHomingAfterEquil" }; double[] parameterValues = new double[] { 10, 2, 0.7 }; runSimulation(batchArguments, "tsointsoin", parameterNames, parameterValues); - double[][] distributionResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.9.exportToR"); + double[][] spawnerRunResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.8.exportToR"); + for (double[] result : spawnerRunResults) { + System.out.println(Arrays.toString(result)); + } + + double[][] distributionResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.10.exportToR"); for (double[] result : distributionResults) { System.out.println(Arrays.toString(result)); } diff --git a/src/main/java/species/AnalyseFishDistribution.java b/src/main/java/species/AnalyseFishDistribution.java index 4ba0ecf382aa49a1b981541b00ffbda65d6e5885..4d8d337cda5889b0202a582d58fdb48444f2b9fb 100644 --- a/src/main/java/species/AnalyseFishDistribution.java +++ b/src/main/java/species/AnalyseFishDistribution.java @@ -27,6 +27,7 @@ import com.thoughtworks.xstream.io.xml.DomDriver; import environment.RIOBasinNetwork; import environment.RiverBasin; +import environment.Time.Season; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.pilot.Pilot; import miscellaneous.TreeMapForCentile; @@ -37,6 +38,8 @@ import observer.ObservableRecord; */ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { + private Season analysisSeason = Season.SPRING; + /** * The minimum number of recruits to consider a basin as populated * @@ -71,62 +74,64 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis if (records == null) initTransientParameters(group.getPilot()); - // initialise the distribution range - double southernEdge = northernLimit; - double northernEdge = southernLimit; - int southernId = -1; - int northernId = -1; - String southernName = ""; - String northernName = ""; - // initialise for centroid - TreeMapForCentile latitudeEffective = new TreeMapForCentile(); - TreeMapForCentile latitudePresence = new TreeMapForCentile(); - - for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { - - if (riverBasin.getLastRecruitments().getMean() > minimumRecruitsForPopulatedBasin) { - // the river basin is consdered populated - - // NOTE : recruiit number is calulated after thermal tolerance impact - // (which is intreaged in the stock-recruitment relationship) - - // southern edge - if (riverBasin.getLatitude() < southernEdge) { - // the basin is the new southern edge - southernEdge = riverBasin.getLatitude(); - southernId = riverBasin.getBasin_id(); - southernName = riverBasin.getName(); - } - - // northern edge - if (riverBasin.getLatitude() > southernEdge) { - // the basin is the new northern edge - northernEdge = riverBasin.getLatitude(); - northernId = riverBasin.getBasin_id(); - northernName = riverBasin.getName(); + if (group.getEnvironment().getTime().getSeason(group.getPilot()) == analysisSeason) { + // initialise the distribution range + double southernEdge = northernLimit; + double northernEdge = southernLimit; + int southernId = -1; + int northernId = -1; + String southernName = ""; + String northernName = ""; + // initialise for centroid + TreeMapForCentile latitudeEffective = new TreeMapForCentile(); + TreeMapForCentile latitudePresence = new TreeMapForCentile(); + + for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { + + if (riverBasin.getLastRecruitments().getMean() > minimumRecruitsForPopulatedBasin) { + // the river basin is consdered populated + + // NOTE : recruiit number is calulated after thermal tolerance impact + // (which is intreaged in the stock-recruitment relationship) + + // southern edge + if (riverBasin.getLatitude() < southernEdge) { + // the basin is the new southern edge + southernEdge = riverBasin.getLatitude(); + southernId = riverBasin.getBasin_id(); + southernName = riverBasin.getName(); + } + + // northern edge + if (riverBasin.getLatitude() > southernEdge) { + // the basin is the new northern edge + northernEdge = riverBasin.getLatitude(); + northernId = riverBasin.getBasin_id(); + northernName = riverBasin.getName(); + } + + // for distribution centroide computation + latitudePresence.putWithAdding(riverBasin.getLatitude(), 1L); + long effective = ((Double) riverBasin.getLastSpawnerNumbersBeforeReproduction().getMean()).longValue(); + latitudeEffective.putWithAdding(riverBasin.getLatitude(), effective); } - - // for distribution centroide computation - latitudePresence.putWithAdding(riverBasin.getLatitude(), 1L); - long effective = ((Double) riverBasin.getLastSpawnerNumbersBeforeReproduction().getMean()).longValue(); - latitudeEffective.putWithAdding(riverBasin.getLatitude(), effective); } - } - // if the universe is empty - if (southernEdge == northernLimit & northernEdge == southernLimit) { - southernEdge = (northernLimit + southernLimit) / 2.; - northernEdge = southernEdge; - } + // if the universe is empty + if (southernEdge == northernLimit & northernEdge == southernLimit) { + southernEdge = (northernLimit + southernLimit) / 2.; + northernEdge = southernEdge; + } - // distribution centroids computation - double basinCentroid = latitudePresence.calculateMedian(); - double effectiveCentroid = latitudeEffective.calculateMedian(); + // distribution centroids computation + double basinCentroid = latitudePresence.calculateMedian(); + double effectiveCentroid = latitudeEffective.calculateMedian(); - // add a record - FishDistributionRecord record = new FishDistributionRecord(southernId, southernName, southernEdge, northernId, - northernName, northernEdge, basinCentroid, effectiveCentroid); + // add a record + FishDistributionRecord record = new FishDistributionRecord(southernId, southernName, southernEdge, northernId, + northernName, northernEdge, basinCentroid, effectiveCentroid); - records.add(record); + records.add(record); + } } diff --git a/src/main/java/species/AnalyseSpawnerFeatures.java b/src/main/java/species/AnalyseSpawnerFeatures.java index 57cc98119dc907221a9efa3639506a969ca8f3dd..8640ceda8845d830ca624ca0d260782bc40a4483 100644 --- a/src/main/java/species/AnalyseSpawnerFeatures.java +++ b/src/main/java/species/AnalyseSpawnerFeatures.java @@ -27,6 +27,7 @@ import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; import environment.RiverBasin; +import environment.Time.Season; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.pilot.Pilot; import miscellaneous.QueueMemory; @@ -38,6 +39,7 @@ import species.DiadromousFish.Gender; public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { private int memorySize = 30; + private Season analysisSeason = Season.SPRING; private transient Map<Integer, QueueMemory<Double>> femaleAgeMemories; private transient Map<Integer, QueueMemory<Double>> maleAgeMemories; @@ -56,47 +58,62 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish // first passage if (femaleAgeMemories == null) { femaleAgeMemories = new HashMap<Integer, QueueMemory<Double>>(); + maleAgeMemories = new HashMap<Integer, QueueMemory<Double>>(); + primiparousMemories = new HashMap<Integer, QueueMemory<Double>>(); for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { - femaleAgeMemories.put(riverBasin.getId(), new QueueMemory<>(memorySize)); + femaleAgeMemories.put(riverBasin.getBasin_id(), new QueueMemory<>(memorySize)); + maleAgeMemories.put(riverBasin.getBasin_id(), new QueueMemory<>(memorySize)); + primiparousMemories.put(riverBasin.getBasin_id(), new QueueMemory<>(memorySize)); } } - for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { + if (group.getEnvironment().getTime().getSeason(group.getPilot()) == analysisSeason) { + for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { - if (riverBasin.getFishs(group) != null) { + if (riverBasin.getFishs(group) != null) { - double meanAgeForFemale = 0.; - double nbAgeForFemale = 0.; + double meanAgeForFemale = 0.; + double nbAgeForFemale = 0.; - double meanAgeForMale = 0.; - double nbAgeForMale = 0.; + double meanAgeForMale = 0.; + double nbAgeForMale = 0.; - double nbOfSpawners = 0.; - double nbOfPrimiparous = 0.; + double nbOfSpawners = 0.; + double nbOfPrimiparous = 0.; - for (DiadromousFish fish : riverBasin.getFishs(group)) { - if (fish.isMature()) { + for (DiadromousFish fish : riverBasin.getFishs(group)) { + if (fish.isMature()) { - // mean age - if (fish.getGender() == Gender.FEMALE) { - meanAgeForFemale += fish.getAge() * fish.getAmount(); - nbAgeForFemale += fish.getAmount(); - } else if (fish.getGender() == Gender.MALE) { - meanAgeForMale += fish.getAge() * fish.getAmount(); - nbAgeForMale += fish.getAmount(); - } + // mean age + if (fish.getGender() == Gender.FEMALE) { + meanAgeForFemale += fish.getAge() * fish.getAmount(); + nbAgeForFemale += fish.getAmount(); + } else if (fish.getGender() == Gender.MALE) { + meanAgeForMale += fish.getAge() * fish.getAmount(); + nbAgeForMale += fish.getAmount(); + } - // primiparous - nbOfSpawners += fish.getAmount(); - if (fish.getNumberOfReproduction() == 0) - nbOfPrimiparous += fish.getAmount(); + // primiparous + nbOfSpawners += fish.getAmount(); + if (fish.getNumberOfReproduction() == 0) + nbOfPrimiparous += fish.getAmount(); + } } + // add value in the queues + if (nbAgeForFemale > 0.) + femaleAgeMemories.get(riverBasin.getBasin_id()).push(meanAgeForFemale / nbAgeForFemale); + else + femaleAgeMemories.get(riverBasin.getBasin_id()).push(Double.NaN); + if (nbAgeForMale > 0.) + maleAgeMemories.get(riverBasin.getBasin_id()).push(meanAgeForMale / nbAgeForMale); + else + maleAgeMemories.get(riverBasin.getBasin_id()).push(Double.NaN); + if (nbOfSpawners > 0.) + primiparousMemories.get(riverBasin.getBasin_id()).push(nbOfPrimiparous / nbOfSpawners); + else + primiparousMemories.get(riverBasin.getBasin_id()).push(Double.NaN); } - // add value in the quues - femaleAgeMemories.get(riverBasin.getBasin_id()).add(meanAgeForFemale / nbAgeForFemale); - maleAgeMemories.get(riverBasin.getBasin_id()).add(meanAgeForMale / nbAgeForMale); - primiparousMemories.get(riverBasin.getBasin_id()).add(nbOfPrimiparous / nbOfSpawners); } } } diff --git a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java index 427ab7f411a1d9d0589ebe1abfc4cce37ece4d8a..8904f0025347fb428de26461623d03a04f0f97f8 100644 --- a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java +++ b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java @@ -126,7 +126,7 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG // before the party !!!! double fluxBefore = riverBasin.getSpawnerNumberPerGroup(group); - riverBasin.getLastSpawnerNumbersBeforeReproduction().add(fluxBefore); + riverBasin.getLastSpawnerNumbersBeforeReproduction().push(fluxBefore); double b, c, alpha, beta, amountPerSuperIndividual, S95, S50; double numberOfFemaleSpawners = 0.;