nmfs-fish-tools / SSMSE

Management Strategy Evaluation (MSE) using Stock Synthesis (SS3)
https://nmfs-fish-tools.github.io/SSMSE
MIT License
18 stars 11 forks source link

Two-area model causing error in achieved_F within update_OM #175

Closed skylersagarese-NOAA closed 8 months ago

skylersagarese-NOAA commented 9 months ago

When using a two-area model (with two fleets operating in each area), I'm getting an error in achieved_F within the update_OM function:

            SSMSE:::update_OM(OM_dir = OM_out_dir, catch = new_catch_list[["catch"]],
                      harvest_rate = new_catch_list[["catch_F"]], catch_basis = NULL,
                      F_limit = NULL, EM_pars = new_catch_list[["EM_pars"]],
                      write_dat = TRUE, impl_error = impl_error, verbose = verbose,
                      n_F_search_loops = n_F_search_loops, tolerance_F_search = tolerance_F_search,
                      seed = (iter_seed[["iter"]][1] + 234567 + yr))

Error in [<-.data.frame(*tmp*, i, "last_adjust", value = c(1.01732724909191, : replacement has 2 rows, data has 1

This is occurring because achieved_F is giving two values (one per area), which is later producing two values for target_F: achieved_F <- F_achieved[F_achieved[, "year"] == catch_intended[i, "year"] & F_achieved[, "seas"] == catch_intended[i, "seas"] & F_achieved[, "fleet"] == catch_intended[i, "fleet"], "F"]

achieved_F for fleet 1 [1] 0.012108 0 #Fleet 1 fishes in area 1 not area 2

achieved_F for fleet 2 [1] 0 0.01 #Fleet 2 fishes in area 2 not area 1

achieved_F for fleet 3 [1] 0.171941 0 #Fleet 3 fishes in area 1 not area 2

achieved_F for fleet 4 [1] 0 0.0385965 #Fleet 4 fishes in area 2 not area 1

For this model, F is positive in only one area, so my fix here is to sum these two values for achieved_F right below the achieved_F function given above. achieved_F<-sum(achieved_F) #F in one area is always zero

k-doering-NOAA commented 9 months ago

@skylersagarese-NOAA thanks for reporting this, and sorry to again ask for your model files/code (feel free to email me them when you submit an issue in the future if this is easier for you than waiting for me to ask!

It sounds like your fix would work for this model, but not generally for 2 area models, is that right? Would a more general solution be needed in that case?

skylersagarese-NOAA commented 9 months ago

I believe my fix would work for SEFSC models where we have more than one region and specify fleets as areas. But this fix will not work for other models if they have a fleet operating in 2 separate areas (is that even possible?)

skylersagarese-NOAA commented 8 months ago

@k-doering-NOAA - it works! thank you!

k-doering-NOAA commented 8 months ago

Thanks for finding and proposing the fix - it was really all you, just me duplicating your work!