sizespectrum / therMizer

1 stars 1 forks source link

Error when setting n_pp_array with upgradeTherParams #1

Closed pwoodworth-jefcoats closed 1 year ago

pwoodworth-jefcoats commented 1 year ago

I'm encountering and error when I try to include n_pp_array in upgradeTherParams. Here's a snippet of code:

# Load resource spectra
isimip_plankton <- read.table("ClimateForcing/GFDL_resource_spectra_S1.03I0.85.dat") # shared via email
isimip_plankton <- as(isimip_plankton, "matrix")
sizes <- names(params@initial_n_pp)
time_steps <- seq(0,600,1)
n_pp_array <- array(NA, dim = c(length(time_steps), length(sizes)), dimnames = list(time = time_steps, w = sizes))

# Transform plankton data and divide by bin width
# Need an extra time step preceding the simulation
n_pp_array[1,] <- (10^(isimip_plankton[1,])) / params@dw_full
for (t in seq(1,length(time_steps) - 1,1)) {
  n_pp_array[t + 1,] <- (10^(isimip_plankton[t,])) / params@dw_full
}

params <- upgradeTherParams(params, ocean_temp_array = ocean_temp_array, n_pp_array = n_pp_array, vertical_migration_array = vertical_migration_array, exposure_array = HIexposure)

and the error: Error in !dim(n_pp_array[2] == length(params@w_full)) : invalid argument type

I think this might be the result of a typo on line 55 of therParams.R, where a ')' is misplaced. Changing

if(!dim(n_pp_array[2] == length(params@w_full)))

to

if(!dim(n_pp_array)[2] == length(params@w_full))

might fix the problem. Maybe. I wanted to get your thoughts before changing the code.

baldrech commented 1 year ago

Yes that did the trick: Fixed in fa177a5