Commit f9caeb9e authored by patrick.lambert's avatar patrick.lambert
Browse files

new version of AnalyseFishDistribution

parent 35bdda67
...@@ -106,6 +106,7 @@ public class RiverBasin extends Basin { ...@@ -106,6 +106,7 @@ public class RiverBasin extends Basin {
// private int memorySize; // size of the queue // private int memorySize; // size of the queue
// TODO define as many QueueMemory as populations // TODO define as many QueueMemory as populations
private QueueMemory<Double> lastSpawnerNumbersBeforeReproduction;
private QueueMemory<Long> lastRecruitments; private QueueMemory<Long> lastRecruitments;
private QueueMemory<Long> lastRecruitmentExpectations; private QueueMemory<Long> lastRecruitmentExpectations;
private QueueMemory<Double> lastProdCapacities; // keep the production capacities of the basin (parameter alpha of private QueueMemory<Double> lastProdCapacities; // keep the production capacities of the basin (parameter alpha of
...@@ -133,7 +134,6 @@ public class RiverBasin extends Basin { ...@@ -133,7 +134,6 @@ public class RiverBasin extends Basin {
protected static transient ObservablesHandler cobservable; protected static transient ObservablesHandler cobservable;
public ObservablesHandler getCobservable() { public ObservablesHandler getCobservable() {
return cobservable; return cobservable;
} }
...@@ -235,6 +235,7 @@ public class RiverBasin extends Basin { ...@@ -235,6 +235,7 @@ public class RiverBasin extends Basin {
this.yearOfLastNulRep = 0; this.yearOfLastNulRep = 0;
this.type = Basin.BasinType.RIVER; this.type = Basin.BasinType.RIVER;
// this.memorySize = memoryAllQueues; // this.memorySize = memoryAllQueues;
this.lastSpawnerNumbersBeforeReproduction = new QueueMemory<Double>(memorySize);
this.lastRecruitments = new QueueMemory<Long>(memorySize); this.lastRecruitments = new QueueMemory<Long>(memorySize);
this.lastRecruitmentExpectations = new QueueMemory<Long>(memorySize); this.lastRecruitmentExpectations = new QueueMemory<Long>(memorySize);
this.lastProdCapacities = new QueueMemory<Double>(memorySize); this.lastProdCapacities = new QueueMemory<Double>(memorySize);
...@@ -429,6 +430,14 @@ public class RiverBasin extends Basin { ...@@ -429,6 +430,14 @@ public class RiverBasin extends Basin {
} }
/**
* @return the lastSpawnerNumbersBeforeReproduction
*/
public QueueMemory<Double> getLastSpawnerNumbersBeforeReproduction() {
return this.lastSpawnerNumbersBeforeReproduction;
}
public QueueMemory<Long> getLastRecruitments() { public QueueMemory<Long> getLastRecruitments() {
return lastRecruitments; return lastRecruitments;
} }
...@@ -453,12 +462,12 @@ public class RiverBasin extends Basin { ...@@ -453,12 +462,12 @@ public class RiverBasin extends Basin {
return numberOfNonNulRecruitmentDuringLastYears; return numberOfNonNulRecruitmentDuringLastYears;
} }
/* /*
* public QueueMemory<Double> getFemaleSpawnersForFirstTimeMeanAges() { return * public QueueMemory<Double> getFemaleSpawnersForFirstTimeMeanAges() { return
* spawnersForFirstTimeMeanAges.get(Gender.FEMALE); } * spawnersForFirstTimeMeanAges.get(Gender.FEMALE); }
*/ */
public QueueMemory<Double> getSpawnersForFirstTimeMeanLengths(DiadromousFish.Gender gender) { public QueueMemory<Double> getSpawnersForFirstTimeMeanLengths(DiadromousFish.Gender gender) {
if (gender == Gender.FEMALE) if (gender == Gender.FEMALE)
return femaleSpawnersForFirstTimeMeanLengths; return femaleSpawnersForFirstTimeMeanLengths;
......
...@@ -27,8 +27,6 @@ import com.thoughtworks.xstream.io.xml.DomDriver; ...@@ -27,8 +27,6 @@ import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.RIOBasinNetwork; import environment.RIOBasinNetwork;
import environment.RiverBasin; import environment.RiverBasin;
import environment.Time;
import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import fr.cemagref.simaqualife.pilot.Pilot; import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.TreeMapForCentile; import miscellaneous.TreeMapForCentile;
...@@ -39,17 +37,6 @@ import observer.ObservableRecord; ...@@ -39,17 +37,6 @@ import observer.ObservableRecord;
*/ */
public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private Season fishDistributionAnalysisSeason = Season.SPRING;
private long fishDistributionAnalysisStartYear = 1920;
private long fishDistributionAnalysisEndYear = 1950;
private transient List<FishDistributionRecord> records;
private transient double southernLimit;
private transient double northernLimit;
/** /**
* The minimum number of recruits to consider a basin as populated * The minimum number of recruits to consider a basin as populated
* *
...@@ -57,53 +44,11 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis ...@@ -57,53 +44,11 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
*/ */
private int minimumRecruitsForPopulatedBasin = 50; private int minimumRecruitsForPopulatedBasin = 50;
private class FishDistributionRecord implements ObservableRecord { private transient List<FishDistributionRecord> records;
@Information(unit = "year")
private long year;
@Information(unit = "-")
private int southern_basin_id;
@Information(unit = "-")
private String southern_basin_name;
@Information(unit = "°")
private double southern_latitude;
@Information(unit = "-")
private int northern_basin_id;
@Information(unit = "-")
private String northern_basin_name;
@Information(unit = "°")
private double northern_latitude;
@Information(unit = "°")
private double centroide_latitude;
public FishDistributionRecord(long year, int southern_basin_id, String southern_basin_name, double southern_latitude,
int northern_basin_id, String northern_basin_name, double northern_latitude, double centroide_latitude) {
this.year = year;
this.southern_basin_id = southern_basin_id;
this.southern_basin_name = southern_basin_name;
this.southern_latitude = southern_latitude;
this.northern_basin_id = northern_basin_id;
this.northern_basin_name = northern_basin_name;
this.northern_latitude = northern_latitude;
this.centroide_latitude = centroide_latitude;
}
@Override
public String toString() {
return "FishDistributionRecord [year=" + this.year + ", southern_basin_id=" + this.southern_basin_id
+ ", southern_basin_name=" + this.southern_basin_name + ", southern_latitude=" + this.southern_latitude
+ ", northern_basin_id=" + this.northern_basin_id + ", northern_basin_name=" + this.northern_basin_name
+ ", northern_latitude=" + this.northern_latitude + ", centroide_latitude=" + this.centroide_latitude + "]";
}
}
public static void main(String[] args) { private transient double southernLimit;
System.out.println((new XStream(new DomDriver())).toXML(new AnalyseFishDistribution()));
}
private transient double northernLimit;
@Override @Override
public void initTransientParameters(Pilot pilot) { public void initTransientParameters(Pilot pilot) {
...@@ -126,11 +71,6 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis ...@@ -126,11 +71,6 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
if (records == null) if (records == null)
initTransientParameters(group.getPilot()); initTransientParameters(group.getPilot());
Time time = group.getEnvironment().getTime();
if (time.getSeason(group.getPilot()) == fishDistributionAnalysisSeason
& time.getYear(group.getPilot()) >= fishDistributionAnalysisStartYear
& time.getYear(group.getPilot()) <= fishDistributionAnalysisEndYear) {
// initialise the distribution range // initialise the distribution range
double southernEdge = northernLimit; double southernEdge = northernLimit;
double northernEdge = southernLimit; double northernEdge = southernLimit;
...@@ -140,10 +80,15 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis ...@@ -140,10 +80,15 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
String northernName = ""; String northernName = "";
// initialise for centroid // initialise for centroid
TreeMapForCentile latitudeEffective = new TreeMapForCentile(); TreeMapForCentile latitudeEffective = new TreeMapForCentile();
TreeMapForCentile latitudePresence = new TreeMapForCentile();
for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) {
if (riverBasin.getLastRecruitments().getLastItem() > minimumRecruitsForPopulatedBasin) { if (riverBasin.getLastRecruitments().getMean() > minimumRecruitsForPopulatedBasin) {
// the basin is considerd as populated // the river basin is consdered populated
// NOTE : recruiit number is calulated after thermal tolerance impact
// (which is intreaged in the stock-recruitment relationship)
// southern edge // southern edge
if (riverBasin.getLatitude() < southernEdge) { if (riverBasin.getLatitude() < southernEdge) {
...@@ -162,10 +107,8 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis ...@@ -162,10 +107,8 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
} }
// for distribution centroide computation // for distribution centroide computation
long effective = 0; latitudePresence.putWithAdding(riverBasin.getLatitude(), 1L);
for (DiadromousFish fish : riverBasin.getFishs(group)) { long effective = ((Double) riverBasin.getLastSpawnerNumbersBeforeReproduction().getMean()).longValue();
effective += fish.getAmount();
}
latitudeEffective.putWithAdding(riverBasin.getLatitude(), effective); latitudeEffective.putWithAdding(riverBasin.getLatitude(), effective);
} }
} }
...@@ -174,28 +117,77 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis ...@@ -174,28 +117,77 @@ public class AnalyseFishDistribution extends AquaNismsGroupProcess<DiadromousFis
southernEdge = (northernLimit + southernLimit) / 2.; southernEdge = (northernLimit + southernLimit) / 2.;
northernEdge = southernEdge; northernEdge = southernEdge;
} }
// distribution centroide computation
double centroide = latitudeEffective.calculateMedian(); // distribution centroids computation
double basinCentroid = latitudePresence.calculateMedian();
double effectiveCentroid = latitudeEffective.calculateMedian();
// add a record // add a record
FishDistributionRecord record = new FishDistributionRecord(time.getYear(group.getPilot()), southernId, southernName, FishDistributionRecord record = new FishDistributionRecord(southernId, southernName, southernEdge, northernId,
southernEdge, northernId, northernName, northernEdge, centroide); northernName, northernEdge, basinCentroid, effectiveCentroid);
records.add(record); records.add(record);
} }
}
public double[][] exportToR() { public double[][] exportToR() {
double[][] export = new double[records.size()][4]; double[][] export = new double[records.size()][4];
for (int i = 0; i < records.size(); i++) { for (int i = 0; i < records.size(); i++) {
export[i][0] = records.get(i).year; export[i][0] = records.get(i).southern_basin_id;
export[i][1] = records.get(i).southern_basin_id; export[i][1] = records.get(i).northern_basin_id;
export[i][2] = records.get(i).northern_basin_id; export[i][2] = records.get(i).basinCentroid_latitude;
export[i][3] = records.get(i).centroide_latitude; export[i][3] = records.get(i).effectiveCentroid_latitude;
} }
return export; return export;
}
private class FishDistributionRecord implements ObservableRecord {
@Information(unit = "-")
private int southern_basin_id;
@Information(unit = "-")
private String southern_basin_name;
@Information(unit = "°")
private double southern_latitude;
@Information(unit = "-")
private int northern_basin_id;
@Information(unit = "-")
private String northern_basin_name;
@Information(unit = "°")
private double northern_latitude;
@Information(unit = "°")
private double basinCentroid_latitude;
@Information(unit = "°")
private double effectiveCentroid_latitude;
public FishDistributionRecord(int southern_basin_id, String southern_basin_name, double southern_latitude,
int northern_basin_id, String northern_basin_name, double northern_latitude, double basinCentroid_latitude,
double effectiveCentroid_latitude) {
super();
this.southern_basin_id = southern_basin_id;
this.southern_basin_name = southern_basin_name;
this.southern_latitude = southern_latitude;
this.northern_basin_id = northern_basin_id;
this.northern_basin_name = northern_basin_name;
this.northern_latitude = northern_latitude;
this.basinCentroid_latitude = basinCentroid_latitude;
this.effectiveCentroid_latitude = effectiveCentroid_latitude;
}
@Override
public String toString() {
return "FishDistributionRecord [southern_basin_id=" + this.southern_basin_id + ", southern_basin_name="
+ this.southern_basin_name + ", southern_latitude=" + this.southern_latitude + ", northern_basin_id="
+ this.northern_basin_id + ", northern_basin_name=" + this.northern_basin_name + ", northern_latitude="
+ this.northern_latitude + ", basinCentroide_latitude=" + this.basinCentroid_latitude
+ ", effectiveCentroide_latitude=" + this.effectiveCentroid_latitude + "]";
}
}
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())).toXML(new AnalyseFishDistribution()));
} }
} }
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;
...@@ -82,7 +80,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -82,7 +80,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
private transient StockRecruitmentRelationship stockRecruitmentRelationship; private transient StockRecruitmentRelationship stockRecruitmentRelationship;
// private transient UniformGen genUniform; // private transient UniformGen genUniform;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())).toXML(new ReproduceAndSurviveAfterReproductionWithDiagnose())); System.out.println((new XStream(new DomDriver())).toXML(new ReproduceAndSurviveAfterReproductionWithDiagnose()));
} }
...@@ -128,7 +125,8 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -128,7 +125,8 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) { for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) {
// before the party !!!! // before the party !!!!
double fluxBefore = riverBasin.getSpawnerNumber(); double fluxBefore = riverBasin.getSpawnerNumberPerGroup(group);
riverBasin.getLastSpawnerNumbersBeforeReproduction().add(fluxBefore);
double b, c, alpha, beta, amountPerSuperIndividual, S95, S50; double b, c, alpha, beta, amountPerSuperIndividual, S95, S50;
double numberOfFemaleSpawners = 0.; double numberOfFemaleSpawners = 0.;
...@@ -520,16 +518,16 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -520,16 +518,16 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
/ riverBasin.getLastProdCapacities().getLastItem()); / riverBasin.getLastProdCapacities().getLastItem());
// keep the no null recruitment // keep the no null recruitment
if (numberOfAutochtones > 0) { // if (numberOfAutochtones > 0) {
riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(1.); riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(1.);
riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(1.); riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(1.);
} else { // } else {
riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(0.); // riverBasin.getNumberOfNonNulRecruitmentForFinalProbOfPres().push(0.);
riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(0.); // riverBasin.getNumberOfNonNulRecruitmentDuringLastYears().push(0.);
} // }
} else { } else {
// stock the last year of null recruitment // stock the null recruitment of the last year
riverBasin.setYearOfLastNulRep(time.getYear(group.getPilot())); riverBasin.setYearOfLastNulRep(time.getYear(group.getPilot()));
riverBasin.getLastRecruitmentExpectations().push((long) 0); riverBasin.getLastRecruitmentExpectations().push((long) 0);
riverBasin.getLastRecruitments().push((long) 0); riverBasin.getLastRecruitments().push((long) 0);
...@@ -567,25 +565,17 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -567,25 +565,17 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
* ";" + riverBasin.getSpawnerNumberPerGroup(group)+ "; " + totalInputFluxes); * ";" + riverBasin.getSpawnerNumberPerGroup(group)+ "; " + totalInputFluxes);
*/ */
/* /*
BufferedWriter bW = group.getbWForFluxes(); * BufferedWriter bW = group.getbWForFluxes(); if (bW != null) { try { for (SpawnerOrigin origin :
if (bW != null) { * totalInputFluxes.keySet()) { bW.write(group.getPilot().getCurrentTime() + "; " +
try { * time.getYear(group.getPilot()) + ";" + time.getSeason(group.getPilot()) + ";" +
for (SpawnerOrigin origin : totalInputFluxes.keySet()) { * riverBasin.getName() + ";" + fluxBefore + ";" + "IMPORT" + ";" + origin); bW.write(";" +
bW.write(group.getPilot().getCurrentTime() + "; " + time.getYear(group.getPilot()) + ";" * totalInputFluxes.get(origin).get("biomass"));
+ time.getSeason(group.getPilot()) + ";" + riverBasin.getName() + ";" + fluxBefore + ";" *
+ "IMPORT" + ";" + origin); * for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { bW.write(";" +
bW.write(";" + totalInputFluxes.get(origin).get("biomass")); * totalInputFluxes.get(origin).get(nutrient)); } bW.write("\n"); } } catch (IOException e) {
*
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { * e.printStackTrace(); } }
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()));
...@@ -657,7 +647,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -657,7 +647,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
*/ */
double sigmaZ; // double sigmaZ; //
public void init(double alpha, double beta, double S50, double S95) { public void init(double alpha, double beta, double S50, double S95) {
this.alpha = alpha; this.alpha = alpha;
this.beta = beta; this.beta = beta;
...@@ -752,7 +741,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG ...@@ -752,7 +741,6 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG
// third: effective of corresponding recruitment // third: effective of corresponding recruitment
List<Trio<Integer, Long, Long>> data; // WHY age as integer List<Trio<Integer, Long, Long>> data; // WHY age as integer
public void init(List<Trio<Integer, Long, Long>> data) { public void init(List<Trio<Integer, Long, Long>> data) {
this.data = data; this.data = data;
} }
......
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