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

get_SDA_interpretation sometimes throws warning for NCCPI #315

Closed
kevinwolz opened this issue Nov 17, 2023 · 3 comments
Closed

get_SDA_interpretation sometimes throws warning for NCCPI #315

kevinwolz opened this issue Nov 17, 2023 · 3 comments

Comments

@kevinwolz
Copy link

kevinwolz commented Nov 17, 2023

I'm using the approach developed in #303 to get NCCPI data. get_SDA_interpretation sometimes throws the below warning for me and sometimes not, depending on the specific mukeys passed to it. Attached here is an Rdata file (in the zip file) containing a vector of mukeys that does generate the warning. What's going on here?

mukeys <- readRDS("mukeys.RData")
out <- get_SDA_interpretation(rulename    = "NCCPI - National Commodity Crop Productivity Index (Ver 3.0)",
method      = "Dominant Component",
mukeys      = mukeys,
wide_reason = TRUE) 
Warning message:
In rbind(c("NCCPI - NCCPI Corn Submodel (I)", "Not rated"), c("NCCPI - NCCPI Small Grains Submodel (II)",  :
  number of columns of result is not a multiple of vector length (arg 1)

mukeys.RData.zip

@kevinwolz kevinwolz changed the title get_SDA_interpretation sometimes throws warning for NCCPI get_SDA_interpretation sometimes throws warning for NCCPI Nov 17, 2023
brownag added a commit that referenced this issue Nov 17, 2023
@brownag
Copy link
Member

brownag commented Nov 17, 2023

Hey @kevinwolz

This appears to be an unhandled issue with some components that lack ratings for most of the subrules.

I am unable to open the attached .RData file. But I can reproduce the issue here with mukey 459419 which is CA041 mapunit symbol 127 "Fluvents, channeled".

It is 100% higher taxa "Fluvents" and is "Not rated" for anything except "Impacted soil" subrule. The issue above arises because the impacted soil has a numeric rating of zero, whereas the others have "Not rated" reason with no numeric, which creates a non-conformal rbind condition that kinda messes things up with the resulting character matrix. Thanks for pointing this out

library(soilDB)
y <- get_SDA_interpretation(
  rulename    = "NCCPI - National Commodity Crop Productivity Index (Ver 3.0)",
  method      = "Dominant Component",
  mukeys      = 459419,
  wide_reason = TRUE
)
#> Warning in rbind(c("NCCPI - NCCPI Corn Submodel (I)", "Not rated"), c("NCCPI -
#> NCCPI Small Grains Submodel (II)", : number of columns of result is not a
#> multiple of vector length (arg 1)
y
#>    mukey    cokey areasymbol musym              muname compname
#> 1 459419 24586388      CA041   127 Fluvents, channeled Fluvents
#>             compkind comppct_r majcompflag
#> 1 Taxon above family       100         Yes
#>   rating_NCCPINationalCommodityCropProductivityIndexVer30
#> 1                                                      NA
#>   class_NCCPINationalCommodityCropProductivityIndexVer30
#> 1                                              Not rated
#>                                                                                                                                                                                             reason_NCCPINationalCommodityCropProductivityIndexVer30
#> 1 NCCPI - NCCPI Corn Submodel (I) "Not rated" (); NCCPI - NCCPI Small Grains Submodel (II) "Not rated" (); NCCPI - NCCPI Cotton Submodel (II) "Not rated" (); NCCPI - NCCPI Soybeans Submodel (I) "Not rated" (); Impacted soil "No limitation" (0)
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPICornSubmodelI
#> 1                                                        NCCPI - NCCPI Corn Submodel (I)
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPISmallGrainsSubmodelII
#> 1                                                       NCCPI - NCCPI Small Grains Submodel (II)
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPICottonSubmodelII
#> 1                                                        NCCPI - NCCPI Cotton Submodel (II)
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPISoybeansSubmodelI
#> 1                                                        NCCPI - NCCPI Soybeans Submodel (I)
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_Impactedsoil
#> 1                                                                           0

After 1ac18dc I get no warnings but let me know if you find others that have this kind of issue.

library(soilDB)
y <- get_SDA_interpretation(
  rulename    = "NCCPI - National Commodity Crop Productivity Index (Ver 3.0)",
  method      = "Dominant Component",
  mukeys      = 459419,
  wide_reason = TRUE
)
y
#>    mukey    cokey areasymbol musym              muname compname
#> 1 459419 24586388      CA041   127 Fluvents, channeled Fluvents
#>             compkind comppct_r majcompflag
#> 1 Taxon above family       100         Yes
#>   rating_NCCPINationalCommodityCropProductivityIndexVer30
#> 1                                                      NA
#>   class_NCCPINationalCommodityCropProductivityIndexVer30
#> 1                                              Not rated
#>                                                                                                                                                                                             reason_NCCPINationalCommodityCropProductivityIndexVer30
#> 1 NCCPI - NCCPI Corn Submodel (I) "Not rated" (); NCCPI - NCCPI Small Grains Submodel (II) "Not rated" (); NCCPI - NCCPI Cotton Submodel (II) "Not rated" (); NCCPI - NCCPI Soybeans Submodel (I) "Not rated" (); Impacted soil "No limitation" (0)
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPICornSubmodelI
#> 1                                                                                   <NA>
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPISmallGrainsSubmodelII
#> 1                                                                                           <NA>
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPICottonSubmodelII
#> 1                                                                                      <NA>
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_NCCPINCCPISoybeansSubmodelI
#> 1                                                                                       <NA>
#>   rating_reason_NCCPINationalCommodityCropProductivityIndexVer30_Impactedsoil
#> 1                                                                           0

@kevinwolz
Copy link
Author

Thanks for the quick response! The mukeys I was working with no work on my end without a warning.

@brownag
Copy link
Member

brownag commented Nov 17, 2023

Great. Closing this, but we can continue fixing any issues with wide_reason subroutine on #316 where you uncovered a much more general problem.

@brownag brownag closed this as completed Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants