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
03b203c3
Commit
03b203c3
authored
Oct 25, 2019
by
Lambert Patrick
Browse files
write biomass and effective fluxes
parent
55dd75d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
data/input/fishTryRealBV_CC.xml
View file @
03b203c3
...
...
@@ -214,7 +214,9 @@
<processesEachStep>
<environment.InformTime>
<synchronisationMode>
ASYNCHRONOUS
</synchronisationMode>
<consoleDisplay>
true
</consoleDisplay>
</environment.InformTime>
<species.PlopProcess>
<synchronisationMode>
ASYNCHRONOUS
</synchronisationMode>
<temporisation>
0
</temporisation>
...
...
@@ -273,18 +275,12 @@
<mortalityRateInOffshore>
0.4
</mortalityRateInOffshore>
</species.Survive>
<species.WriteEffectivesFluxes>
<species.WriteEffective
AndBiomas
sFluxes>
<synchronisationMode>
ASYNCHRONOUS
</synchronisationMode>
<exportSeason>
SPRING
</exportSeason>
<fileNameOutput>
effectiveFluxes
</fileNameOutput>
</species.WriteEffectivesFluxes>
<species.WriteBiomassFluxes>
<synchronisationMode>
ASYNCHRONOUS
</synchronisationMode>
<exportSeason>
SPRING
</exportSeason>
<fileNameOutput>
BiomassFluxessBeforeReproduction
</fileNameOutput>
</species.WriteBiomassFluxes>
<fileNameOutput>
effectiveBiomassFluxesBeforeReproduction
</fileNameOutput>
</species.WriteEffectiveAndBiomassFluxes>
<species.ReproduceAndSurviveAfterReproductionWithDiagnose>
<synchronisationMode>
ASYNCHRONOUS
</synchronisationMode>
<reproductionSeason>
SPRING
</reproductionSeason>
...
...
src/main/java/species/NutrientRoutine.java
View file @
03b203c3
...
...
@@ -116,11 +116,11 @@ public class NutrientRoutine {
private
Map
<
String
,
Double
>
compoJuvenile
;
private
transient
NutrientFluxesCollection
nutrientFluxesCollection
;
private
transient
Nutrient
Import
FluxesCollection
nutrient
Import
FluxesCollection
;
public
NutrientRoutine
()
{
this
.
nutrientFluxesCollection
=
new
NutrientFluxesCollection
();
this
.
nutrient
Import
FluxesCollection
=
new
Nutrient
Import
FluxesCollection
();
}
/**
...
...
@@ -155,17 +155,17 @@ public class NutrientRoutine {
this
.
juvenileFeatures
=
juvenileFeatures
;
this
.
compoJuvenile
=
compoJuvenile
;
this
.
nutrientFluxesCollection
=
new
NutrientFluxesCollection
();
this
.
nutrient
Import
FluxesCollection
=
new
Nutrient
Import
FluxesCollection
();
}
public
void
createNutrienFluxesCollection
(
String
[]
basinNames
)
{
nutrientFluxesCollection
=
new
NutrientFluxesCollection
();
nutrientFluxesCollection
.
setBasinNames
(
basinNames
);
nutrient
Import
FluxesCollection
=
new
Nutrient
Import
FluxesCollection
();
nutrient
Import
FluxesCollection
.
setBasinNames
(
basinNames
);
}
public
NutrientFluxesCollection
getNutrientFluxesCollection
()
{
return
nutrientFluxesCollection
;
public
Nutrient
Import
FluxesCollection
getNutrientFluxesCollection
()
{
return
nutrient
Import
FluxesCollection
;
}
/**
...
...
@@ -546,9 +546,10 @@ public class NutrientRoutine {
}
public
class
NutrientFluxesCollection
{
public
class
Nutrient
Import
FluxesCollection
{
/*
* collection of import fluxes (from sea to rivers)
* <key> Year
* <value>
* <key> Nutrient
...
...
@@ -558,21 +559,37 @@ public class NutrientRoutine {
* <key> destination basin name
* <value> flux
*/
//
private
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
fluxesCollection
;
private
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
importFluxesCollection
;
/*
* collection of export fluxes (from river to sea)
* <key> Year
* <value>
* <key> Nutrient
* <value>
* <key> origin basin name
* <value> flux
*/
private
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Double
>>>
exportFluxesCollection
;
private
transient
String
[]
basinNames
;
NutrientFluxesCollection
()
{
Nutrient
Import
FluxesCollection
()
{
fluxesCollection
=
new
HashMap
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
();
importFluxesCollection
=
new
HashMap
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
();
exportFluxesCollection
=
new
HashMap
<
Long
,
Map
<
String
,
Map
<
String
,
Double
>>>
();
}
public
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
getFluxesCollection
()
{
return
f
luxesCollection
;
public
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
get
Import
FluxesCollection
()
{
return
importF
luxesCollection
;
}
public
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Double
>>>
getExportFluxesCollection
()
{
return
exportFluxesCollection
;
}
public
void
setBasinNames
(
String
[]
basinNames
)
{
this
.
basinNames
=
basinNames
;
}
...
...
@@ -580,7 +597,7 @@ public class NutrientRoutine {
public
void
put
(
Long
year
,
String
nutrient
,
String
originBasinName
,
String
destinationBasinName
,
Double
flux
)
{
if
(!
f
luxesCollection
.
containsKey
(
year
))
{
if
(!
importF
luxesCollection
.
containsKey
(
year
))
{
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>
nutrientsMap
=
new
TreeMap
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>();
...
...
@@ -600,15 +617,69 @@ public class NutrientRoutine {
nutrientsMap
.
put
(
nutrientOfInterest
,
originsMap
);
}
f
luxesCollection
.
put
(
year
,
nutrientsMap
);
importF
luxesCollection
.
put
(
year
,
nutrientsMap
);
}
double
previousFlux
=
f
luxesCollection
.
get
(
year
).
get
(
nutrient
).
get
(
originBasinName
).
get
(
destinationBasinName
);
f
luxesCollection
.
get
(
year
).
get
(
nutrient
).
get
(
originBasinName
).
put
(
destinationBasinName
,
previousFlux
+
flux
);
double
previousFlux
=
importF
luxesCollection
.
get
(
year
).
get
(
nutrient
).
get
(
originBasinName
).
get
(
destinationBasinName
);
importF
luxesCollection
.
get
(
year
).
get
(
nutrient
).
get
(
originBasinName
).
put
(
destinationBasinName
,
previousFlux
+
flux
);
}
}
public
class
NutrientExportFluxesCollection
{
/*
* <key> Year
* <value>
* <key> Nutrient
* <value>
* <key> origin basin name
* <value> flux
*/
//
private
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Double
>>>
exportFluxesCollection
;
private
transient
String
[]
basinNames
;
NutrientExportFluxesCollection
()
{
exportFluxesCollection
=
new
HashMap
<
Long
,
Map
<
String
,
Map
<
String
,
Double
>>>
();
}
public
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Double
>>>
getFluxesCollection
()
{
return
exportFluxesCollection
;
}
public
void
setBasinNames
(
String
[]
basinNames
)
{
this
.
basinNames
=
basinNames
;
}
public
void
put
(
Long
year
,
String
nutrient
,
String
originBasinName
,
Double
flux
)
{
if
(!
exportFluxesCollection
.
containsKey
(
year
))
{
Map
<
String
,
Map
<
String
,
Double
>>
nutrientsMap
=
new
TreeMap
<
String
,
Map
<
String
,
Double
>>();
for
(
String
nutrientOfInterest
:
nutrientsOfInterest
)
{
Map
<
String
,
Double
>
originsMap
=
new
TreeMap
<
String
,
Double
>();
for
(
String
originName
:
basinNames
)
{
originsMap
.
put
(
originName
,
0
.);
}
nutrientsMap
.
put
(
nutrientOfInterest
,
originsMap
);
}
exportFluxesCollection
.
put
(
year
,
nutrientsMap
);
}
double
previousFlux
=
exportFluxesCollection
.
get
(
year
).
get
(
nutrient
).
get
(
originBasinName
);
exportFluxesCollection
.
get
(
year
).
get
(
nutrient
).
put
(
originBasinName
,
previousFlux
+
flux
);
}
}
}
src/main/java/species/WriteEffectiveAndBiomassFluxes.java
0 → 100644
View file @
03b203c3
/**
* patrick.lambert
* @author Patrick Lambert
* @copyright Copyright (c) 2018, Irstea
*
* 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.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.HashMap
;
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
species.DiadromousFish.Stage
;
/**
*
*/
public
class
WriteEffectiveAndBiomassFluxes
extends
AquaNismsGroupProcess
<
DiadromousFish
,
DiadromousFishGroup
>
{
private
Season
exportSeason
=
Season
.
SPRING
;
private
String
fileNameOutput
=
"effectiveBiomassFluxes"
;
private
transient
BufferedWriter
bW
;
private
transient
String
sep
=
";"
;
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
((
new
XStream
(
new
DomDriver
()))
.
toXML
(
new
WriteEffectiveAndBiomassFluxes
()));
}
/* (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
+
"type"
+
sep
+
"originBasin"
);
//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
();
}
}
}
if
(
Time
.
getSeason
(
pilot
)
==
exportSeason
&
Time
.
getYear
(
pilot
)
>=
group
.
getMinYearToWrite
())
{
//Create the map to get the biomass in each migration basin and birth basin
Map
<
String
,
Map
<
String
,
Long
>>
spawnerEffectivePerDestination
=
new
HashMap
<
String
,
Map
<
String
,
Long
>>(
group
.
getEnvironment
().
getRiverBasinNames
().
length
);
//Create the map to get the abundance in each migration and birth birth basin
Map
<
String
,
Map
<
String
,
Double
>>
spawnerBiomassPerDestination
=
new
HashMap
<
String
,
Map
<
String
,
Double
>>(
group
.
getEnvironment
().
getRiverBasinNames
().
length
);
// initialise maps with 0
for
(
String
destinationName:
group
.
getEnvironment
().
getRiverBasinNames
())
{
Map
<
String
,
Long
>
spawnerEffectivePerOrigin
=
new
HashMap
<
String
,
Long
>(
group
.
getEnvironment
().
getRiverBasinNames
().
length
);
Map
<
String
,
Double
>
spawnerBiomassPerOrigin
=
new
HashMap
<
String
,
Double
>(
group
.
getEnvironment
().
getRiverBasinNames
().
length
);
for
(
String
originName
:
group
.
getEnvironment
().
getRiverBasinNames
()){
spawnerEffectivePerOrigin
.
put
(
originName
,
0L
);
spawnerBiomassPerOrigin
.
put
(
originName
,
0
.);
}
spawnerEffectivePerDestination
.
put
(
destinationName
,
spawnerEffectivePerOrigin
);
spawnerBiomassPerDestination
.
put
(
destinationName
,
spawnerBiomassPerOrigin
);
}
for
(
RiverBasin
destinationBasin:
group
.
getEnvironment
().
getRiverBasins
())
{
//compute the cumulative effective and biomass per birth basin
if
(
destinationBasin
.
getFishs
(
group
)
!=
null
)
{
for
(
DiadromousFish
fish
:
destinationBasin
.
getFishs
(
group
))
{
if
(
fish
.
getStage
()
==
Stage
.
MATURE
)
{
String
originBasinName
=
fish
.
getBirthBasin
().
getName
();
spawnerEffectivePerDestination
.
get
(
destinationBasin
.
getName
()).
put
(
originBasinName
,
spawnerEffectivePerDestination
.
get
(
destinationBasin
.
getName
()).
get
(
originBasinName
)
+
fish
.
getAmount
()
);
double
biomass
=
group
.
getNutrientRoutine
().
getWeight
(
fish
)
*
fish
.
getAmount
();
spawnerBiomassPerDestination
.
get
(
destinationBasin
.
getName
()).
put
(
originBasinName
,
spawnerBiomassPerDestination
.
get
(
destinationBasin
.
getName
()).
get
(
originBasinName
)
+
biomass
);
}
}
}
}
try
{
// write effective
for
(
String
originBasinName:
group
.
getEnvironment
().
getRiverBasinNames
())
{
bW
.
write
(
Time
.
getYear
(
pilot
)+
sep
+
"effective"
+
sep
+
originBasinName
);
for
(
String
destinationBasinName
:
group
.
getEnvironment
().
getRiverBasinNames
())
{
bW
.
write
(
sep
+
spawnerEffectivePerDestination
.
get
(
destinationBasinName
).
get
(
originBasinName
));
}
// write an end-of-line
bW
.
write
(
"\n"
);
}
// write biomass
for
(
String
originBasinName:
group
.
getEnvironment
().
getRiverBasinNames
())
{
bW
.
write
(
Time
.
getYear
(
pilot
)+
sep
+
"biomass"
+
sep
+
originBasinName
);
for
(
String
destinationBasinName
:
group
.
getEnvironment
().
getRiverBasinNames
())
{
bW
.
write
(
sep
+
spawnerBiomassPerDestination
.
get
(
destinationBasinName
).
get
(
originBasinName
));
}
// write an end-of-line
bW
.
write
(
"\n"
);
}
if
(
group
.
getPilot
().
getCurrentTime
()==
group
.
getPilot
().
getSimBegin
()+
group
.
getPilot
().
getSimDuration
()-
1
)
{
bW
.
flush
();
bW
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
src/main/java/species/WriteImportNutrientFluxes.java
View file @
03b203c3
...
...
@@ -47,7 +47,7 @@ public class WriteImportNutrientFluxes extends AquaNismsGroupProcess<DiadromousF
bW
.
write
(
"\n"
);
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
fluxesCollection
=
group
.
getNutrientRoutine
().
getNutrientFluxesCollection
().
getFluxesCollection
();
Map
<
Long
,
Map
<
String
,
Map
<
String
,
Map
<
String
,
Double
>>>>
fluxesCollection
=
group
.
getNutrientRoutine
().
getNutrientFluxesCollection
().
get
Import
FluxesCollection
();
// to iterate on sorted years
List
<
Long
>
years
=
new
ArrayList
<
Long
>(
fluxesCollection
.
keySet
());
...
...
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