# 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] "predatorPressure"       "predPreyIni"            "dietMatrix"
[13] "meanSize"               "meanSizeCatch"          "biomassBySize"
[16] "yieldBySize"            "mortalityBySize"        "dietMatrixBySize"
[19] "predatorPressureBySize" "biomassByAge"           "mortalityByAge"
[22] "dietMatrixByAge"        "predatorPressureByAge"  "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("astart", "_static", "gog_v4", "output")
data = read_osmose(input.dir)

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] "/home/nbarrier/Modeles/osmose/git-applis/doc_user" [1] "osmose.biomass" "array" [1] 120 11 2 [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 14891.16 46741.26 38375.67 30627.71 24444.62 19509.86 49741.34 107132.6 85972.04 72108.63 60721.1 50699.62 78041.32 148337.2 114610.9 95813.85 80558.64 67609.66 94155.57 171545.6 132456.3 114153.4 101113.9 89551.95 107530.1 163571.4 108648.5 94115.12 82979.13 72561.16 90979.27 138685.1 90566.71 78443.33 68583.82 60000.33 80823.12 124621.4 83601.49 72902.04 64559.43 56044.97 66635.52 101412.9 68321.84 58053.17 49468.77 42364.26 55502.25 85742.26 58174.74 49620.63 42588.04 37047.14 49974.27 79586.16 55007.96 46599.91 39674.82 33858.97 45228.08 67812.83 50674.97 42698.28 36615.02 31103 40453.41 65057.78 47236.47 39444.73 34904.08 29485.93 42033.85 64170.78 45497.85 39086.29 33575.53 28807.78 42485.54 65427.74 46010.14 39134.78 34178.96 29293.95 37487.74 57341.83 40080.67 34166.77 29383.83 25668.52 37918.29 63708.44 45625.16 38005.8 32557.42 27579.8 39196.49 70540.89 51387.9 45079.81 39321.64 33058.05 39183.27 63203.5 40880.41 34241.62 29211.16 24971.61 32598.48 60469.79 43863.51 38004.45 [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.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