Structures representing a GADGET stock file

gadget_stockfile_extremes(stock_name, data)
gadget_stockfile_refweight(stock_name, data)
gadget_stockfile_initialconditions(stock_name, data)
gadget_stockfile_recruitment(stock_name, data)

Arguments

stock_name

A name, e.g. cod.imm, used as the name for the stockfile

data

A data.frame used to generate the data. See details.

Details

The columns required in the data varies depends on which function you are using.

gadget_stockfile_extremes requires age and length columns and populates minlength, minage, maxlength, maxage. The values are obtained by the grouping used, rather than the maximum values in the data. If you want the minimum and maximum from the data, query with length = NULL, age = NULL, so the table contains "all" and the grouping contains the actual minimum and maximum.

gadget_stockfile_refweight requires a length column and a mean column representing mean weight for that length group. It populates the refweightfile and dl.

gadget_stockfile_initialconditions requires area, age, length, number and mean (weight) columns. Populates initialconditions minlength, minage, maxlength, maxage, dl and the numberfile. As before, the min/max values are populated using the groupings you specify, not the min/max available data.

gadget_stockfile_recruitment requires year, step, area, age, length, number and mean (weight) columns. Populates doesrenew, minlength, maxlength, dl, numberfile.

Value

The return value is a gadget_stockfile object that can be written to the filesystem with gadget_dir_write.

Examples


mdb <- mfdb(tempfile(fileext = '.duckdb'))
#> 2022-11-16 12:34:23 INFO:mfdb:Creating schema from scratch
#> 2022-11-16 12:34:23 INFO:mfdb:Taxonomy market_category no updates to make
#> 2022-11-16 12:34:24 INFO:mfdb:Schema up-to-date

# Define 2 areacells of equal size
mfdb_import_area(mdb, data.frame(name=c("divA", "divB"), size=1))

# Make up some samples
samples <- expand.grid(
    year = 1998,
    month = c(1:12),
    areacell = c("divA", "divB"),
    species = 'COD',
    age = c(1:5),
    length = c(0,40,80))
samples$count <- runif(nrow(samples), 20, 90)
mfdb_import_survey(mdb, data_source = "x", samples)

imm_data <- mfdb_sample_meanweight(mdb, c('age', 'length'), list(
    age = NULL, # The age column will say 'all', but will know the min/max
    length = mfdb_step_interval('', 10, to = 100),
    species = 'COD'))

# Write both min/max and refweighfile into our gadget directory
component <- gadget_stockfile_extremes('cod.imm', imm_data[[1]])
component
#> [[1]]
#> [[1]]$stockname
#> [1] "cod.imm"
#> 
#> [[1]]$minage
#> [1] 1
#> 
#> [[1]]$maxage
#> [1] 5
#> 
#> [[1]]$minlength
#> [1] 0
#> 
#> [[1]]$maxlength
#> [1] 100
#> 
#> 
#> attr(,"stock_name")
#> [1] "cod.imm"
#> attr(,"class")
#> [1] "gadget_stockfile_extremes" "gadget_stockfile"         

component <- gadget_stockfile_refweight('cod.imm', imm_data[[1]])
component
#> [[1]]
#> [[1]]$dl
#> [1] 10
#> 
#> [[1]]$refweightfile
#> ; Generated by mfdb 7.3.99
#> ; -- data --
#> ; length	weight
#> 0	NA
#> 40	NA
#> 80	NA
#> 
#> 
#> attr(,"stock_name")
#> [1] "cod.imm"
#> attr(,"class")
#> [1] "gadget_stockfile_refweight" "gadget_stockfile"          

gadget_dir_write(gadget_directory(tempfile()), component)

mfdb_disconnect(mdb)