Commit 92003b21 authored by Lambert Patrick's avatar Lambert Patrick
Browse files

bug fixed to print N p fluxes

parent 75f75c35
......@@ -199,6 +199,7 @@
<yearOfTheUpdate>0</yearOfTheUpdate>
<basinsToUpdateFile>data/input/reality/basinsToUpdate.csv</basinsToUpdateFile>
<outputPath>data/output/</outputPath>
<minYearToWrite>1840</minYearToWrite>
<fileNameFluxes>nutrientFluxes</fileNameFluxes>
<lengthAtHatching>2.0</lengthAtHatching>
<linfVonBertForFemale>70.0</linfVonBertForFemale>
......@@ -272,11 +273,11 @@
<mortalityRateInOffshore>0.4</mortalityRateInOffshore>
</species.Survive>
<species.WriteEffectiveFluxes>
<species.WriteEffectivesFluxes>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<exportSeason>SPRING</exportSeason>
<fileNameOutput>effectiveFluxes</fileNameOutput>
</species.WriteEffectiveFluxes>
</species.WriteEffectivesFluxes>
<species.WriteBiomassFluxes>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
......@@ -323,7 +324,7 @@
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<fileName>fluxes</fileName>
</species.WriteImportNutrientFluxes>
<species.IdentifyPopulation>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<consoleDisplay>false</consoleDisplay>
......@@ -334,7 +335,7 @@
</years>
<fileNameOutput>JeuParam100_2100RCP85_A_essai</fileNameOutput>
</species.IdentifyPopulation>
<species.TypeTrajectoryCV>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<fileNameOutput>JeuParam100_2100RCP85_A_essai</fileNameOutput>
......
......@@ -95,6 +95,8 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
private String outputPath = "data/output/" ;
private long minYearToWrite = 1900;
//TODO:remove fileNameFluxes
private String fileNameFluxes = "fluxes";
......@@ -506,7 +508,8 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
if (targetedAgeForMaleSpawnerForFirstTime == null)
targetedAgeForMaleSpawnerForFirstTime = 4.5;
this.nutrientRoutine.getNutrientFluxesCollection().setBasinNames(this.getEnvironment().getRiverBasinNames());
//this.nutrientRoutine.getNutrientFluxesCollection().setBasinNames(this.getEnvironment().getRiverBasinNames());
this.nutrientRoutine.createNutrienFluxesCollection(this.getEnvironment().getRiverBasinNames());
}
......@@ -665,6 +668,13 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
}
/**
* @return the minYearToWrite
*/
public long getMinYearToWrite() {
return minYearToWrite;
}
// ================================================================
// statictis for calibration
// ================================================================
......
......@@ -29,6 +29,7 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
......@@ -158,7 +159,10 @@ public class NutrientRoutine {
}
public void createNutrienFluxesCollection(String[] basinNames) {
nutrientFluxesCollection = new NutrientFluxesCollection();
nutrientFluxesCollection.setBasinNames(basinNames);
}
public NutrientFluxesCollection getNutrientFluxesCollection() {
return nutrientFluxesCollection;
......@@ -578,11 +582,11 @@ public class NutrientRoutine {
if(!fluxesCollection.containsKey(year)) {
Map <String, Map <String, Map <String, Double>>> nutrientsMap = new HashMap <String, Map <String, Map <String, Double>>>();
Map <String, Map <String, Map <String, Double>>> nutrientsMap = new TreeMap <String, Map <String, Map <String, Double>>>();
for (String nutrientOfInterest : nutrientsOfInterest) {
Map <String, Map <String, Double>> originsMap = new HashMap <String, Map <String, Double>>();
Map <String, Map <String, Double>> originsMap = new TreeMap <String, Map <String, Double>>();
for (String originName : basinNames) {
Map <String, Double> destinationsMap = new HashMap <String, Double>();
......
......@@ -113,7 +113,8 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
basinList.add("Meuse");
basinList. add("Rhine");
System.out.print(group.getPilot().getCurrentTime() + " - ");
if (displayFluxesOnConsole == true)
System.out.print(group.getPilot().getCurrentTime() + " - ");
for(RiverBasin riverBasin : group.getEnvironment().getRiverBasins()){
......@@ -431,12 +432,13 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
}
// display info from a catchment list
if (basinList.contains(riverBasin.getName()) ) {
System.out.print(riverBasin.getName() + ": " + numberOfFemaleSpawners + " + "+ numberOfMaleSpawners +
" -> "+ numberOfRecruit + "\t") ;
if (displayFluxesOnConsole == true) {
if (basinList.contains(riverBasin.getName()) ) {
System.out.print(riverBasin.getName() + ": " + numberOfFemaleSpawners + " + "+ numberOfMaleSpawners +
" -> "+ numberOfRecruit + "\t") ;
}
}
// Creation of new superFish
if (numberOfRecruit > 0){
long numberOfsuperIndividual, effectiveAmount, remainingFish;
......@@ -552,7 +554,8 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
riverBasin.getSpawnerOrigins().push(spawnerOriginsDuringReproduction);
//System.out.println(" AFTER " +riverBasin.getSpawnerOrigins().keySet());
}
System.out.println();
if (displayFluxesOnConsole == true)
System.out.println();
// --------------------------------------------------------------------------------------------------
// update the observers
......
......@@ -57,11 +57,15 @@ public class Survive extends AquaNismsGroupProcess<DiadromousFish, DiadromousFis
totalInputFluxes.get(origin).put("biomass",0.);
}
double sumNGuadalquivir = 0.;
for(Basin basin : group.getEnvironment().getBasins()){
//System.out.print(basin.getName());
if (basin.getFishs(group)!=null) {
//System.out.println(" y a des poissons");
for(DiadromousFish fish : basin.getFishs(group)){
survivalProbability = 1.;
//Compute the survival probability according to the fish position
if(fish.getPosition().getType() == TypeBassin.RIVER && fish.isMature()){ //Survive in river before spawning
......@@ -114,18 +118,28 @@ public class Survive extends AquaNismsGroupProcess<DiadromousFish, DiadromousFis
group.getNutrientRoutine().getNutrientFluxesCollection().
put(Time.getYear(group.getPilot()), nutrient, fish.getBirthBasin().getName(), basin.getName(), aFluxForDeadFishBeforeSpawning.get(nutrient) * deathAmount);
}
/*
* if
* (basin.getName().equalsIgnoreCase("Guadalquivir")
* ) { sumNGuadalquivir +=
* aFluxForDeadFishBeforeSpawning.get("N") *
* deathAmount;
* System.out.println(Time.getYear(group.getPilot())
* + " : " + sumNGuadalquivir); }
*/
}
}
}//end on loop of fish
}
for (DiadromousFish fish : deadFish){
group.removeAquaNism(fish);
}
} //end loop on basin
}//end of doprocess
}//end of class
......
......@@ -74,7 +74,7 @@ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, Di
}
try {
if (Time.getSeason(pilot) == exportSeason & Time.getYear(pilot)>1900) {
if (Time.getSeason(pilot) == exportSeason & Time.getYear(pilot) >= group.getMinYearToWrite()) {
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
......
......@@ -85,8 +85,9 @@ public class WriteEffectivesFluxes extends AquaNismsGroupProcess<DiadromousFish,
}
}
try {
if (Time.getSeason(pilot) == exportSeason & Time.getYear(pilot)>1900) {
if (Time.getSeason(pilot) == exportSeason & Time.getYear(pilot) >= group.getMinYearToWrite()) {
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
//Create the map to get the abundance in each birth basin
......@@ -116,8 +117,10 @@ public class WriteEffectivesFluxes extends AquaNismsGroupProcess<DiadromousFish,
bW.write("\n");
}
}
if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1)
if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1) {
bW.flush();
bW.close();
}
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -4,7 +4,11 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
......@@ -27,7 +31,7 @@ public class WriteImportNutrientFluxes extends AquaNismsGroupProcess<DiadromousF
public void doProcess(DiadromousFishGroup group) {
BufferedWriter bW;
String outputPath = "data/output/" ;
String sep = ";";
new File(outputPath + fileName).getParentFile().mkdirs();
......@@ -45,24 +49,29 @@ public class WriteImportNutrientFluxes extends AquaNismsGroupProcess<DiadromousF
Map<Long, Map <String, Map<String, Map<String, Double>>>> fluxesCollection = group.getNutrientRoutine().getNutrientFluxesCollection().getFluxesCollection();
for (long year : fluxesCollection.keySet()) {
Map <String, Map<String, Map<String, Double>>> yearsMap = fluxesCollection.get(year);
for (String nutrient : yearsMap.keySet()) {
// to iterate on sorted years
List<Long> years = new ArrayList<Long>(fluxesCollection.keySet());
Collections.sort(years);
Map<String, Map<String, Double>> originsMap = yearsMap.get(nutrient);
for (String originBasinName : originsMap.keySet()) {
for (long year :years) {
if (year >= group.getMinYearToWrite()) {
Map <String, Map<String, Map<String, Double>>> yearsMap = fluxesCollection.get(year);
Map<String, Double> destinationsMap = originsMap.get(originBasinName);
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
for (String destinationBasinName : destinationsMap.keySet()) {
Map<String, Map<String, Double>> originsMap = yearsMap.get(nutrient);
for (String originBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(year+ sep+ nutrient + sep + originBasinName );
Map<String, Double> destinationsMap = originsMap.get(originBasinName);
Double aFlux = destinationsMap.get(destinationBasinName);
for (String destinationBasinName : group.getEnvironment().getRiverBasinNames()) {
Double aFlux = destinationsMap.get(destinationBasinName);
bW.write( sep + aFlux);
}
bW.write(year + sep+ nutrient + sep + originBasinName + sep + aFlux + "\n");
}
bW.write("\n");
}
}
}
}
......
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