7.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" "mortality" "meanTL"
[7] "meanTLCatch" "biomassByTL" "predatorPressure"
[10] "predPreyIni" "dietMatrix" "meanSize"
[13] "meanSizeCatch" "SizeSpectrum" "abundanceBySize"
[16] "biomassBySize" "meanTLBySize" "mortalityBySize"
[19] "dietMatrixBySize" "predatorPressureBySize" "abundanceByAge"
[22] "biomassByAge" "meanSizeByAge" "meanTLByAge"
[25] "mortalityByAge" "dietMatrixByAge" "predatorPressureByAge"
[28] "abundanceByTL" "yieldByFishery" "yield"
[31] "yieldN" "yieldBySize" "yieldNBySize"
[34] "yieldByAge" "yieldNByAge" "discards"
[37] "surveyBiomass" "surveyAbundance" "surveyYield"
[40] "sizeMature" "ageMature" "ingestion"
[43] "ingestionTot" "maintenance" "meanEnet"
[46] "sizeInf" "kappa" "abundAge1"
[49] "ingestByAge" "ingestBySize" "kappaByAge"
[52] "kappaBySize" "enetByAge" "enetBySize"
[55] "maintenanceByAge" "maintenanceBySize" "meanWeightByAge"
[58] "meanWeightBySize" "meanWeightByWeight" "yieldByWeight"
[61] "yieldNByWeight" "abundanceByWeight" "biomassByWeight"
[64] "yield.fishery0" "yield.fishery1" "yield.fishery2"
[67] "yield.fishery3" "yield.fishery4" "yield.fishery5"
[70] "yield.fishery6" "yield.fishery7" "yield.fishery8"
[73] "yield.fishery9" "yield.fishery10" "yield.fishery11"
[76] "yield.fishery12" "yield.fishery13" "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")
getwd()
input.dir = file.path("eec_4.3.0", "output-PAPIER-trophic")
data = read_osmose(input.dir)
biom = get_var(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 = get_var(data, "biomass", expected=TRUE)
class(biom)
dim(biom)
cat("\n")
biom = get_var(data, "biomass", how="list")
class(biom)
names(biom)
cat(biom$OctopusVulgaris)
cat("\n")
biom = get_var(data, "dietMatrixByAge")
class(biom)
cat("\n")
biom = get_var(data, "dietMatrixByAge", how="list")
class(biom)
[1] "/home/barrier/Codes/osmose/git-osmose/doc"
[1] "osmose.biomass" "array"
[1] 30 14 1
[1] "matrix" "array"
[1] 30 14
[1] "list"
[1] "lesserSpottedDogfish" "redMullet" "pouting"
[4] "whiting" "poorCod" "cod"
[7] "dragonet" "sole" "plaice"
[10] "horseMackerel" "mackerel" "herring"
[13] "sardine" "squids"
[1] "osmose.dietMatrixByAge" "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.
7.4.1. Reading NetCDF outputs
In the new Osmose version, the user has the possibility to save outputs as NetCDF (.nc) instead of CSV (.csv) files. However, no function has been provided to automatically read all the Osmose NetCDF files. Therefore, scripts must be written by the user, following the example shown below:
rm(list=ls())
library("ncdf4")
filename = file.path("rosmose", "_static",
"gogosm_mortalityRateDistribByAge-OctopusVulgaris_Simu0.nc")
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ fid")
fid = nc_open(filename)
print(fid)
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ vars")
var = fid$var
print(names(var))
mort = ncvar_get(fid, "mortality")
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ dims")
dims = fid$dim
print(names(dims))
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ mortality")
mcause = ncvar_get(fid, "mortality_cause")
attrs = ncatt_get(fid, "mortality_cause")
print(attrs)
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ age")
age = ncvar_get(fid, "Age")
print(age)
[1] "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ fid"
File rosmose/_static/gogosm_mortalityRateDistribByAge-OctopusVulgaris_Simu0.nc (NC_FORMAT_CLASSIC):
1 variables (excluding dimension variables):
float mortality[mortality_cause,Age,time]
units:
description: Predation (Mpred), Starvation (Mstarv), Other Natural mortality (Mnat), Fishing (F) & Out-of-domain (Z) mortality rates per time step of saving and per size class. Z is the total mortality for migratory fish outside the simulation grid. To get annual mortality rates, sum the mortality rates within one year.
_FillValue: -99
3 dimensions:
time Size:12 *** is unlimited ***
units: days since 0-1-1 0:0:0
calendar: 360_day
description: time ellapsed, in days, since the beginning of the simulation
Age Size:25
mortality_cause Size:6
mortality_cause0: PREDATION
mortality_cause1: STARVATION
mortality_cause2: ADDITIONAL
mortality_cause3: FISHING
mortality_cause4: OUT
mortality_cause5: OXY
[1] "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ vars"
[1] "mortality"
[1] "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ dims"
[1] "time" "Age" "mortality_cause"
[1] "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ mortality"
$mortality_cause0
[1] "PREDATION"
$mortality_cause1
[1] "STARVATION"
$mortality_cause2
[1] "ADDITIONAL"
$mortality_cause3
[1] "FISHING"
$mortality_cause4
[1] "OUT"
$mortality_cause5
[1] "OXY"
[1] "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ age"
[1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24