Commit 55e4f229 authored by Lambert Patrick's avatar Lambert Patrick
Browse files

with writing of fluxes

parent dd3a6cb5
...@@ -227,6 +227,7 @@ ...@@ -227,6 +227,7 @@
<yearOfTheUpdate>0</yearOfTheUpdate> <yearOfTheUpdate>0</yearOfTheUpdate>
<basinsToUpdateFile>data/input/reality/basinsToUpdate.csv</basinsToUpdateFile> <basinsToUpdateFile>data/input/reality/basinsToUpdate.csv</basinsToUpdateFile>
<outputPath>data/output/</outputPath> <outputPath>data/output/</outputPath>
<fileNameFluxes>nutrientFluxes</fileNameFluxes>
<processes> <processes>
<processesAtBegin> <processesAtBegin>
<species.PopulateBasinNetworkWithANorthLimit> <species.PopulateBasinNetworkWithANorthLimit>
...@@ -306,11 +307,13 @@ ...@@ -306,11 +307,13 @@
<maxNumberOfSuperIndividualPerReproduction>50.0 <maxNumberOfSuperIndividualPerReproduction>50.0
</maxNumberOfSuperIndividualPerReproduction> </maxNumberOfSuperIndividualPerReproduction>
<withDiagnose>false</withDiagnose> <withDiagnose>false</withDiagnose>
<displayFluxesOnConsole>false</displayFluxesOnConsole>
</species.ReproduceAndSurviveAfterReproductionWithDiagnose> </species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<species.MigrateToSea> <species.MigrateToSea>
<seaMigrationSeason>SUMMER</seaMigrationSeason> <seaMigrationSeason>SUMMER</seaMigrationSeason>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode> <synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<displayFluxesOnConsole>false</displayFluxesOnConsole>
</species.MigrateToSea> </species.MigrateToSea>
<environment.updateTemperatureInRealBasin> <environment.updateTemperatureInRealBasin>
......
...@@ -13,7 +13,10 @@ import fr.cemagref.simaqualife.kernel.Processes; ...@@ -13,7 +13,10 @@ import fr.cemagref.simaqualife.kernel.Processes;
import fr.cemagref.simaqualife.pilot.Pilot; import fr.cemagref.simaqualife.pilot.Pilot;
import java.awt.Color; import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -65,7 +68,7 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe ...@@ -65,7 +68,7 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
private NutrientRoutine nutrientRoutine; private NutrientRoutine nutrientRoutine;
public String fileNameInputForInitialObservation = "data/input/reality/Obs1900.csv"; public String fileNameInputForInitialObservation = "data/input/reality/Obs1900.csv";
/** /**
* centile to calucale the range of species distribution * centile to calucale the range of species distribution
* @unit * @unit
...@@ -100,6 +103,11 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe ...@@ -100,6 +103,11 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
private String basinsToUpdateFile = "data/input/reality/basinsToUpdate.csv"; private String basinsToUpdateFile = "data/input/reality/basinsToUpdate.csv";
private String outputPath = "data/output/"; private String outputPath = "data/output/";
private String fileNameFluxes = "fluxes";
private transient BufferedWriter bWForFluxes;
private transient String sep;
/** /**
* map * map
...@@ -394,6 +402,35 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe ...@@ -394,6 +402,35 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
kOpt = parameterSets.get(parameterSetLine-1).getFirst(); kOpt = parameterSets.get(parameterSetLine-1).getFirst();
tempMinRep = parameterSets.get(parameterSetLine-1).getSecond(); tempMinRep = parameterSets.get(parameterSetLine-1).getSecond();
} }
// open an bufferad writer to export fluxes
if (fileNameFluxes != null){
sep = ";";
new File(this.outputPath +fileNameFluxes).getParentFile().mkdirs();
try {
bWForFluxes = new BufferedWriter(new FileWriter(new File(this.outputPath+
fileNameFluxes +this.getSimulationId()+ ".csv")));
bWForFluxes.write("timestep"+sep+"year"+sep+"season"+sep+"basin"
+sep+"fluxType"+sep+"origine"+sep+"biomass");
for (String nutrient : nutrientRoutine.getNutrientsOfInterest()) {
bWForFluxes.write(sep+nutrient);
}
bWForFluxes.write("\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @return the bWForFluxes
*/
public BufferedWriter getbWForFluxes() {
return bWForFluxes;
} }
public double getKOpt(){ public double getKOpt(){
......
...@@ -8,6 +8,9 @@ import environment.RiverBasin; ...@@ -8,6 +8,9 @@ import environment.RiverBasin;
import environment.Time; import environment.Time;
import environment.Time.Season; import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
...@@ -15,7 +18,6 @@ import java.util.Map; ...@@ -15,7 +18,6 @@ import java.util.Map;
import miscellaneous.Duo; import miscellaneous.Duo;
import species.DiadromousFish.Stage; import species.DiadromousFish.Stage;
import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = AquaNismsGroupProcess.class) @ServiceProvider(service = AquaNismsGroupProcess.class)
...@@ -23,6 +25,8 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo ...@@ -23,6 +25,8 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
private Season seaMigrationSeason = Season.SUMMER; private Season seaMigrationSeason = Season.SUMMER;
private boolean displayFluxesOnConsole = true;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())) System.out.println((new XStream(new DomDriver()))
.toXML(new MigrateToSea())); .toXML(new MigrateToSea()));
...@@ -33,48 +37,65 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo ...@@ -33,48 +37,65 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
if (Time.getSeason(group.getPilot()) == seaMigrationSeason ){ if (Time.getSeason(group.getPilot()) == seaMigrationSeason ){
Basin destination; Basin destination;
//On crer la Map pour stocker les flux d'export //On crer la Map pour stocker les flux d'export
Map<String, Double> totalOutputFluxes = new Hashtable<String, Double>(); Map<String, Double> totalOutputFluxes = new Hashtable<String, Double>();
List<Duo<DiadromousFish,Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish,Basin>>(); List<Duo<DiadromousFish,Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish,Basin>>();
for (int i = 0; i < group.getEnvironment().getRiverBasins().length; i++) { for (int i = 0; i < group.getEnvironment().getRiverBasins().length; i++) {
RiverBasin basin = group.getEnvironment().getRiverBasins()[i]; RiverBasin basin = group.getEnvironment().getRiverBasins()[i];
//Fish move to sea and compute the related export of nutrients //Fish move to sea and compute the related export of nutrients
List<DiadromousFish> fishes = basin.getFishs(group); List<DiadromousFish> fishes = basin.getFishs(group);
// ON r-initialise notre map pour chauqe bassin // ON r-initialise notre map pour chauqe bassin
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
totalOutputFluxes.put(nutrient, 0.); totalOutputFluxes.put(nutrient, 0.);
} }
totalOutputFluxes.put("biomass", 0.); //cration de la biomasse totalOutputFluxes.put("biomass", 0.); //cration de la biomasse
if (fishes!=null) { if (fishes!=null) {
for (DiadromousFish fish : fishes) { for (DiadromousFish fish : fishes) {
destination = group.getEnvironment().getAssociatedSeaBasin(fish.getPosition()); destination = group.getEnvironment().getAssociatedSeaBasin(fish.getPosition());
fishesToMove.add(new Duo<DiadromousFish, Basin>(fish, destination)); //Mentionne la sortie d'un poisson de la boucle fishesToMove.add(new Duo<DiadromousFish, Basin>(fish, destination)); //Mentionne la sortie d'un poisson de la boucle
double biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount(); double biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount();
if (fish.getStage()==Stage.IMMATURE) { if (fish.getStage()==Stage.IMMATURE) {
Map <String, Double> aFluxExportedByJuveniles= group.getNutrientRoutine().computeNutrientsExportForJuveniles(fish); Map <String, Double> aFluxExportedByJuveniles= group.getNutrientRoutine().computeNutrientsExportForJuveniles(fish);
for (String nutrient: aFluxExportedByJuveniles.keySet()) { for (String nutrient: aFluxExportedByJuveniles.keySet()) {
totalOutputFluxes.put(nutrient,totalOutputFluxes.get(nutrient) + aFluxExportedByJuveniles.get(nutrient) * fish.getAmount()); totalOutputFluxes.put(nutrient,totalOutputFluxes.get(nutrient) + aFluxExportedByJuveniles.get(nutrient) * fish.getAmount());
} }
totalOutputFluxes.put("biomass", totalOutputFluxes.get("biomass") + biomass); totalOutputFluxes.put("biomass", totalOutputFluxes.get("biomass") + biomass);
} }
} }
} }
for (Duo<DiadromousFish,Basin> duo : fishesToMove) { for (Duo<DiadromousFish,Basin> duo : fishesToMove) {
duo.getFirst().moveTo(group.getPilot(), duo.getSecond(), group); //on dplace les poissons dans le fichier MoveTo et on dnote la destination du poisson. duo.getFirst().moveTo(group.getPilot(), duo.getSecond(), group); //on d�place les poissons dans le fichier MoveTo et on d�note la destination du poisson.
}
if (displayFluxesOnConsole)
System.out.println(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) + ";EXPORT;"
+ basin.getName() + "; " + totalOutputFluxes);
BufferedWriter bW = group.getbWForFluxes();
if ( bW != null) {
try {
bW.write(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot())
+";"+ basin.getName() + ";IMPORT; NONE");
bW.write(";" + totalOutputFluxes.get("biomass"));
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
bW.write(";" + totalOutputFluxes.get(nutrient));
}
bW.write("\n");
} catch (IOException e) {
e.printStackTrace();
}
} }
System.out.println(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) + ";EXPORT;"
+ basin.getName() + "; " + totalOutputFluxes);
} }
} }
} }
} }
\ No newline at end of file
package species; package species;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -59,9 +61,13 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -59,9 +61,13 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
private double maxNumberOfSuperIndividualPerReproduction = 50.; private double maxNumberOfSuperIndividualPerReproduction = 50.;
private boolean withDiagnose = true; private boolean withDiagnose = true;
private boolean displayFluxesOnConsole = true;
private transient NormalGen genNormal; private transient NormalGen genNormal;
private transient MortalityFunction mortalityFunction; private transient MortalityFunction mortalityFunction;
private enum fluxOrigin {AUTOCHTONOUS, ALLOCHTONOUS};
/** /**
* relationship between * relationship between
* recruitment in number of juvenile on spawning grounds * recruitment in number of juvenile on spawning grounds
...@@ -110,10 +116,10 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -110,10 +116,10 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
if (fishInBasin != null){ if (fishInBasin != null){
//Initiate the total fluxes for this basin //Initiate the total fluxes for this basin
Map<String, Map<String, Double>> totalInputFluxes = new Hashtable<String, Map <String, Double>>(); //On crer la Map pour stocker les flux Map<fluxOrigin, Map<String, Double>> totalInputFluxes = new Hashtable<fluxOrigin, Map <String, Double>>(); //On crer la Map pour stocker les flux
totalInputFluxes.put("autochtonous", new Hashtable < String, Double>()); totalInputFluxes.put(fluxOrigin.AUTOCHTONOUS, new Hashtable < String, Double>());
totalInputFluxes.put("allochtonous", new Hashtable < String, Double>()); totalInputFluxes.put(fluxOrigin.ALLOCHTONOUS, new Hashtable < String, Double>());
for (String origin: totalInputFluxes.keySet()) { for (fluxOrigin origin: totalInputFluxes.keySet()) {
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
totalInputFluxes.get(origin).put(nutrient, 0.); // ON MET A JOUR NOTRE map totalInputFluxes.get(origin).put(nutrient, 0.); // ON MET A JOUR NOTRE map
} }
...@@ -195,11 +201,11 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -195,11 +201,11 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
// survival after reproduction (semelparity or iteroparity) of SI (change the amount of the SI) // survival after reproduction (semelparity or iteroparity) of SI (change the amount of the SI)
survivalAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), survivalRateAfterReproduction); survivalAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), survivalRateAfterReproduction);
double biomass = 0.; double biomass = 0.;
String origin; fluxOrigin origin;
if(fish.getBirthBasin()== riverBasin) if(fish.getBirthBasin()== riverBasin)
origin = "autochtonous"; origin = fluxOrigin.AUTOCHTONOUS;
else else
origin = "allochtonous"; origin = fluxOrigin.ALLOCHTONOUS;
if (survivalAmount > 0) {// SUperindividu est encore vivant mais il perd des effectifs if (survivalAmount > 0) {// SUperindividu est encore vivant mais il perd des effectifs
//Export for fishes survived after spawning (survivalAmount) : excretion + gametes //Export for fishes survived after spawning (survivalAmount) : excretion + gametes
...@@ -395,9 +401,28 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -395,9 +401,28 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
} }
deadFish.clear(); deadFish.clear();
System.out.println(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) + ";IMPORT;"
+ riverBasin.getName() + "; " + totalInputFluxes);
if (displayFluxesOnConsole)
System.out.println(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) + ";IMPORT;"
+ riverBasin.getName() + "; " + totalInputFluxes);
BufferedWriter bW = group.getbWForFluxes();
if ( bW != null) {
try {
for (fluxOrigin origin : totalInputFluxes.keySet()) {
bW.write(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot())
+";"+ riverBasin.getName() + ";IMPORT;"+origin);
bW.write(";" + totalInputFluxes.get(origin).get("biomass"));
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
bW.write(";" + totalInputFluxes.get(origin).get(nutrient));
}
bW.write("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
} }
else { else {
riverBasin.setYearOfLastNulRep(Time.getYear(group.getPilot())); riverBasin.setYearOfLastNulRep(Time.getYear(group.getPilot()));
......
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