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

Meanbodywt causing error within run_SSMSE_iter #171

Closed skylersagarese-NOAA closed 9 months ago

skylersagarese-NOAA commented 9 months ago

When I included meanbodywt data, I got the following error within the run_SSMSE_iter function:             

Error in (function (x, x_name, dat)  : sample_struct could not be automatically expanded due to list elements meanbodywt, meanbodywt; colnames Std_in, Std_in 

Section of code: if (!is.null(sample_struct)) {                 sample_struct <- SSMSE:::get_full_sample_struct(sample_struct = sample_struct,                                                         OM_out_dir = OM_out_dir)                 sample_struct <- SSMSE:::convert_to_r4ss_names(sample_struct)                 sample_struct_hist <- SSMSE:::convert_to_r4ss_names(sample_struct_hist)               }

k-doering-NOAA commented 9 months ago

Here's where this error is in the codebase: https://github.com/nmfs-fish-tools/SSMSE/blob/d1e7714a61e4925b377f0930d654a6a74202a5e6/R/sample_struct.R#L558-L561

It means this part of the code is throwing an error: https://github.com/nmfs-fish-tools/SSMSE/blob/d1e7714a61e4925b377f0930d654a6a74202a5e6/R/sample_struct.R#L511-L519

I think what's happening is there is no "Std_in" column, and it needs to be specified. Could that column be created?

These are the column names that should exist for mean size at age data in the sample_struct: https://github.com/nmfs-fish-tools/SSMSE/blob/d1e7714a61e4925b377f0930d654a6a74202a5e6/R/sample_struct.R#L20-L21

skylersagarese-NOAA commented 9 months ago

I renamed the meanbodywt data in sample_struct but am now receiving a different error within the run_SSMSE_iter function, specifically within the get_full_sample_struct function:

Section of code: if (!is.null(sample_struct)) { sample_struct <- SSMSE:::get_full_sample_struct(sample_struct = sample_struct, OM_out_dir = OM_out_dir) sample_struct <- SSMSE:::convert_to_r4ss_names(sample_struct) sample_struct_hist <- SSMSE:::convert_to_r4ss_names(sample_struct_hist) }

Error in (function (x, x_name, dat) : Column Yr missing from 1 or more data frames in sample_struct. Yr must always be specified

k-doering-NOAA commented 9 months ago

@skylersagarese-NOAA , I'm so sorry, I lead you astray with the wrong names! These are actually the correct column names to be using: https://github.com/nmfs-fish-tools/SSMSE/blob/d1e7714a61e4925b377f0930d654a6a74202a5e6/R/sample_struct.R#L36-L37

skylersagarese-NOAA commented 9 months ago

I was actually using those headers in my sample_struct object (below).

sample_struct$meanbodywt Yr Seas FltSvy Part Type Std_in 1 2021 7 3 2 2 0.09656815 2 2022 7 3 2 2 0.09656815 ...

I am not having any luck trying to identify where this is tripping up in get_full_sample_struct. I assume there is a naming issue somewhere, but am struggling to find it.

k-doering-NOAA commented 9 months ago

Ok, do you think you could email me the code you ran so I can try to replicate it on my end?

skylersagarese-NOAA commented 9 months ago

Just shared a google drive folder with you (because of confidentiality issues in our data file)...

k-doering-NOAA commented 9 months ago

Got it - I'll try to replicate by tomorrow!

k-doering-NOAA commented 9 months ago

@skylersagarese-NOAA my code was erroring at a different part:

https://github.com/nmfs-fish-tools/SSMSE/blob/f594bb1d826a0cc3264c0f7ed975c72906f42a6a/R/runSSMSE.R#L525

Ironically, there was a mistake in the error checking function that suggest that the "Std_in" column should be "SE" (it shouldn't). I made a change in commit 14e3f092d3cba9734b0cc6fa48f576887683d046 (pushed to the fix-sky-isses branch, and then I was able to run run_SSMSE() through an entire iteration with the mean size data (for time's sake, I just did one).

@skylersagarese-NOAA could you test and see if that fix also works for you? If not, I'll have to sort out what I'm doing different from you.

skylersagarese-NOAA commented 9 months ago

@k-doering-NOAA - that fix worked for me too! Thank you!