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

merge with camille

parents 997e3c55 31ba887c
......@@ -7,12 +7,9 @@
<blue>0</blue>
<alpha>255</alpha>
</color>
<dMaxDisp>300.0</dMaxDisp>
<linfVonBertForFemale>70.0</linfVonBertForFemale>
<linfVonBertForMale>70.0</linfVonBertForMale>
<lFirstMaturityForFemale>55.0</lFirstMaturityForFemale>
<lFirstMaturityForMale>40.0</lFirstMaturityForMale>
<lengthAtHatching>2</lengthAtHatching>
<lFirstMaturity>40.0</lFirstMaturity>
<nutrientRoutine>
<nutrientsOfInterest>
<string>N</string>
......@@ -43,11 +40,11 @@
</entry>
<entry>
<string>bLW</string>
<double>2.1774</double>
<double>3.2252</double>
</entry>
<entry>
<string>aLW</string>
<double>0.27144384321211973</double>
<double>0.004095817237891344</double>
</entry>
</hashtable>
</entry>
......@@ -64,11 +61,11 @@
</entry>
<entry>
<string>bLW</string>
<double>3.147</double>
<double>3.3429</double>
</entry>
<entry>
<string>aLW</string>
<double>0.007388725660209693</double>
<double>0.002665367811305362</double>
</entry>
</hashtable>
</entry>
......@@ -230,6 +227,7 @@
<yearOfTheUpdate>0</yearOfTheUpdate>
<basinsToUpdateFile>data/input/reality/basinsToUpdate.csv</basinsToUpdateFile>
<outputPath>data/output/</outputPath>
<fileNameFluxes>nutrientFluxes</fileNameFluxes>
<processes>
<processesAtBegin>
<species.PopulateBasinNetworkWithANorthLimit>
......@@ -294,17 +292,18 @@
<mortalityRateInOffshore>0.4</mortalityRateInOffshore>
</species.Survive>
<species.ExportLenghtAgeDistribution>
<species.ExportFluxes>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<exportSeason>SPRING</exportSeason>
<fileNameOutput>lengthAgeDistribution</fileNameOutput>
</species.ExportLenghtAgeDistribution>
<fileNameOutput>EffectiveFluxes</fileNameOutput>
</species.ExportFluxes>
<species.ExportFluxes>
<species.ExportBiomass>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<survivalRateAfterReproduction>0.1</survivalRateAfterReproduction>
<exportSeason>SPRING</exportSeason>
<fileNameOutput>effectiveFluxes</fileNameOutput>
</species.ExportFluxes>
<fileNameOutput>BiomassFluxes</fileNameOutput>
</species.ExportBiomass>
<species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
......@@ -325,11 +324,13 @@
<maxNumberOfSuperIndividualPerReproduction>50.0
</maxNumberOfSuperIndividualPerReproduction>
<withDiagnose>false</withDiagnose>
<displayFluxesOnConsole>true</displayFluxesOnConsole>
</species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<species.MigrateToSea>
<seaMigrationSeason>SUMMER</seaMigrationSeason>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<displayFluxesOnConsole>true</displayFluxesOnConsole>
</species.MigrateToSea>
<environment.updateTemperatureInRealBasin>
......@@ -347,7 +348,7 @@
<long>2000</long>
<long>2100</long>
</years>
<fileNameOutput>fluxes</fileNameOutput>
<fileNameOutput>JeuParam100_2100RCP85_A_essai</fileNameOutput>
</species.IdentifyPopulation>
<species.TypeTrajectoryCV>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
......
......@@ -70,12 +70,20 @@ public class RiverBasin extends Basin {
public double getSpawnerNumber() {
long nbSpawn = 0;
for (DiadromousFishGroup group : this.getGroups()) {
nbSpawn += getSpawnerNumberPerGroup(group);
}
return nbSpawn;
}
public double getSpawnerNumberPerGroup(DiadromousFishGroup group) {
long nbSpawn = 0;
for (DiadromousFish fish : this.getFishs(group)) {
if (fish.isMature()) {
nbSpawn += fish.getAmount();
}
}
}
return nbSpawn;
}
......
......@@ -456,7 +456,7 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe
fileNameFluxes +this.getSimulationId() + ".csv")));
bWForFluxes.write("timestep"+sep+"year"+sep+"season"+sep+"basin"
+sep+"abundance" + sep + "fluxType"+sep+"origine"+sep+"biomass");
+sep+"abundance" + sep + "fluxType"+ sep + "origin" +sep+"biomass");
for (String nutrient : nutrientRoutine.getNutrientsOfInterest()) {
bWForFluxes.write(sep+nutrient);
}
......
package species;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.RiverBasin;
import environment.Time;
import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.Miscellaneous;
import species.DiadromousFish.Stage;
import species.ReproduceAndSurviveAfterReproductionWithDiagnose;
/**
*
*/
public class ExportBiomass extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private double survivalRateAfterReproduction = 0.1;
private Season exportSeason = Season.SPRING;
private String fileNameOutput = "BiomassFluxes";
private transient BufferedWriter bW;
private transient String sep=";";
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new ExportBiomass()));
}
/* (non-Javadoc)
* @see fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess#initTransientParameters(fr.cemagref.simaqualife.pilot.Pilot)
*/
@Override
public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot);
sep=";";
}
@Override
public void doProcess(DiadromousFishGroup group) {
if (bW==null){
if (fileNameOutput != null){
new File(group.getOutputPath()+fileNameOutput).getParentFile().mkdirs();
try {
bW = new BufferedWriter(new FileWriter(new File(group.getOutputPath()+
fileNameOutput +group.getSimulationId()+ ".csv")));
bW.write("year"+sep+"migrationBasin" ); //create the field of the column
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep + birthBasinName); // write each basin name in the file
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
if (Time.getSeason(pilot) == exportSeason & Time.getYear(pilot)>1900) {
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
//Create the map to get the biomass in each birth basin
Map<String, Double> spawnerOriginsBeforeReproduction = new HashMap<String, Double>(group.getEnvironment().getRiverBasinNames().length);
for (String basinName : group.getEnvironment().getRiverBasinNames()){
spawnerOriginsBeforeReproduction.put(basinName, 0.);
}
double biomass=0.;
//compute the cumulative effective per birth basin
if (migrationBasin.getFishs(group) != null) {
for (DiadromousFish fish : migrationBasin.getFishs(group)) {
double survivalAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), survivalRateAfterReproduction);
biomass = group.getNutrientRoutine().getWeight(fish) * (fish.getAmount() - survivalAmount);
if (fish.getStage() == Stage.MATURE) {
String birthBasinName = fish.getBirthBasin().getName();
spawnerOriginsBeforeReproduction.put(birthBasinName, spawnerOriginsBeforeReproduction.get(birthBasinName) + biomass);
}
}
}
//write the first two fields of the line
bW.write(Time.getYear(pilot)+sep+migrationBasin.getName());
//write the cumulative effective from birth basin
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep+spawnerOriginsBeforeReproduction.get(birthBasinName));
}
//write an end-of(line
bW.write("\n");
}
}
if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1)
bW.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
......@@ -73,10 +73,11 @@ public class ExportFluxes extends AquaNismsGroupProcess<DiadromousFish, Diadromo
bW = new BufferedWriter(new FileWriter(new File(group.getOutputPath()+
fileNameOutput +group.getSimulationId()+ ".csv")));
bW.write("year"+sep+"migrationBasin");
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()){
bW.write(sep+birthBasinName);
bW.write("year"+sep+"migrationBasin" ); //create the field of the column
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep + birthBasinName); // write each basin name in the file
}
bW.write("\n");
} catch (IOException e) {
e.printStackTrace();
......@@ -86,16 +87,16 @@ public class ExportFluxes extends AquaNismsGroupProcess<DiadromousFish, Diadromo
try {
if (Time.getSeason(pilot) == exportSeason & Time.getYear(pilot)>1900) {
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
// create the map to get the abundance per birth basin
//Create the map to get the abundance in each birth basin
Map<String, Long> spawnerOriginsBeforeReproduction = new HashMap<String, Long>(group.getEnvironment().getRiverBasinNames().length);
for (String basinName : group.getEnvironment().getRiverBasinNames()){
spawnerOriginsBeforeReproduction.put(basinName, 0L);
spawnerOriginsBeforeReproduction.put(basinName, 0L);
}
// compute the cumulative effetive per birth basin
//compute the cumulative effective per birth basin
if (migrationBasin.getFishs(group) != null) {
for (DiadromousFish fish : migrationBasin.getFishs(group)) {
if (fish.getStage() == Stage.MATURE) {
......@@ -104,13 +105,13 @@ public class ExportFluxes extends AquaNismsGroupProcess<DiadromousFish, Diadromo
}
}
}
// write the fisrt 2 fields of the line
//write the first two fields of the line
bW.write(Time.getYear(pilot)+sep+migrationBasin.getName());
// the cumulative effective from birth basin
for (String natalBasinName : group.getEnvironment().getRiverBasinNames()){
bW.write(sep+spawnerOriginsBeforeReproduction.get(natalBasinName));
//write the cumulative effective from birth basin
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep+spawnerOriginsBeforeReproduction.get(birthBasinName));
}
// write an end-of-line
bW.write("\n");
......@@ -123,4 +124,3 @@ public class ExportFluxes extends AquaNismsGroupProcess<DiadromousFish, Diadromo
}
}
}
......@@ -188,7 +188,8 @@ public class NutrientRoutine {
/**
* compute the nutrient fluxes for a single fish (in the super individual)
* that dies after spawning (gametes expelling)
* that dies after spawning (gametes expelling)
* Considering that a fish died after reproduction have the same nutrient contribution that a fish died before reproduction, we use the same coefficient for weight computation.
* @param fish
* @return nutrientsInput
*/
......@@ -375,25 +376,21 @@ public class NutrientRoutine {
*/
Map<String,Double> aFeature = new Hashtable<String,Double>();
aFeature.put("aLW", Math.exp(-4.9078)); //weight size relationship computed from BDalosesBruch
aFeature.put("bLW", 3.147);
aFeature.put("aLW_Gonad", -5.2425); // issu de la relation taille - poids des gonades Bruch
aFeature.put("bLW", 3.3429); //From Taverny
aFeature.put("aLW", 1.2102E-6 * Math.pow(10., aFeature.get("bLW"))); //weight size relationship -- Conversion des g/mm en g.cm (from Taverny, 1991)
aFeature.put("bLW_Gonad", 2.6729); // issu de la relation taille - poids des gonades Bruch
//aFeature.put("bLW",3.3429);// parametre "b" de la relation taille/poids - Coefficient d'allometrie
//aFeature.put("aLW",1.2102E-6 * Math.pow(10., aFeature.get("bLW"))); // parametre "a" de la relation taille/poids en kg/cm- Traduit la condition
//aFeature.put("GSI",0.15);
aFeature.put("aLW_Gonad", -5.2425); // issu de la relation taille - poids des gonades Bruch
aFeaturePreSpawning.put(Gender.FEMALE, aFeature);
/*
* For males
*/
aFeature = new Hashtable<String,Double>();
aFeature.put("aLW", Math.exp(-1.304));
aFeature.put("bLW", 2.1774);
aFeature.put("aLW_Gonad", -8.8744);
aFeature.put("bLW", 3.2252);
aFeature.put("aLW", 2.4386E-6 * Math.pow(10., aFeature.get("bLW"))); //weight size relationship from Taverny -- Conversion des g/mm en g.cm (from Taverny, 1991)
aFeature.put("bLW_Gonad", 3.3838);
//aFeature.put("aLW",2.4386E-6 * Math.pow(10, aFeature.get("bLW"))); // Conversion des g/mm en g.cm (from Taverny, 1991)
//aFeature.put("GSI",.08);
aFeature.put("aLW_Gonad", -8.8744);
aFeaturePreSpawning.put(Gender.MALE,aFeature);
System.out.println("aFeaturePreSpawning: " + aFeaturePreSpawning.toString()); //
......
package species;
import environment.SeaBasin;
import fr.cemagref.simaqualife.pilot.Pilot;
import species.DiadromousFish.Gender;
import species.DiadromousFish.Stage;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* @author camille.poulet
*
*/
public class NutrientRoutineEssay {
private static enum SpawningPosition {PRE,POST}; // on crer un static pour rserver une mme classe mmoire pour toutes les instances
//private static enum Gender {UNDIFFERENCIED, FEMALE, MALE};
private ArrayList<String> nutrientsOfInterest;
private double residenceTime;
private Map<String, Double> excretionRate;
/**
* Main feature for weight (g) computation before spawning i.e. gametes expelling according to gender, for a given length (cm)
* //Voir pour un retour la ligne lors du commentaire
* key gender
* value
* key feature
* value value
*/
private Map <DiadromousFish.Gender,Map<String, Double>> fishFeaturesPreSpawning;
private Map <DiadromousFish.Gender, Map<String, Double>> fishFeaturesPostSpawning;
private Map<String, Double> juvenileFeatures;
/**
* Weight of gametes spawned for both males and females
* key gender
* value g
* usually computed as the difference between unspawned gonad (inbound) and spawned gonad (outbound; "spent gonad")
*/
//private Map <DiadromousFish.Gender, Double> spawnedGametesWeight;
/**
* chemical composition of carcass before gametes expelling (before spawning) i.e. soma + gonads + gametes
* <key> gender
* <value>
* <key> chemical element
* <value> value ratio element / (total wet weight) g/g
*/
private Map<DiadromousFish.Gender,Map<String,Double>> compoCarcassPreSpawning;
//package permettant la cration d'une table de hachage ie fonctionnant en cl -valeur. Cl unique, mais valeur peut tre associe plusieurs cls;
//La class d'objet Map a pour point faible la taille des donnes stocker. Plus on a de valeur dans la table, plus c'est lourd et lent! Donc, trouver un compromis entre temps de calcul et espace.
//N'accepte pas la valeur nulle et thread safe i.e. utilisable simultanment par plusieurs lments du programme.
/**
* chemical composition of gametes estimated from the MIGADO dataset (BDalosesBruch)
* <key> gender
* <value>
* <key> chemical element
* <value> value
*/
private Map<DiadromousFish.Gender, Map<String,Double>> compoGametes;
// For juveniles - Based on Taverny (1991)
/**
* chemical composition of juveniles
* <key> chemical element
* <value> value
*/
private Map<String,Double> compoJuvenile;
/**
* Constructor based on the 5 Map of fish composition
* @param fishFeaturesPreSpawning
* @param compoCarcassPreSpawning
* @param compoCarcassPostSpawning
* @param compoGametes
* @param compoJuvenile
*/
public NutrientRoutineEssay(ArrayList<String> nutrientsOfInterest,
double residenceTime,
Map <String, Double> excretionRate,
Map<DiadromousFish.Gender, Map<String, Double>> fishFeaturesPreSpawning,
Map<DiadromousFish.Gender, Map<String, Double>> fishFeaturesPostSpawning,
Map<DiadromousFish.Gender, Map<String, Double>> compoCarcassPreSpawning,
Map<DiadromousFish.Gender, Map<String, Double>> compoGametes,
Map<String, Double> juvenileFeatures,
Map<String, Double> compoJuvenile)
{
super();
this.nutrientsOfInterest = nutrientsOfInterest;
this.excretionRate = excretionRate;
this.residenceTime = residenceTime;
this.fishFeaturesPreSpawning = fishFeaturesPreSpawning;
this.fishFeaturesPostSpawning = fishFeaturesPostSpawning;
this.compoCarcassPreSpawning = compoCarcassPreSpawning;
this.compoGametes = compoGametes;
this.juvenileFeatures = juvenileFeatures;
this.compoJuvenile = compoJuvenile;
}
/**
* compute the nutrient fluxes for a single fish (in the super individual)
* that dies before spawning
* @param fish
*/
public Map<String,Double> computeNutrientsInputForDeadFish(DiadromousFish fish, ArrayList<String> nutrientsOfInterest) {
Map<String,Double> nutrientsInput = new Hashtable<String, Double>(); // On crer ici une Map, classe mre des hashtable (Homme = classe mere ie Map//Jules = hashtable)
for (String nutrient : nutrientsOfInterest) {
if (fish.getStage()== Stage.MATURE) {
double totalWeightPre = this.getWeight(fish,SpawningPosition.PRE);
double carcass = totalWeightPre
* compoCarcassPreSpawning.get(fish.getGender()).get(nutrient);
double excretion = totalWeightPre
* residenceTime
* excretionRate.get(nutrient) ;
double nutrientImport = carcass + excretion;
nutrientsInput.put(nutrient, nutrientImport);
}
else {
nutrientsInput.put(nutrient, 0.);
}
}
//TODO Multiply by fish amount
return nutrientsInput;
}
public Map<String,Double> computeNutrientsInputForDeadFish(DiadromousFish fish) {
return computeNutrientsInputForDeadFish(fish,this.nutrientsOfInterest);
}
/**
* compute the nutrient fluxes for a single fish (in the super individual)
* that survives after spawning
* Map: model output = element of interest ie string + double ie the quantification of this fluxes.
* @return nutrientsInput
*/
public Map<String,Double>computeNutrientsInputForSurvivalAfterSpawning(DiadromousFish fish, ArrayList<String> nutrientsOfInterest) {
Map<String,Double> nutrientsInput = new Hashtable<String,Double>();
for (String nutrient: nutrientsOfInterest) {
if (fish.getStage()==Stage.MATURE) {
double totalWeightPre = this.getWeight(fish,SpawningPosition.PRE);
double gametes = this.getGonadWeight(fish, SpawningPosition.PRE) - this.getGonadWeight(fish, SpawningPosition.POST)
* compoGametes.get(fish.getGender()).get(nutrient);
double excretion = totalWeightPre
* residenceTime
* excretionRate.get(nutrient);
double nutrientImport = gametes + excretion;
nutrientsInput.put(nutrient, nutrientImport);
}
else {
nutrientsInput.put(nutrient,0.);
}
}
return nutrientsInput;
}
public Map<String,Double>computeNutrientsInputForSurvivalAfterSpawning(DiadromousFish fish) {
return computeNutrientsInputForSurvivalAfterSpawning(fish, this.nutrientsOfInterest);
}
public Map<String,Double> computeNutrientsExportForJuveniles(DiadromousFish juvenileFish, ArrayList<String>nutrientsOfInterest) {
Map<String,Double> nutrientsExport = new Hashtable<String,Double>();
for(String nutrient: nutrientsOfInterest) {
if(juvenileFish.getStage()==Stage.IMMATURE) {
double JuvenileMass = this.getWeight(juvenileFish);
nutrientsExport.put(nutrient, JuvenileMass * compoJuvenile.get(nutrient));
}
}
return nutrientsExport;
}
public Map<String,Double> computeNutrientsExportForJuveniles(DiadromousFish juvenileFish){
return computeNutrientsExportForJuveniles(juvenileFish, this.nutrientsOfInterest);
}
/**
* Compute the weight for a fish with length (cm)
* @param fish
* @return weight (g)
*/
public double getWeight (DiadromousFish fish, SpawningPosition spawningPosition) {
double weight = 0.;
if (fish.getStage()==Stage.IMMATURE)
weight = juvenileFeatures.get("aLW") * Math.pow(fish.getLength(),juvenileFeatures.get("bLW"));
else //Stage.MATURE
weight = fishFeaturesPreSpawning.get(fish.getGender()).get("aLW") * Math.pow(fish.getLength(), fishFeaturesPreSpawning.get(fish.getGender()).get("bLW") );
return weight;
}
/**
* Compute the weight for a fish with length (cm)
* @param fish
* @return weight (g)
*/
public double getWeight (DiadromousFish fish) {
return getWeight (fish, SpawningPosition.PRE);
}
/**
* Compute the gonad weight for a fish with length (cm) to compute the gamete emission (g).
* @param fish
* @return weight (g)
*/
public double getGonadWeight (DiadromousFish fish, SpawningPosition spawningPosition) {
double gonadWeight = 0.;
if (fish.getStage()==Stage.MATURE);
if (spawningPosition == SpawningPosition.PRE)
gonadWeight = Math.exp(fishFeaturesPreSpawning.get(fish.getGender()).get("aLW_Gonad")
+ fishFeaturesPreSpawning.get(fish.getGender()).get("bLW_Gonad") * Math.log(fish.getLength()));