Commit 98ed1ea1 authored by patrick.lambert's avatar patrick.lambert
Browse files

new process to analyse fish distribution

parent 8f73b6a9
......@@ -305,6 +305,14 @@
<displayFluxesOnConsole>false</displayFluxesOnConsole>
</species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<species.AnalyseFishDistribution>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<fishDistributionAnalysisSeason>SPRING</fishDistributionAnalysisSeason>
<fishDistributionAnalysisStartYear>1820</fishDistributionAnalysisStartYear>
<fishDistributionAnalysisEndYear>1850</fishDistributionAnalysisEndYear>
<minimumRecruitsForPopulatedBasin>50</minimumRecruitsForPopulatedBasin>
</species.AnalyseFishDistribution>
<species.MigrateFromRiverToInshore>
<synchronisationMode>ASYNCHRONOUS</synchronisationMode>
<migrationSeasonToReachInshore>SPRING</migrationSeasonToReachInshore>
......
......@@ -55,7 +55,7 @@ public class EasyRun {
}
public static double[] getValuesFromEnvironement(String targetName) throws Exception {
public static double[] getValuesFromEnvironment(String targetName) throws Exception {
return (double[]) ReflectUtils.getValueFromPath(pilot.getAquaticWorld().getEnvironment(), targetName);
}
......@@ -70,8 +70,13 @@ public class EasyRun {
}
public static double[][] getValuesFromAquanismGroupProcess(String targetPath) throws Exception {
return (double[][]) ReflectUtils.getValueFromPath(pilot.getAquaticWorld().getAquaNismsGroupsList().get(0), targetPath);
}
public static void main(String[] args) throws Exception {
String[] batchArguments = ("-simDuration 48 -simBegin 1 -timeStepDuration 1 -RNGStatusIndex 1 "
String[] batchArguments = ("-simDuration 100 -simBegin 1 -timeStepDuration 1 -RNGStatusIndex 1 "
+ "-groups data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml "
+ "-env data/input/northeastamerica/RIOBNneaBasins_Rjava.xml "
+ "-observers data/input/northeastamerica/RIO_obs_empty.xml").split("\\ ");
......@@ -83,16 +88,18 @@ public class EasyRun {
runSimulation(batchArguments, "tsointsoin", parameterNames, parameterValues);
List truc = getAListFromAquanismGroupProcess("processes.processesAtEnd.1.getRecords");
System.out.println(truc.get(0).toString());
double[][] distributionResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.9.exportToR");
for (double[] result : distributionResults) {
System.out.println(Arrays.toString(result));
}
// List truc = getAListFromAquanismGroupProcess("processes.processesAtEnd.1.getRecords");
// System.out.println(truc.get(0).toString());
// System.out.println(getAListFromAquanismGroupProcess("processes.processesAtEnd.1.getRecords"));
System.out.println(Arrays.toString(getValuesFromEnvironement("getMeanLastPercOfAut")));
System.out.println(Arrays.toString(getValuesFromEnvironment("getMeanLastPercOfAut")));
System.out.println(Arrays.toString(getValuesFromAquanismGroup("getRangeDistribution")));
// double[] basinRecruitments = runSimulation(batchArguments, "tsointsoin", parameterNames, parameterValues);
// System.out.println(Arrays.toString(basinRecruitments));
}
}
/**
* patrick
* @author Patrick Lambert
* @copyright Copyright (c) 2020, INRAE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package species;
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.RIOBasinNetwork;
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.TreeMapForCentile;
import observer.ObservableRecord;
/**
*
*/
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
*
* @unit: #
*/
private int minimumRecruitsForPopulatedBasin = 50;
private class FishDistributionRecord implements ObservableRecord {
@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) {
System.out.println((new XStream(new DomDriver())).toXML(new AnalyseFishDistribution()));
}
@Override
public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot);
records = new ArrayList<FishDistributionRecord>();
// define the latitude range of basin network
southernLimit = 90.;
northernLimit = -90.;
for (RiverBasin riverBasin : ((RIOBasinNetwork) pilot.getAquaticWorld().getEnvironment()).getRiverBasins()) {
southernLimit = Math.min(southernLimit, riverBasin.getLatitude());
northernLimit = Math.max(northernLimit, riverBasin.getLatitude());
}
}
@Override
public void doProcess(DiadromousFishGroup group) {
if (records == null)
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
double southernEdge = northernLimit;
double northernEdge = southernLimit;
int southernId = -1;
int northernId = -1;
String southernName = "";
String northernName = "";
// initialise for centroid
TreeMapForCentile latitudeEffective = new TreeMapForCentile();
for (RiverBasin riverBasin : group.getEnvironment().getRiverBasins()) {
if (riverBasin.getLastRecruitments().getLastItem() > minimumRecruitsForPopulatedBasin) {
// the basin is considerd as populated
// southern edge
if (riverBasin.getLatitude() < southernEdge) {
// the basin is the new southern edge
southernEdge = riverBasin.getLatitude();
southernId = riverBasin.getBasin_id();
southernName = riverBasin.getName();
}
// northern edge
if (riverBasin.getLatitude() > southernEdge) {
// the basin is the new northern edge
northernEdge = riverBasin.getLatitude();
northernId = riverBasin.getBasin_id();
northernName = riverBasin.getName();
}
// for distribution centroide computation
long effective = 0;
for (DiadromousFish fish : riverBasin.getFishs(group)) {
effective += fish.getAmount();
}
latitudeEffective.putWithAdding(riverBasin.getLatitude(), effective);
}
}
// if the universe is empty
if (southernEdge == northernLimit & northernEdge == southernLimit) {
southernEdge = (northernLimit + southernLimit) / 2.;
northernEdge = southernEdge;
}
// distribution centroide computation
double centroide = latitudeEffective.calculateMedian();
// add a record
FishDistributionRecord record = new FishDistributionRecord(time.getYear(group.getPilot()), southernId, southernName,
southernEdge, northernId, northernName, northernEdge, centroide);
records.add(record);
}
}
public double[][] exportToR() {
double[][] export = new double[records.size()][4];
for (int i = 0; i < records.size(); i++) {
export[i][0] = records.get(i).year;
export[i][1] = records.get(i).southern_basin_id;
export[i][2] = records.get(i).northern_basin_id;
export[i][3] = records.get(i).centroide_latitude;
}
return export;
}
}
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