diff --git a/data/input/fishTryRealBV_CC.xml b/data/input/fishTryRealBV_CC.xml index 6236237886728ab546c03a51417852ddee2d881b..d0a9a1a6bcaeb1730f94f96d66573c485346b430 100644 --- a/data/input/fishTryRealBV_CC.xml +++ b/data/input/fishTryRealBV_CC.xml @@ -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> diff --git a/src/main/java/species/DiadromousFishGroup.java b/src/main/java/species/DiadromousFishGroup.java index 67d2454f4b121b10f28ba7867b4a79d72e9e141a..4ad4c7b26cb5694452a1f0d587c714732a016eff 100644 --- a/src/main/java/species/DiadromousFishGroup.java +++ b/src/main/java/species/DiadromousFishGroup.java @@ -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; @@ -65,7 +68,7 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe private NutrientRoutine nutrientRoutine; public String fileNameInputForInitialObservation = "data/input/reality/Obs1900.csv"; - + /** * centile to calucale the range of species distribution * @unit @@ -100,6 +103,11 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe private String basinsToUpdateFile = "data/input/reality/basinsToUpdate.csv"; private String outputPath = "data/output/"; + + private String fileNameFluxes = "fluxes"; + + private transient BufferedWriter bWForFluxes; + private transient String sep; /** * map @@ -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(){ diff --git a/src/main/java/species/MigrateToSea.java b/src/main/java/species/MigrateToSea.java index 206043342e5bf624554daa588f8c98e9f6c507ae..e5887e23e4d81eef860b9370f8e10de482cf99fd 100644 --- a/src/main/java/species/MigrateToSea.java +++ b/src/main/java/species/MigrateToSea.java @@ -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())); @@ -33,48 +37,65 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo if (Time.getSeason(group.getPilot()) == seaMigrationSeason ){ Basin destination; - - //On créer la Map pour stocker les flux d'export + + //On cr�er 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>>(); for (int i = 0; i < group.getEnvironment().getRiverBasins().length; i++) { RiverBasin basin = group.getEnvironment().getRiverBasins()[i]; //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.); //création de la biomasse - + totalOutputFluxes.put("biomass", 0.); //cr�ation de la biomasse + if (fishes!=null) { for (DiadromousFish fish : fishes) { destination = group.getEnvironment().getAssociatedSeaBasin(fish.getPosition()); 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(); - + if (fish.getStage()==Stage.IMMATURE) { Map <String, Double> aFluxExportedByJuveniles= group.getNutrientRoutine().computeNutrientsExportForJuveniles(fish); for (String nutrient: aFluxExportedByJuveniles.keySet()) { totalOutputFluxes.put(nutrient,totalOutputFluxes.get(nutrient) + aFluxExportedByJuveniles.get(nutrient) * fish.getAmount()); } - + totalOutputFluxes.put("biomass", totalOutputFluxes.get("biomass") + biomass); } } } - + for (Duo<DiadromousFish,Basin> duo : fishesToMove) { - 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. + 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 diff --git a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java index 20dd84d3ec092eacd6f6af7037d4e2241487290d..5bebd92294b095d9bc34f8c377e9cbd53065ae50 100644 --- a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java +++ b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java @@ -1,6 +1,8 @@ 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 créer 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 cr�er 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(); - 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 { riverBasin.setYearOfLastNulRep(Time.getYear(group.getPilot()));