gadget-framework / rgadget

Rgadget is a set of useful utilities for gadget
6 stars 12 forks source link

make a stomach likelihood with multiple species #98

Closed vbartolino closed 4 years ago

vbartolino commented 4 years ago

I've a mfdb extraction of stomach data including multiple species. I do not find a way to assign the correct species to the prey aggregation file using the argument prey_labels The issue was initially posted in mfdb https://github.com/mareframe/mfdb/issues/60#issuecomment-579886674

lentinj commented 4 years ago

There's a unit test for this bit that looks like:-

    gadget_dir_write(gd, gadget_stomachcontent_component(
        data = sample_data,
        area = list(all = 101),
        predator_length = list(len100 = c(100,500)),
        prey_length = list(cod = 10:20, anacoda = 1:5, "cod.imm" = 1:10),
        prey_labels = list("cod" = "all.cod", "cod.imm" = "immature.cod", "other"),
        prey_digestion_coefficients = list("cod.imm" = c(1,1,1), "cod" = c(3,3,3), c(9,9,9))))
    ok(cmp_file(gd, gadget_dir_read(gd, "likelihood")$components[[2]]$preyaggfile,
        ver_string,
        "; ",
        "cod\t",
        "all.cod\t",
        "lengths\t10\t20",
        "digestioncoefficients\t3\t3\t3",
        "; ",
        "anacoda\t",
        "other\t",
        "lengths\t1\t5",
        "digestioncoefficients\t9\t9\t9",
        "; ",
        "cod.imm\t",
        "all.cod\t",
        "lengths\t1\t10",
        "digestioncoefficients\t1\t1\t1",
        NULL))

prey_length, prey_labels and prey_digestion_coefficients all roughly have the same elements. prey_length is the most important out of the 3, and defines the groups that appear in the prey agg file. The other 2 get assigned to the prey_labels groups using the first name that matches the prey_label name (thus why cod.imm is all.cod in the preyaggfile, since it matches the first prey_label as well as the third). So a wild guess would be that the problem is actually in the value of prey_length.

If you want some rationale for all this I'd have to do a bit more digging and remembering.

vbartolino commented 4 years ago

Thanks, with this example I've been able to fix the code for my model