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

generateZerosUsingFO needed #137

Open
nmprista opened this issue Oct 17, 2023 · 5 comments
Open

generateZerosUsingFO needed #137

nmprista opened this issue Oct 17, 2023 · 5 comments
Assignees
Labels
2_preparation Generating probabilities and Zero's, subsetting species

Comments

@nmprista
Copy link
Contributor

when FOcatchReg=="All", it is expected that SScatchFraction is either "Catch" OR "Lan"+"Dis". In the latter case, if one is missing the other is to be assumed 0. There is a need for a function that generates those zeros, basically creating a Dis row in SS with SSsampled=Y and generating an entire species list of 0s in SA.

Thoughts
This function could be included in generateZerosUsingSL since it also uses the SL. But it carries out a different procedure so better to keep it separate and explicit. Then create a wrapper that runs both.

Related to: generateZerosUsingSL

@nmprista nmprista added the 2_preparation Generating probabilities and Zero's, subsetting species label Oct 17, 2023
@davidcurrie2001 davidcurrie2001 self-assigned this Oct 19, 2023
@davidcurrie2001
Copy link
Contributor

Following discussion this function should create any missing SS rows. The function will need to know which species list should be used for the SS rows it creates. There was a difference of opinion on how this should work:

  • Only allow a specise list which already exists in the data
  • Allow the user to specify a new species list as part of the function call.

We will test these options and see how they work in practice before we decide the way forward.

@KirstenBirchHaakansson
Copy link
Contributor

Should we have a warning if people use this on a hierarchy without a FO?

As far as I can tell this information only exist in FO - not in the other tables that can be parent to SS

@davidcurrie2001
Copy link
Contributor

A first version of the function is available at generateMissingSSRows(). It compares the FO table to the SS table and aims to create any missing SS rows.
It will throw an error if:

  • There is no FO, SS, or SL data
  • The requested SpeciesListName for the created SS rows doesn't already exist in SL.

@davidcurrie2001
Copy link
Contributor

Here is an example of how to use the function:

myH1RawObject <- importRDBESDataCSV(rdbesExtractPath = "./tests/testthat/h1_v_1_19_18")
# Only use a subset of the test data
myH1RawObject <- filterRDBESDataObject(myH1RawObject, c("DEstratumName"), c("DE_stratum1_H1", "DE_stratum2_H1", "DE_stratum3_H1"))
myH1RawObject <- findAndKillOrphans(myH1RawObject, verbose = FALSE)

# Set FO to Lan
myH1RawObject[["FO"]]$FOcatReg <- "Lan"
# Ensure only SS Dis rows exists
myH1RawObject[["SS"]]$SScatchFra <- "Dis"

# Number of SS rows before we run our function
print(nrow(myH1RawObject[["SS"]]))

# Try to generate any missing SS rows - we should get Lan rows created
mySSAfter <- generateMissingSSRows(myH1RawObject,
                                   "ZW_1965_SpeciesList",
                                   verbose = FALSE)

# Copy our new SS data into the RDBES object
myH1RawObject[["SS"]] <- mySSAfter

# Number of SS rows after we have run our function
print(nrow(myH1RawObject[["SS"]]))

# Validate the data
validateRDBESDataObject(myH1RawObject)

@nmprista
Copy link
Contributor Author

nmprista commented Oct 20, 2023

I had some problems running the example above. But if it does what I think it does - generating the missing SS rows - the issue is likely solved if we couple it to the improvements I made on generateZerosUsingSL (I worked it up so it includes in SA the species of lonely SS rows), and run the two functions in a sequence. It will be fun to try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2_preparation Generating probabilities and Zero's, subsetting species
Projects
None yet
Development

No branches or pull requests

3 participants