Commit b80a5ab7 authored by Lambert Patrick's avatar Lambert Patrick
Browse files

writing nutrient export fluxes

parent 11cbd429
......@@ -214,9 +214,9 @@
<processesEachStep>
<environment.InformTime>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<consoleDisplay>true</consoleDisplay>
<consoleDisplay>true</consoleDisplay>
</environment.InformTime>
<species.PlopProcess>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<temporisation>0</temporisation>
......@@ -280,7 +280,7 @@
<exportSeason>SPRING</exportSeason>
<fileNameOutput>effectiveBiomassFluxesBeforeReproduction</fileNameOutput>
</species.WriteEffectiveAndBiomassFluxes>
<species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<reproductionSeason>SPRING</reproductionSeason>
......@@ -321,21 +321,10 @@
<fileName>fluxes</fileName>
</species.WriteImportNutrientFluxes>
<species.IdentifyPopulation>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<consoleDisplay>false</consoleDisplay>
<fluxesSeason>SPRING</fluxesSeason>
<years>
<long>2000</long>
<long>2100</long>
</years>
<fileNameOutput>JeuParam100_2100RCP85_A_essai</fileNameOutput>
</species.IdentifyPopulation>
<species.TypeTrajectoryCV>
<species.WriteNutrientExportFluxes>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<fileNameOutput>JeuParam100_2100RCP85_A_essai</fileNameOutput>
</species.TypeTrajectoryCV>
<fileName>nutrientExportFluxes</fileName>
</species.WriteNutrientExportFluxes>
</processesAtEnd>
</processes>
......
......@@ -42,8 +42,8 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
Map<String, Double> totalOutputFluxes = new Hashtable<String, Double>();
List<Duo<DiadromousFish,Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish,Basin>>();
for (int i = 0; i < group.getEnvironment().getRiverBasins().length; i++) {
RiverBasin basin = group.getEnvironment().getRiverBasins()[i];
for (RiverBasin basin : group.getEnvironment().getRiverBasins()) {
//Fish move to sea and compute the related export of nutrients
List<DiadromousFish> fishes = basin.getFishs(group);
......@@ -64,6 +64,8 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo
Map <String, Double> aFluxExportedByJuveniles= group.getNutrientRoutine().computeNutrientsExportForJuveniles(fish);
for (String nutrient: aFluxExportedByJuveniles.keySet()) {
totalOutputFluxes.put(nutrient,totalOutputFluxes.get(nutrient) + aFluxExportedByJuveniles.get(nutrient) * fish.getAmount());
group.getNutrientRoutine().getNutrientExportFluxesCollection().put(Time.getYear(group.getPilot()), nutrient, basin.getName(), aFluxExportedByJuveniles.get(nutrient) * fish.getAmount());
}
totalOutputFluxes.put("biomass", totalOutputFluxes.get("biomass") + biomass);
......
package species;
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;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
public class WriteNutrientExportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private String fileName= "nutrientExportFluxes";
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new WriteNutrientExportFluxes()));
}
@Override
public void doProcess(DiadromousFishGroup group) {
BufferedWriter bW;
String outputPath = "data/output/" ;
String sep = ";";
new File(outputPath + fileName).getParentFile().mkdirs();
try {
bW = new BufferedWriter(new FileWriter(new File(outputPath+
fileName + group.getSimulationId() + ".csv")));
bW.write("year"+sep+"nutrient" + sep + "originBasin" + sep + "value" + "\n");
Map<Long, Map <String, Map<String, Double>>> fluxesCollection = group.getNutrientRoutine().getNutrientExportFluxesCollection().getExportFluxesCollection();
// to iterate on sorted years
List<Long> years = new ArrayList<Long>(fluxesCollection.keySet());
Collections.sort(years);
for (long year :years) {
if (year >= group.getMinYearToWrite()) {
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
for (String originBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(year+ sep+ nutrient + sep + originBasinName );
bW.write( sep + fluxesCollection.get(year).get(nutrient).get(originBasinName) + '\n');
}
}
}
}
bW.flush();
bW.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
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