5. Pre/post processing of OSMOSE model

In this section, the pre/post processing tools of the osmose package are presented

5.1. Library loading

require("osmose")

ls("package:osmose")
Le chargement a nécessité le package : osmose
 [1] "correct_ltl_file"        "existOsmoseParameter"   
 [3] "extract_grid_mask"       "extract_grid_param"     
 [5] "find_species_index"      "getAverageMortality"    
 [7] "getFishingBaseRate"      "getFishingMortality"    
 [9] "getMortality"            "getMortalityDeviation"  
[11] "getOsmoseParameter"      "getSizeSpectrum"        
[13] "getVar"                  "make_movement_netcdf"   
[15] "osmose2R"                "read_osmose"            
[17] "readOsmoseConfiguration" "report"                 
[19] "run_osmose"              "runOsmose"              
[21] "writeFishingFiles"       "write_osmose"           
[23] "write.osmose"

5.2. Reading Osmose parameters

The loading of Osmose parameters is achieved by using the readOsmoseConfiguration function. The output parameters are stored as strings in a recursive list.

The parameters are accessed by using the getOsmoseParameter function, which returns the parameter in the proper format.

Warning

You can get access to the parameters by using the list format. However, numerical variables will be returned as strings instead of a numerics

suppressMessages(require("osmose"))

# recover the reference configuration file
filename = system.file(package="osmose", "extdata", "master", "osm_all-parameters.csv")

# load the Osmose configuration file
osmConf = readOsmoseConfiguration(filename)

# Summarize the configuration
summary(osmConf)
cat("\n")

# Recovers some parameters
ncpu = getOsmoseParameter(osmConf, "simulation", "ncpu")

# proper way to recover the season parameter (returns a vector of numeric)
map0season = getOsmoseParameter(osmConf, "movement", "season", "map0")
cat("is.vector(map0season) =", is.vector(map0season), "\n")

# Bad way to recover the map0 season parameter (returns a string)
map0season_bis = osmConf$movement$season$map0
cat("is.character(map0season_bis) =", is.character(map0season_bis), "\n")
             Length Class  Mode
simulation    7     -none- list
mortality     5     -none- list
osmose        2     -none- list
output       20     -none- list
movement      6     -none- list
predation     4     -none- list
reproduction  1     -none- list
species      12     -none- list
ltl           3     -none- list
plankton      6     -none- list
grid          6     -none- list
population    1     -none- list

is.vector(map0season) = TRUE 
is.character(map0season_bis) = TRUE

Furthermore, some parameters can be plotted for a given species. This is done as follows:

# Plotting reproduction growth
png(filename = 'species.png')
plot(osmConf, what="species", species=0)

# Plotting reproduction seasonality
png(filename = 'reproduction.png')
plot(osmConf, what="reproduction", species=1) 

# Plotting size range for predation
png(filename = 'predation.png')
plot(osmConf, what="predation", species=2)
_images/species.png

Fig. 5.1 Growth parameters for species 0

_images/reproduction.png

Fig. 5.2 Reproduction seasonality for species 1

_images/predation.png

Fig. 5.3 Predation size range for species 2

5.3. Running the model

OSMOSE Java can be run from R by using the run_osmose function.

library("osmose")

# recover the reference configuration file
filename = system.file(package="osmose", "extdata", "master", "osm_all-parameters.csv")

# setting output directory
outdir = 'output'

# default run mode (java file in inst/java/)
runOsmose(input=fileName, output=outdir)

By default, the OSMOSE Java included in the package is used. However, the user is free to use another build of the OSMOSE Java program as follows:

# Running Osmose by using another version of the .jar file.
jarfile = "/home/nbarrier/Modeles/osmose/svn-osmose/trunk/dist/osmose-trunk.jar"
runOsmose(osmose=jarfile, input=fileName, 
          output=outdir, version="4")

Warning

The way the OSMOSE Java core is called has changed between versions 3 and 4. As a consequence, the user must be sure to properly set the version argument.

5.4. Reading outputs

The reading of outputs is achieved by using the read_osmose function:

library("osmose")

data = read_osmose(path='output') 

The content of the data object can be obtained as follows:

names(data)
 [1] "model"                  "species"                "biomass"               
 [4] "abundance"              "yield"                  "yieldN"                
 [7] "mortality"              "meanTL"                 "meanTLCatch"           
[10] "biomassByTL"            "predatorPressure"       "predPreyIni"           
[13] "dietMatrix"             "meanSize"               "meanSizeCatch"         
[16] "SizeSpectrum"           "abundanceBySize"        "biomassBySize"         
[19] "yieldBySize"            "yieldNBySize"           "meanTLBySize"          
[22] "mortalityBySize"        "dietMatrixBySize"       "predatorPressureBySize"
[25] "abundanceByAge"         "biomassByAge"           "yieldByAge"            
[28] "yieldNByAge"            "meanSizeByAge"          "meanTLByAge"           
[31] "mortalityByAge"         "dietMatrixByAge"        "predatorPressureByAge" 
[34] "config"

Variables are accessed by using the getVar function, which allows to apply some operations prior to extraction (average over the replicates, conversion into a list or a matrix):

library("osmose")

data = read_osmose("output")

biom = getVar(data, "biomass")
class(biom)
dim(biom)
cat("\n")

# expected = TRUE if mean over replicate should be returned
# only works for data that inherits from array
biom = getVar(data, "biomass", expected=TRUE)
class(biom)
dim(biom)
cat("\n")

biom = getVar(data, "biomass", how="list")
class(biom)
names(biom)
cat(biom$OctopusVulgaris)
cat("\n")

biom = getVar(data, "dietMatrix")
class(biom)
cat("\n")

biom = getVar(data, "dietMatrix", how="list")
class(biom)
[1] "osmose.biomass" "array"         
[1] 120  11   3

[1] "matrix"
[1] 120  11

[1] "list"
 [1] "OctopusVulgaris"       "MelicertusKerathurus"  "MetapenaeusMonoceros" 
 [4] "TrachurusTrachurus"    "SardinaPilchardus"     "SardinellaAurita"     
 [7] "EngraulisEncrasicolus" "DiplodusAnnularis"     "MustelusMustelus"     
[10] "MerlucciusMerluccius"  "PagellusErythrinus"   
0 0 0 0 0 0 0 0 15781.6 48488.35 39828.78 31787.74 25370.59 20248.9 53191.6 115545.1 92327.91 77744.52 65830.65 54840.04 78690.15 145137.3 106689.6 89557.24 75448.63 63581.84 94315.63 169401.6 128161.3 111114 97743.36 85284.81 111553.3 178472.8 129631.5 112778.2 100447.8 89032.81 106923.4 139955.4 85951.02 74232.06 65498.5 57923.74 69083.21 90930.17 56089.03 46699.82 39921.29 33900.61 45667.22 79728.92 58529.65 51139.86 43699.58 37645.97 53456.19 95171.82 68095.26 58712.88 50206.31 43868.15 59624.38 97738.27 69175.62 58875.63 51371.91 44305.12 59683.55 93388.94 65217.48 56079.13 49641.77 43834.97 53074.88 72633.85 47046.89 40593.72 35075.18 29524 44159.88 76601.57 57293.17 49263.57 42465.76 35690.89 45178.8 70766.41 49709.73 43180.91 37478.74 32417.84 44701.4 80692.32 58009.92 49221.96 42412.14 36096.7 46507.37 74249.08 51200.34 43819.48 37942.7 33084.75 40183.11 71830.84 50153.7 43088.12 36432.06 30797.93 36590.15 58218.22 38542.19 32620.02 27619.44 23506.24 28160.44 50781.51 35485.84 30303.21
[1] "osmose.dietMatrix" "list"             

[1] "list"

The first argument is the data object obtained by using the read_osmose function, while the second argument is the name of the variable to extract.

5.5. Plotting outputs

Plotting Osmose outputs is achieved by calling the generic plot function on the osmose object, output by the read_osmose function. The function takes as argument the variable to be displayed (what argument). The species argument allows to specify the indexes of the species to display (cf. the X in the species.name.spX parameters).

library("osmose")

data = read_osmose(path='output') 

test = getVar(data, "species")

png(file="biomass.png")
plot(data, what="biomass")

png(file="abundance.png")
plot(data, what="abundance", species=c(0, 1, 2))

png(file="yield.png")
plot(data, what="yield")

png(file="yieldN.png")
plot(data, what="yieldN")

Hint

When several replicates are run, the uncertainty due to the stochastic mortality is displayed as a grey shading.

Warning

At this time, only these four variables can be plotted. However, more plot functions (diet matrix, mortality, etc.) will be released soon.


_images/biomass.png

Fig. 5.4 Biomass plot

_images/abundance.png

Fig. 5.5 Abundance plot

_images/yield.png

Fig. 5.6 Yield biomass plot

_images/yieldN.png

Fig. 5.7 Yield abundance plot