data-raw/WSS_collapsed.R

#Western Scotian Shelf Model (No stanza groups)
#SML

#User parameters

#-------------------------------------------------------------------------------
#Required packages
library(data.table); library(Rpath); library(here); library(readxl)

#-------------------------------------------------------------------------------
#User created functions

#-------------------------------------------------------------------------------
#Western Scotian Shelf Groups - collapsed list (no multistanza groups)
groups <- c('Whales', 'Toothed cetaceans', 'Seals', 'Sea birds', 'Sharks', 
            'Large pelagics', 'Cod', 'S Hake', 'Halibut', 'Pollock', 
            'D piscivores', 'L benthivores', 'Skates', 'Dogfish', 'Redfish', 
            'A plaice', 'Flounders', 'Haddock', 'L sculpin', 'Herring', 
            'Other pelagic', 'Mackerel', 'Mesopelagic', 'Small-medium benthivores', 
            'Squids', 'Lobster', 'Large crabs', 'Small crabs', 'Shrimps', 'Scallop', 
            'Bivalves', 'Other molluscs', 'Other arthropoda', 'Echinoderms', 
            'Sessile benthic groups', 'Worms', 'Meiofauna','Gelatinous zoop', 
            'Macrozoop', 'Mesozoop', 'Microzoop', 'Microflora', 'Phytoplankton', 
            'Discards', 'Detritus', 'Fleet1')

#Identify type (0 = consumer, 1 = producer, 2 = detritus, 3 = fleet)
types <- c(rep(0, 42), 1, 2, 2, 3)

#Create parameter list object
WSS46.params <- create.rpath.params(groups, types)

#Fill in model parameters
#Biomass, Production, consumption
biomass <- c(0.407075, 0.049754, 0.04383, 0.00617, 0.0260249, 0.023573, 0.5752627,
             0.7525942, 0.02386296, 0.2825461, 0.3460134, 0.1559776, 0.137757, 
             2.102007, 2.253408, 0.1443158, 0.4183195, 1.095571, 0.1348786,
             5.758492, 0.86577, 0.535679, 0.012515, 0.037782, 0.173893, 0.301295, 
             0.157303, 0.965481, 1.302563, 0.646857, 63.37292, 2, 0.853, 12.63734, 
             26.02519, 7.345485, 4.09129, 0.5204, 41.31, 23.79555, 5.800508, 3.678861, 33.664, 0.063293,
             1, NA)

pb <- c(0.071, 0.18, 0.147007, 0.25, 0.18, 0.4, 0.607618, 1.475795, 0.28693, 0.637828,
        0.528589, 0.529134, 0.232082, 0.1393199, 0.242964, 0.426256, 0.566763,
        0.553228, 0.495396, 0.7064298, 0.74, 0.583, 0.97, 1.41, 4, 0.91, 0.654, 
        1.31, 3, 0.342, 0.69, 0.75, 4.4, 0.33, 0.32, 1.25, 10.8, 15.51, 3.04, NA, 
        82.8, 104.938, 70.639, rep(NA, 3))

qb <- c(4.94, 14.5, 7.338632, 87.6, 4.78, 4.24, 2.22494, 6.00205, 2.020085, 
        3.94136, 3.160823, 2.821233, 2.447539, 1.739802, 3.254867, 3.08827, 4.223,
        2.609985, 5.740644, 3.326162, 3.31, 5.08, 18.9, 4.7, 11.33333, rep(NA, 12), 
        62.05, 19.5, 73, rep(NA, 6))

WSS46.params$model[, Biomass := biomass]
WSS46.params$model[, PB      := pb]
WSS46.params$model[, QB      := qb]

#Production to Consumption
WSS46.params$model[Group %in% c('Lobster', 'Large crabs', 'Small crabs', 'Shrimps', 
                              'Scallop', 'Bivalves', 'Other molluscs', 'Other arthropoda', 
                              'Echinoderms', 'Sessile benthic groups', 'Worms', 
                              'Meiofauna'),
                 ProdCons := 0.15]
WSS46.params$model[Group == 'Mesozoop', ProdCons := 0.4]
WSS46.params$model[Group %in% c('Microzoop', 'Microflora'), ProdCons := 0.5]

#Biomass accumulation and unassimilated production
ba <- c(0.0032566, 0, 0.003702101, 0, -0.001951868, 0, -0.02876313, 0, 0, 
        -0.01130184, -0.01730067, -0.01559776, rep(0, 3), -0.01010211, 0,
        0.07668997, -0.00674393, rep(0, 6), 0.0301295, rep(0, 3), 0.03234285,
        rep(0, 15), NA)
WSS46.params$model[, BioAcc  := ba]
WSS46.params$model[, Unassim := c(rep(0.2, 38), rep(0.4, 3), 0.2, rep(0, 3), NA)]

#Detrital fate
WSS46.params$model[, Detritus := c(rep(1, 43), rep(0, 3))]
WSS46.params$model[, Discards := c(rep(0, 45), 1)]

#Landings/Discards
land <- c(rep(0, 4), 0.00209077, 0.005067847, 0.116104, 0.036881, 0.003272,
          0.09672, 0.058946, 0.004406, 0.000799, 0.01325133, 0.05914, 0.005274,
          0.021106, 0.090329, 0.002021, 0.950853, 0.019708, 0.048208, 0, 0, 0.001637, 0.203756,
          0.016668, 0, 0.000162, 0.106389, 0.010353, 0.00236, 0, 0.03026, 
          rep(0, 11), NA)
disc <- c(0, 0.002995, 0, 2.4E-05, 0.000575, 0.000469, 0.000286, 9.6E-05, 0.000306,
          0.00029, 0.002805, 0.000385, 0.013094, 0.009694, 0.00027, 9E-06,
          0.000372, 0.000111, 0.000883, 0.000211, 0.00056, 0.000276, 0, 0.000236,
          1.9E-05, 0.001526, 0.00725, 0.000633, 8E-06, 0, 0, 4.1E-05, 0, 0.016926,
          0.002943, rep(0, 10), NA)
WSS46.params$model[, Fleet1      := land]
WSS46.params$model[, Fleet1.disc := disc]

#Diet composition
DC.groups <- groups[which(!groups %in% c('Discards', 'Detritus', 'Fleet1'))]
DC.data <- as.data.table(matrix(c(
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0.006511993,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0.002663992,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0.002219998,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  1.60E-05,0.02950997,0.04260996,1.00E-06,0.1083579,0.01990398,0.002533272,1.01E-05,0.003230158,3.72E-05,0.004610747,0,0,0,0,0,0,0,0,0,0,0,0,0,1.30E-05,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.0042,0.2066628,0.01942298,0.000609998,0.009922989,0.03653397,0.1019249,0.05217623,0.1394296,0.08281286,0.08318212,0.01884649,0.002128295,0.006747999,0.00525781,0.0116024,0,0.006067672,0,0,0,0,0,0,0.002964,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0.001625999,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.000586,0.001667998,0.06197794,7.60E-05,0,0.001342999,0.000305295,0,0,0.000452922,0.01706825,0,0.000952189,0,0,0,0,0.002475319,0,0,0,0,0,0,0.000136,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0.005450995,0.002031998,3.40E-05,0.01506498,0.000345,0.000871167,0,0.01569448,8.40E-05,0.002534624,0,0,0.005926999,0,0,0,0,0,0,0,0,0,0,0.000544,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0.02202998,0.005664994,0,0.1266549,0.001036999,0.00161806,0,0.01197543,0.00020107,0.0182506,0.00956348,0.002093793,0.004761999,0,0,0,8.63E-05,0.000309706,0,0,0,0,0,0.000215,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0.006431994,0,0.000807999,0.002838997,1.57E-05,0,0,0,0.005297593,0,0,0,0,0,0,0,0,0,0,0,0,0,0.000187,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0.000467,0,0,0.05148594,0.01104599,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0.2010318,0,0.01671098,0.1353089,0.04610595,0,0,0.000411421,0.01896155,0,0.04869779,0.013318,0,0,0,0.000326364,0.003001982,0,0,0,0,0,0.004695,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0.001418999,2.20E-05,0,0.007809991,0.000204,0.008288263,0,0.000620986,0,0.01257421,0,0.00021003,0,0,0,0,0,0,0,0,0,0,0.002884003,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,2.90E-05,0.06341794,0,0.1497418,0.004294996,0.01848504,0,0.009127609,0,0.01063039,0.000170916,0,8.50E-05,0,0,0,0,0,0,0,0,0,0.004534005,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.012545,0.07445793,0.002529998,0.001488995,0.02710397,0.009244991,0.005095783,0.000534412,0.0329706,0.0109315,0.2203275,0,0,0,0,0,0,0.01041137,0.005067866,0,0,0,0,0,0.002768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0.01231399,0.000729,0,0.000163,0.000175483,0,0.007402087,0,0.02021118,0,0.001840081,0,0,0,0,0,0.001510052,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.16352,0.3334607,0.4925875,0.3092771,0.3986586,0.5882584,0.209409,0.01779894,0.405404,0.07667714,0.2481793,0,0.02304704,0.3108059,0,0,0,0.006918214,0,0,0,0,0,0,0.012258,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.0194,0.007396993,0.05680194,0.07663676,0.04387695,0.1276559,0.04879509,0.02281588,0.003064731,0.04530539,0.02639162,0.01663626,0.0321243,0.006191999,0.01858892,0.005184783,0.00622429,0.00722715,0.02353639,0,0,0,0,0,0.004734,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.010398,0.04417396,0.02815897,0.04363187,0.02364997,0.02666597,0.0281309,0,0.005847048,0.01108723,0.006816827,0,0,0.028541,0,0,0,0,0,0,0,0,0,0,0.003069,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0.002380993,0,0,5.14E-05,0,0,6.61E-05,0.000264903,0.01813501,0.000914232,7.00E-06,1.40E-05,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0.000580999,0.002858991,0,0.000926999,0.000411937,0,5.61E-05,0,0.004104086,0.02664713,0.001760019,0.007229999,0,0,0,4.11E-06,0.001260794,0,0,0,0,0.000585001,0,0.000838,0.001769,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.011769,0.2679567,0.002056998,0.03595289,0.01354798,0.01555398,0.005473626,0.02276554,0.009377987,0.008141318,0.03572549,0.002112686,0.006008342,0.04755399,0,0,0,0.008444746,0,0,0,0,0,0,0.037929,0,0.008357,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,2.10E-05,0,0,7.20E-05,0.000200629,0,0,0,0.000527604,0.01030356,0.000700652,0.002615,0,0,0,0.002332596,0.002603326,0,0,0,0,0,0,0.003342,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,9.30E-05,1.00E-06,0.01914623,0,0.008660211,0,0.003538989,0.001762108,0.005892469,0.00136,0,0,7.50E-05,0.000949353,0.005818277,0,0,0,0,0.02003702,0,0.005944,0.001101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0.1746417,0.00061708,0.1213235,0.001942688,0.011507,0.2078596,0.1315664,0.011512,0,0.008946407,0.007704692,0.07827041,0.3444259,0,0,0,0,0.003498004,0.014737,0.110362,0.02056,0,0,0,0,0.00686,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0.000710999,0,0,0.003309997,0.04056714,0.1071053,0.03457633,0.1725158,0.01060929,0.06944652,0.07314944,0.034228,0.1331381,0.06582825,0.001000811,0.02757718,0.1319217,0.0675,0.03362296,0.025021,0,0.1077271,0.010014,0.000164,0.004209,0,0,0,0,0.020851,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0.000133914,0,0,0,6.49E-05,0.07551757,0,0.002766,0,0.03791029,0.000336728,0.000937197,0.000336635,0,0,0,0,0,0,0,0.01727,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0.005460214,7.24E-05,0.000113219,9.75E-05,0.000667583,0.04495781,0.000834812,4.00E-06,0,0.1538326,0.06535369,0.06478802,0.000158878,0,0,0,0,0.03415903,0,0.264599,0.491575,0.05595795,0,0,0,0.332281,0,0.016104,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0.004046815,0,0.000104641,0.004222065,0.000649714,0.01740504,0.002030869,0.000447,0,0.01835961,0.01048056,0.01434949,0.00464439,0,0,0,0,0.02048402,0,0.038274,0.051839,0.05595795,0,0,0,0.027689,0,0.008389,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0.00758379,0.0210978,0,0.008855653,0.00060106,0.03160582,0.02619822,2.60E-05,0.01217144,0.01882007,0.1016545,0.03184985,0.01886067,0.023112,0.06520893,0.031488,0,0.1160341,0,0.003578,0.011448,0.01618998,0.004533,0,0,0.03083,0.0075,0.002502,0,0.02,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0.01512109,0,0,4.94E-05,6.09E-07,0.05912234,0.000691105,2.10E-05,0,0.2037614,0.0243745,0.3048731,0.01022155,0,0,0,0,0.02519003,0,0.267847,0.085048,0,0,0,0,0.027689,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0.01216899,0.02443794,0,0.004246551,0.000115806,0.000696029,0.002668923,0.000570764,0.000559,0,0.000100423,0.110011,0.02268314,0.003618606,0.003573,0,0.002512,0,0.005539006,0,0.074532,0.000287,0.05595795,0,0,0,0,0,0.008389,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0.003722175,0.00133168,0.002559182,0.000585194,0.000501688,0.02632969,0.1947723,0.004025,0,0.08524709,0.4777839,0.1402914,0.03604082,0,0.000879999,0.008373,0,0.2088902,0.013273,0.076097,0.30299,0.1119149,0.015272,0,0,0,0,0.008389,0,0.070001,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.013252,0,0.2238298,0,0,0,0.2769,0.025449,0,0,0.070001,0.05,0,0,0,0,0,0,
  0,0,0,0,0,5.90E-05,0.001968749,0,0,0.001497259,6.65E-05,0.003377157,0.001671519,0.273597,0.01380838,0.001702248,0.00083367,0.005355039,0,0,0.001311999,0.001382,0,0,0.001571,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0.726929,0,0,0.315373,0,0,0.2240073,0.7281086,0.105533,0.476236,0.2298282,0.3536144,0.3443648,0.23311,0.8025885,0.350964,0.02769621,0.1706119,0.3969347,0.877033,0.4149986,0.717669,0,0.4400224,0.890893,0,0,0,0.123605,0,0,0,0,0,0.039305,0,0,0.161448,0.055941,0,0,0,0,
  0.050637,0,0,0,0,0,0.001271437,0.0221517,0,0.03710699,0.00214536,0.00391755,0.09778056,2.40E-05,0.01119073,0.0377405,0.07821934,0.0931701,0.009727789,0.028782,0.4740715,0.213555,1,0.01041601,0,0,0,0,0.244326,0,0,0,0,0,0.035968,0,0,0.696038,0.47728,0.058572,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.026305,0,0,0.095929,0.11221,0.161911,0.099731,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.02719697,0.008578,0.04999995,0.095,0,0,0,0.070066,0,0,0.005032,0.015172,0.076645,0.202492,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.002626997,0,0,0,0,0,0,0,0.069225,0.4222216,0.882656,0,0,0,0.61037,0,0,0.041553,0.127274,0.702872,0.209335,0,0,
  0,0.005316995,0,0.000552998,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.002142,0.003547,0.005332995,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.087293,0,0.4476616,0.534461,0.5277785,0.022344,0.2769,0.967051,0.956227,0.217986,0.839998,0.95,0,0.212123,0,0.488442,1,0,
  0,0,0,0.2077324,0,0.000843999,0,0.003414247,0.07868256,0.0605674,0.003464489,0,0,0.004536,0.003242029,0,0.08825109,0,0,0,0.007278992,0,0,0,0,0.051736,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  46, 43, byrow = T))

#Merge DC matrix with diet parameter object
WSS46.params$diet <- cbind(WSS.params$diet[, Group], DC.data)
#Fix column names
setnames(WSS46.params$diet, 1, 'Group')
setnames(WSS46.params$diet, paste0('V', 1:43), DC.groups)

#Ecopath
WSS46 <- rpath(WSS46.params, 'Western Scotian Shelf')

#pedigrees
#Need to get the right pedigree file loaded...Pedigree_Agg is for the 28 model
ped <- data.table::as.data.table(read.csv(here::here('data-raw', 'Pedigree_Agg.csv')))

WSS46.params$pedigree[, 2:6] <- ped[, 3:7]

#export params
usethis::use_data(WSS.params, overwrite = TRUE)

#Ecopath
WSS <- rpath(WSS.params, 'Western Scotian Shelf')


usethis::use_data(WSS, overwrite = TRUE)

#Test rsim
WSS.test <- rsim.scenario(WSS, WSS.params, years = 1:100)

WSS.test$params$NoIntegrate["Gelatinous zoop"] <- 0
WSS.test$params$NoIntegrate["Meiofauna"] <- 0
WSS.test$params$NoIntegrate["Microzoop"] <- 0
WSS.test$params$NoIntegrate["Microflora"] <- 0
WSS.test$params$NoIntegrate["Worms"] <- 0

WSS.run <- rsim.run(WSS.test, method = 'AB')
rsim.plot(WSS.run)
NOAA-EDAB/RpathQNM documentation built on June 13, 2025, 3:02 a.m.