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

with writing of fluxes

parent dd3a6cb5
......@@ -227,6 +227,7 @@
<yearOfTheUpdate>0</yearOfTheUpdate>
<basinsToUpdateFile>data/input/reality/basinsToUpdate.csv</basinsToUpdateFile>
<outputPath>data/output/</outputPath>
<fileNameFluxes>nutrientFluxes</fileNameFluxes>
<processes>
<processesAtBegin>
<species.PopulateBasinNetworkWithANorthLimit>
......@@ -306,11 +307,13 @@
<maxNumberOfSuperIndividualPerReproduction>50.0
</maxNumberOfSuperIndividualPerReproduction>
<withDiagnose>false</withDiagnose>
<displayFluxesOnConsole>false</displayFluxesOnConsole>
</species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<species.MigrateToSea>
<seaMigrationSeason>SUMMER</seaMigrationSeason>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<displayFluxesOnConsole>false</displayFluxesOnConsole>
</species.MigrateToSea>
<environment.updateTemperatureInRealBasin>
......
......@@ -13,7 +13,10 @@ import fr.cemagref.simaqualife.kernel.Processes;
import fr.cemagref.simaqualife.pilot.Pilot;
import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
......@@ -101,6 +104,11 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
private String outputPath = "data/output/";
private String fileNameFluxes = "fluxes";
private transient BufferedWriter bWForFluxes;
private transient String sep;
/**
* map
* <key> basin name
......@@ -394,6 +402,35 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
kOpt = parameterSets.get(parameterSetLine-1).getFirst();
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(){
......
......@@ -8,6 +8,9 @@ import environment.RiverBasin;
import environment.Time;
import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
......@@ -15,7 +18,6 @@ import java.util.Map;
import miscellaneous.Duo;
import species.DiadromousFish.Stage;
import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = AquaNismsGroupProcess.class)
......@@ -23,6 +25,8 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
private Season seaMigrationSeason = Season.SUMMER;
private boolean displayFluxesOnConsole = true;
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new MigrateToSea()));
......@@ -34,7 +38,7 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
if (Time.getSeason(group.getPilot()) == seaMigrationSeason ){
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>();
List<Duo<DiadromousFish,Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish,Basin>>();
......@@ -43,11 +47,11 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
//Fish move to sea and compute the related export of nutrients
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()) {
totalOutputFluxes.put(nutrient, 0.);
}
totalOutputFluxes.put("biomass", 0.); //cration de la biomasse
totalOutputFluxes.put("biomass", 0.); //cration de la biomasse
if (fishes!=null) {
for (DiadromousFish fish : fishes) {
......@@ -68,13 +72,30 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
}
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 dplace les poissons dans le fichier MoveTo et on dnote 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();
}
}
}
}
}
}
\ No newline at end of file
package species;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
......@@ -59,9 +61,13 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
private double maxNumberOfSuperIndividualPerReproduction = 50.;
private boolean withDiagnose = true;
private boolean displayFluxesOnConsole = true;
private transient NormalGen genNormal;
private transient MortalityFunction mortalityFunction;
private enum fluxOrigin {AUTOCHTONOUS, ALLOCHTONOUS};
/**
* relationship between
* recruitment in number of juvenile on spawning grounds
......@@ -110,10 +116,10 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
if (fishInBasin != null){
//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
totalInputFluxes.put("autochtonous", new Hashtable < String, Double>());
totalInputFluxes.put("allochtonous", new Hashtable < String, Double>());
for (String origin: totalInputFluxes.keySet()) {
Map<fluxOrigin, Map<String, Double>> totalInputFluxes = new Hashtable<fluxOrigin, Map <String, Double>>(); //On crer la Map pour stocker les flux
totalInputFluxes.put(fluxOrigin.AUTOCHTONOUS, new Hashtable < String, Double>());
totalInputFluxes.put(fluxOrigin.ALLOCHTONOUS, new Hashtable < String, Double>());
for (fluxOrigin origin: totalInputFluxes.keySet()) {
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
totalInputFluxes.get(origin).put(nutrient, 0.); // ON MET A JOUR NOTRE map
}
......@@ -195,11 +201,11 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
// survival after reproduction (semelparity or iteroparity) of SI (change the amount of the SI)
survivalAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), survivalRateAfterReproduction);
double biomass = 0.;
String origin;
fluxOrigin origin;
if(fish.getBirthBasin()== riverBasin)
origin = "autochtonous";
origin = fluxOrigin.AUTOCHTONOUS;
else
origin = "allochtonous";
origin = fluxOrigin.ALLOCHTONOUS;
if (survivalAmount > 0) {// SUperindividu est encore vivant mais il perd des effectifs
//Export for fishes survived after spawning (survivalAmount) : excretion + gametes
......@@ -395,9 +401,28 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
}
deadFish.clear();
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 {
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