Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
SimAquaLife
GR3D
Commits
b42580a9
Commit
b42580a9
authored
Apr 22, 2021
by
patrick.lambert
Browse files
with a exportToR of exchanges between catchments
parent
862b12ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/analysis/EasyRun.java
View file @
b42580a9
...
...
@@ -118,7 +118,7 @@ public class EasyRun {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// blank are important
String
[]
batchArguments
=
(
"-simDuration
4
0 -simBegin 1 -timeStepDuration 1 -RNGStatusIndex 1 "
String
[]
batchArguments
=
(
"-simDuration
10
0 -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
(
"\\ "
);
...
...
@@ -156,12 +156,13 @@ public class EasyRun {
System
.
out
.
println
(
"\n== AnalyseLikelihoodOfPresence =="
);
System
.
out
.
println
(
getSingleValueFromAquanismGroupProcess
(
"processes.processesAtEnd.0.getLogLikelihood"
));
// List truc = getAListFromAquanismGroupProcess("processes.processesAtEnd.0.getRecords");
// System.out.println(truc.get(0).toString());
// System.out.println(getAListFromAquanismGroupProcess("processes.processesAtEnd.1.getRecords"));
// System.out.println("\ngetMeanLastPercOfAut");
// System.out.println(Arrays.toString(getValuesFromEnvironment("getMeanLastPercOfAut")));
System
.
out
.
println
(
"\n== ExportExchangeSBetweenCatchments =="
);
String
[][]
exchangeSBetweenCatchments
=
getValuesFromAquanismGroupProcess
(
"processes.processesEachStep.16.exportToR"
);
for
(
String
[]
record
:
exchangeSBetweenCatchments
)
{
for
(
String
value
:
record
)
System
.
out
.
print
(
value
+
"\t"
);
System
.
out
.
println
();
}
}
}
src/main/java/analysis/ExportExchangesBetweenCatchments.java
View file @
b42580a9
...
...
@@ -24,14 +24,18 @@ import java.io.File;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.Serializable
;
import
java.util.Hashtable
;
import
java.util.Map
;
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
observer.ObservableRecord
;
import
species.DiadromousFish
;
import
species.DiadromousFishGroup
;
...
...
@@ -39,7 +43,7 @@ import species.DiadromousFishGroup;
/**
*
*/
public
class
ExportExchange
S
BetweenCatchments
extends
AquaNismsGroupProcess
<
DiadromousFish
,
DiadromousFishGroup
>
{
public
class
ExportExchange
s
BetweenCatchments
extends
AquaNismsGroupProcess
<
DiadromousFish
,
DiadromousFishGroup
>
{
/**
*
...
...
@@ -111,38 +115,60 @@ public class ExportExchangeSBetweenCatchments extends AquaNismsGroupProcess<Diad
private
Season
fluxesSeason
=
Season
.
SPRING
;
private
String
fileNameOutput
=
"effectiveFluxes"
;
private
transient
RiverBasin
[]
riverBasins
;
private
transient
BufferedWriter
bW
;
private
transient
String
sep
;
/**
* 1st key: migration basin 2nd key: natal basin 3nd key: year value : effective
*
* @unit
*/
private
transient
Map
<
RiverBasin
,
Map
<
RiverBasin
,
Map
<
Long
,
Double
>>>
exchanges
;
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
((
new
XStream
(
new
DomDriver
())).
toXML
(
new
ExportExchange
S
BetweenCatchments
()));
System
.
out
.
println
((
new
XStream
(
new
DomDriver
())).
toXML
(
new
ExportExchange
s
BetweenCatchments
()));
}
//
// @Override
// public void initTransientParameters(Pilot pilot) {
// super.initTransientParameters(pilot);
// // create output file if necessary
// if (fileNameOutput != null) {
// sep = ",";
//
// String outputPath = ((DiadromousFishGroup)
// pilot.getAquaticWorld().getAquaNismsGroupsList().get(0)).getOutputPath();
// String simulationId = ((DiadromousFishGroup) pilot.getAquaticWorld().getAquaNismsGroupsList().get(0))
// .getSimulationId();
// try {
// new File(outputPath + fileNameOutput).getParentFile().mkdirs();
// bW = new BufferedWriter(new FileWriter(new File(outputPath + fileNameOutput + simulationId + ".csv")));
//
// bW.write("year" + sep + "destinationBasin" + sep + "originBasin" + sep + "effective");
// bW.write("\n");
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// }
@Override
public
void
initTransientParameters
(
Pilot
pilot
)
{
super
.
initTransientParameters
(
pilot
);
riverBasins
=
((
RIOBasinNetwork
)
pilot
.
getAquaticWorld
().
getEnvironment
()).
getRiverBasins
();
exchanges
=
new
Hashtable
<
RiverBasin
,
Map
<
RiverBasin
,
Map
<
Long
,
Double
>>>();
for
(
RiverBasin
migrationBasin
:
riverBasins
)
{
Map
<
RiverBasin
,
Map
<
Long
,
Double
>>
natal_yearEffective
=
new
Hashtable
<
RiverBasin
,
Map
<
Long
,
Double
>>();
for
(
RiverBasin
natalBasin
:
riverBasins
)
{
Map
<
Long
,
Double
>
year_effective
=
new
Hashtable
<
Long
,
Double
>();
for
(
Long
year
=
yearStart
;
year
<=
yearEnd
;
year
++)
{
year_effective
.
put
(
year
,
0
.);
}
natal_yearEffective
.
put
(
natalBasin
,
year_effective
);
}
exchanges
.
put
(
migrationBasin
,
natal_yearEffective
);
}
// create output file if necessary
if
(
fileNameOutput
!=
null
)
{
sep
=
","
;
String
outputPath
=
((
DiadromousFishGroup
)
pilot
.
getAquaticWorld
().
getAquaNismsGroupsList
().
get
(
0
)).
getOutputPath
();
String
simulationId
=
((
RIOBasinNetwork
)
pilot
.
getAquaticWorld
().
getEnvironment
()).
getSimulationId
();
try
{
new
File
(
outputPath
+
fileNameOutput
).
getParentFile
().
mkdirs
();
bW
=
new
BufferedWriter
(
new
FileWriter
(
new
File
(
outputPath
+
fileNameOutput
+
simulationId
+
".csv"
)));
bW
.
write
(
"year"
+
sep
+
"destinationBasin"
+
sep
+
"originBasin"
+
sep
+
"effective"
);
bW
.
write
(
"\n"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
/*
...
...
@@ -153,46 +179,30 @@ public class ExportExchangeSBetweenCatchments extends AquaNismsGroupProcess<Diad
@Override
public
void
doProcess
(
DiadromousFishGroup
group
)
{
// write header in the file
if
(
bW
==
null
)
{
if
(
fileNameOutput
!=
null
)
{
sep
=
","
;
try
{
new
File
(
group
.
getOutputPath
()
+
fileNameOutput
).
getParentFile
().
mkdirs
();
bW
=
new
BufferedWriter
(
new
FileWriter
(
new
File
(
group
.
getOutputPath
()
+
fileNameOutput
+
group
.
getEnvironment
().
getSimulationId
()
+
".csv"
)));
bW
.
write
(
"year"
+
sep
+
"migrationBasin"
+
sep
+
"natalBasin"
+
sep
+
"effective"
);
bW
.
write
(
"\n"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
if
(
exchanges
==
null
)
initTransientParameters
(
group
.
getPilot
());
Time
time
=
group
.
getEnvironment
().
getTime
();
if
(
time
.
getYear
(
group
.
getPilot
())
>=
yearStart
&&
time
.
getYear
(
group
.
getPilot
())
<=
yearEnd
&&
time
.
getSeason
(
group
.
getPilot
())
==
fluxesSeason
)
{
String
[]
basinNames
=
group
.
getEnvironment
().
getRiverBasinNames
();
long
year
=
time
.
getYear
(
group
.
getPilot
());
if
(
year
>=
yearStart
&&
year
<=
yearEnd
&&
time
.
getSeason
(
group
.
getPilot
())
==
fluxesSeason
)
{
// display headers on console
if
(
consoleDisplay
)
{
System
.
out
.
print
(
"migration\\natal"
+
"\t"
);
for
(
String
basinName
:
basinName
s
)
{
System
.
out
.
print
(
basin
Name
+
"\t"
);
for
(
RiverBasin
riverBasin
:
riverBasin
s
)
{
System
.
out
.
print
(
riverBasin
.
get
Name
()
+
"\t"
);
}
System
.
out
.
println
();
}
for
(
RiverBasin
migrationBasin
:
group
.
getEnvironment
().
getR
iverBasins
()
)
{
for
(
RiverBasin
migrationBasin
:
r
iverBasins
)
{
// /display data on console
if
(
consoleDisplay
)
{
System
.
out
.
print
(
migrationBasin
.
getName
()
+
'\t'
);
}
for
(
Str
in
g
natalBasin
Name
:
basinName
s
)
{
double
effective
=
Math
.
round
(
migrationBasin
.
getSpawnerOrigins
().
getMeans
().
get
(
natalBasinName
));
for
(
RiverBas
in
natalBasin
:
riverBasin
s
)
{
double
effective
=
Math
.
round
(
migrationBasin
.
getSpawnerOrigins
().
getMeans
().
get
(
natalBasin
.
get
Name
()
));
if
(
consoleDisplay
)
System
.
out
.
print
(
effective
+
"\t"
);
...
...
@@ -200,13 +210,15 @@ public class ExportExchangeSBetweenCatchments extends AquaNismsGroupProcess<Diad
// write in the file
if
(
fileNameOutput
!=
null
)
{
try
{
bW
.
write
(
time
.
getYear
(
group
.
getPilot
())
+
sep
+
migrationBasin
.
getName
()
+
sep
+
natalBasinName
);
bW
.
write
(
year
+
sep
+
migrationBasin
.
getName
()
+
sep
+
natalBasin
.
get
Name
()
);
bW
.
write
(
sep
+
effective
+
"\n"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
// put in exhanges
exchanges
.
get
(
migrationBasin
).
get
(
natalBasin
).
put
(
year
,
effective
);
}
if
(
consoleDisplay
)
{
System
.
out
.
println
();
...
...
@@ -224,4 +236,42 @@ public class ExportExchangeSBetweenCatchments extends AquaNismsGroupProcess<Diad
}
}
}
public
String
[][]
exportToR
()
{
int
i
,
j
;
String
[][]
export
=
new
String
[
riverBasins
.
length
+
1
][
riverBasins
.
length
+
1
];
// headers
export
[
0
][
0
]
=
"migrationBasin"
;
j
=
1
;
for
(
RiverBasin
natalBasin
:
riverBasins
)
{
export
[
0
][
j
]
=
natalBasin
.
getName
();
j
++;
}
i
=
1
;
for
(
RiverBasin
migrationBasin
:
riverBasins
)
{
export
[
i
][
0
]
=
migrationBasin
.
getName
();
j
=
1
;
for
(
RiverBasin
natalBasin
:
riverBasins
)
{
Map
<
Long
,
Double
>
year_effective
=
exchanges
.
get
(
migrationBasin
).
get
(
natalBasin
);
int
n
=
0
;
double
sum
=
0
;
for
(
Double
effective
:
year_effective
.
values
())
{
if
(
Double
.
isFinite
(
effective
))
{
n
++;
sum
+=
effective
;
}
}
export
[
i
][
j
]
=
String
.
valueOf
(
Math
.
round
(
10
.
*
sum
/
n
)
/
10
);
j
++;
}
i
++;
}
return
export
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment