Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getYield() error when using effort as an array #173

Closed
jpwrobinson opened this issue Nov 23, 2020 · 2 comments
Closed

getYield() error when using effort as an array #173

jpwrobinson opened this issue Nov 23, 2020 · 2 comments
Assignees
Labels

Comments

@jpwrobinson
Copy link

I've been playing around with mizer's North Sea multispecies model, particularly estimating yields under different fishing pressure. The getYield() function has been working fine for this (in many scripts since June, no problems), but now gives this error:

getYield(sim2)
      sp
time   Sprat Sandeel N.pout Herring Dab Whiting Sole Gurnard Plaice
      sp
time   Haddock Cod Saithe
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
5: In sweep(f_gear, c(1, 3, 4), biomass, "*") :
  STATS is longer than the extent of 'dim(x)[MARGIN]'

The error now appears running the simple North Sea example at https://sizespectrum.org/mizer/articles/a_multispecies_model_of_the_north_sea.html. Using the NS_params in your data folder, I'm running:


# load species, gear params
load('data/NS_params.Rdata')

## get effort
f_location <- system.file("doc/NS_f_history.csv", package = "mizer")
f_history <- as(read.csv(f_location, row.names = 1), "matrix")
relative_effort<-f_history

# stick 100 years of initial fishing effort, set to 1957 levels
initial_effort <- matrix(relative_effort[1, ], byrow = TRUE, nrow = 100,
                         ncol = ncol(relative_effort), dimnames = list(1867:1966))
relative_effort <- rbind(initial_effort, relative_effort)

sim <- project(params, effort=relative_effort, dt=0.25)
getYield(sim)

getYield() works if you run the simulation with effort = 0. Could be a bug from a recent update on how effort is defined?

Thanks for all your work on this package, it's fantastic and easy to use.

@gustavdelius
Copy link
Member

James, thank you very much for this useful bug report. The issue arises because the new code assumed that the dimensions of the effort array are called "time" and "gear", but the code does not ensure that these dimensions are named correctly. I have now fixed that. You can get the fixed version with

remotes::install_github("sizespectrum/mizer")

Alternatively, you can assign names to the effort array dimensions by hand:

names(dimnames(relative_effort)) <- c("time", "gear")

or, if you want to work with an existing simulation called sim then

names(dimnames(sim@effort)) <- c("time", "gear")

@jpwrobinson
Copy link
Author

Incredible. Thanks for the super fast fix Gustav, much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants