Structures representing fleet file components

gadget_fleet_component(type,
        name = type,
        livesonareas = unique(data$area),
        multiplicative = 1,
        suitability = NULL,
        fleetfile = 'fleet',
        data = stop("data not provided"),
        ...)

Arguments

type

Required. Type of fleet component to create, e.g. 'totalfleet'

name

Optional. A descriptive name for the fleet component, defaults to the type.

livesonareas

Optional. Vector of area names, defaults to all unique areas in data.

multiplicative

Optional. Defaults to 1

suitability

Optional. Defaults to empty string

fleetfile

Optional. The fleet file to put the component in. Defaults to 'fleet'.

data

Required. The data.frame to use for 'amountfile'. Areas are translated into integers before adding to amountfile.

...

Extra parameters for the component, see details

Details

effortfleet requires the following extra parameters:

catchability

A list of stock names to catchability constants

quotafleet requires the following extra parameters:

quotafunction

Function name, e.g. 'simple'

biomasslevel

Vector of biomass levels

quotalevel

Vector of fishing levels

Value

A gadget_fleet_component object that can them be added to a fleetfile with gadget_dir_write

Examples

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

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

    # Define 2 vessels
    mfdb_import_vessel_taxonomy(mdb, data.frame(
        name = c('1.RSH', '2.COM'),
        full_name = c('Research', 'Commercial'),
        stringsAsFactors = FALSE))

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

    # Make a 'totalfleet' component
    fc <- gadget_fleet_component(
        'totalfleet',
        name = 'research',
        data = mfdb_sample_count(mdb, c(), list(
            vessel = '1.RSH',
            area = mfdb_group(x = 'divA', y = 'divB'),
            year = 1998,
            step = mfdb_timestep_yearly))[[1]])
    fc
#> $totalfleet
#> [1] "research"
#> 
#> $livesonareas
#> x y 
#> 1 2 
#> 
#> $multiplicative
#> [1] 1
#> 
#> $suitability
#> NULL
#> 
#> $amount
#> ; Generated by mfdb 7.3.99
#> ; -- data --
#> ; year	step	area	fleetname	number
#> 1998	1	1	research	107.658659610897
#> 1998	1	2	research	187.917677171063
#> 
#> attr(,"fleetfile")
#> [1] "fleet"
#> attr(,"class")
#> [1] "gadget_totalfleet_component" "gadget_fleet_component"     

    # Write out to a directory
    gadget_dir_write(gd, fc)

    gadget_fleet_component(
        'effortfleet',
        name = 'commercial',
        suitability = "function constant 4;",
        catchability = list(stockA=4, stockB=5),
        quotafunction = 'simple',
        biomasslevel = c(1000, 2000),
        quotalevel = c(0.1, 0.4, 0.9),
        data = mfdb_sample_count(mdb, c(), list(
            vessel = '2.COM',
            area = mfdb_group(x = 'divA', y = 'divB'),
            year = 1998,
            step = mfdb_timestep_yearly))[[1]])
#> $effortfleet
#> [1] "commercial"
#> 
#> $livesonareas
#> x y 
#> 1 2 
#> 
#> $multiplicative
#> [1] 1
#> 
#> $suitability
#> [1] "function constant 4;"
#> 
#> $catchability
#> NULL
#> 
#> $stockA
#> [1] 4
#> 
#> $stockB
#> [1] 5
#> 
#> $amount
#> ; Generated by mfdb 7.3.99
#> ; -- data --
#> ; year	step	area	fleetname	number
#> 1998	1	1	commercial	151.31712609902
#> 1998	1	2	commercial	141.063802621793
#> 
#> attr(,"fleetfile")
#> [1] "fleet"
#> attr(,"class")
#> [1] "gadget_effortfleet_component" "gadget_fleet_component"      

    gadget_fleet_component(
        'quotafleet',
        name = 'commercial',
        suitability = "function constant 4;",
        catchability = list(stockA=4, stockB=5),
        quotafunction = 'simple',
        biomasslevel = c(1000, 2000),
        quotalevel = c(0.1, 0.4, 0.9),
        data = mfdb_sample_count(mdb, c(), list(
            vessel = '2.COM',
            area = mfdb_group(x = 'divA', y = 'divB'),
            year = 1998,
            step = mfdb_timestep_yearly))[[1]])
#> $quotafleet
#> [1] "commercial"
#> 
#> $livesonareas
#> x y 
#> 1 2 
#> 
#> $multiplicative
#> [1] 1
#> 
#> $suitability
#> [1] "function constant 4;"
#> 
#> $quotafunction
#> [1] "simple"
#> 
#> $biomasslevel
#> [1] 1000 2000
#> 
#> $quotalevel
#> [1] 0.1 0.4 0.9
#> 
#> $amount
#> ; Generated by mfdb 7.3.99
#> ; -- data --
#> ; year	step	area	fleetname	number
#> 1998	1	1	commercial	151.31712609902
#> 1998	1	2	commercial	141.063802621793
#> 
#> attr(,"fleetfile")
#> [1] "fleet"
#> attr(,"class")
#> [1] "gadget_quotafleet_component" "gadget_fleet_component"     

    mfdb_disconnect(mdb)