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

Bug in query.trait.data in relation to FRC_LC trait #2269

Closed
serbinsh opened this issue Feb 1, 2019 · 9 comments
Closed

Bug in query.trait.data in relation to FRC_LC trait #2269

serbinsh opened this issue Feb 1, 2019 · 9 comments

Comments

@serbinsh
Copy link
Member

serbinsh commented Feb 1, 2019

Bug Description

I have hit an error when running query.trait.data() with trait "FRC_LC."

This warning is displayed once per session.
Error in if (nrow(result) == 0) { : argument is of length zero
> traceback()
12: query.trait.data(trait = trait, spstr = PEcAn.utils::vecpaste(ids),
        con = con, update.check.only = update.check.only, ids_are_cultivars = ids_are_cultivars)
11: FUN(X[[i]], ...)
10: lapply(traits$name, function(trait) {
        query.trait.data(trait = trait, spstr = PEcAn.utils::vecpaste(ids),
            con = con, update.check.only = update.check.only, ids_are_cultivars = ids_are_cultivars)
    })
9: PEcAn.DB::query.traits(ids = pft_members$id, priors = traits,
       con = dbcon, update.check.only = TRUE, ids_are_cultivars = (pfttype ==
           "cultivar"))
8: FUN(X[[i]], ...)
7: lapply(pfts, get.trait.data.pft, modeltype = modeltype, dbfiles = dbfiles,
       dbcon = dbcon, forceupdate = forceupdate, trait.names = trait.names)
6: PEcAn.DB::get.trait.data(pfts = pfts, modeltype = modeltype,
       dbfiles = dbfiles, database = database, forceupdate = forceupdate)
5: PEcAn.workflow::runModule.get.trait.data(settings) at workflow.R#76
4: eval(ei, envir)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("workflow.R")
>

Specific to this line in the function:

if (nrow(result) == 0) {

> query.trait.data("FRC_LC", "30", con = con)
2019-02-01 09:50:42 INFO   [query.trait.data] :
   ---------------------------------------------------------
2019-02-01 09:50:42 INFO   [query.trait.data] : FRC_LC
Error in postgresqlExecStatement(conn, statement, ...) :
  RS-DBI driver: (could not Retrieve the result : ERROR:  invalid input syntax for integer: ""
LINE 1: ...riables.id = covariates.variable_id where trait_id in ( '' )
                                                                   ^
)
2019-02-01 09:50:42 SEVERE [db.query] :
   Error executing db query 'select covariates.trait_id,
   covariates.level,variables.name from covariates left join variables on
   variables.id = covariates.variable_id where trait_id in ( '' )'
   errorcode=0 message='ERROR: invalid input syntax for integer: "" LINE 1:
   ...riables.id = covariates.variable_id where trait_id in ( '' ) ^ '
Error in PEcAn.logger::logger.severe(paste("Error executing db query '",  :
  Error executing db query 'select covariates.trait_id, covariates.level,variables.name from covariates left join variables on variables.id = covariates.variable_id where trait_id in ( '' )' errorcode=0 message='ERROR:  invalid input syntax for integer: ""
LINE 1: ...riables.id = covariates.variable_id where trait_id in ( '' )
                                                                   ^
'
In addition: Warning message:
In postgresqlQuickSQL(conn, statement, ...) :
  Could not create execute: select covariates.trait_id, covariates.level,variables.name from covariates left join variables on variables.id = covariates.variable_id where trait_id in ( '' )

But for other traits,

> query.trait.data("Vcmax", "938", con = con)
2019-02-01 09:58:00 INFO   [query.trait.data] :
   ---------------------------------------------------------
2019-02-01 09:58:00 INFO   [query.trait.data] : Vcmax
2019-02-01 09:58:00 INFO   [query.trait.data] : Median Vcmax : 21.73
2019-02-01 09:58:00 INFO   [query.trait.data] :
   ---------------------------------------------------------
     id citation_id site_id treatment_id    name       date     time
7  2638          62     368          498 Control 2009-06-16 00:00:00
8  2639          62     368          498 Control 2009-07-24 00:00:00
9  2640          62     368          498 Control 2009-08-28 00:00:00
10 2641          62     368          498 Control 2009-09-18 00:00:00
11 2642          62     368          499   Nfert 2009-06-16 00:00:00
12 2643          62     368          499   Nfert 2009-07-24 00:00:00
13 2644          62     368          499   Nfert 2009-08-28 00:00:00
14 2645          62     368          499   Nfert 2009-09-18 00:00:00
   cultivar_id specie_id  mean statname  stat n vname month      lon     lat
7           19       938 25.62       SE  8.75 4 Vcmax     6 -88.2373 40.0415
8           19       938 23.05       SE  4.17 4 Vcmax     7 -88.2373 40.0415
9           19       938 12.61       SE  6.81 4 Vcmax     8 -88.2373 40.0415
10          19       938 12.48       SE  9.89 4 Vcmax     9 -88.2373 40.0415
11          19       938 29.43       SE 10.60 4 Vcmax     6 -88.2373 40.0415
12          19       938 20.41       SE  8.28 4 Vcmax     7 -88.2373 40.0415
13          19       938 23.91       SE 11.85 4 Vcmax     8 -88.2373 40.0415
14          19       938  8.83       SE  3.02 4 Vcmax     9 -88.2373 40.0415
   control greenhouse mean_unconverted stat_unconverted
7     TRUE      FALSE            25.62             8.75
8     TRUE      FALSE            23.05             4.17
9     TRUE      FALSE            12.61             6.81
10    TRUE      FALSE            12.48             9.89
11   FALSE      FALSE            29.43            10.60
12   FALSE      FALSE            20.41             8.28
13   FALSE      FALSE            23.91            11.85
14   FALSE      FALSE             8.83             3.02

All good.

Looking at "blame" I think it has to do with this change from 11 months ago: #1826

And perhaps others haven't run into this since not many PFTs actually have FRC data available. It just so happens that my new pine barrens PFT does.

To Reproduce

Steps to reproduce the behavior:
query.trait.data("FRC_LC", "30", con = con)
https://modex.bnl.gov/bety/species/30 ; Acer rubrum

  • seems to only be related to Acer rubrum, as far as I can tell

BUT

others DO work, e.g.
query.trait.data("FRC_LC", "32", con = con)

query.trait.data("FRC_LC", "1130", con = con)

@serbinsh
Copy link
Member Author

serbinsh commented Feb 1, 2019

Possible that PR is a red herring, though I suspect there is something up with the species record clashing with that cultivar PR. @dlebauer @infotroph any thoughts?

@serbinsh
Copy link
Member Author

serbinsh commented Feb 1, 2019

OK, hmm...

> query.trait.data("FRC_LC", PEcAn.utils::vecpaste(c("30","1014","1017","1130","1142","1170","1178","9303","9315")),
+                  con = con, update.check.only = FALSE, ids_are_cultivars = FALSE)
2019-02-01 10:33:05 INFO   [query.trait.data] :
   ---------------------------------------------------------
2019-02-01 10:33:05 INFO   [query.trait.data] : FRC_LC
2019-02-01 10:33:05 INFO   [query.trait.data] : Median FRC_LC : 1.33
2019-02-01 10:33:05 INFO   [query.trait.data] :
   ---------------------------------------------------------
     id citation_id site_id treatment_id name date     time cultivar_id
1 26702         336      NA            0 <NA> <NA> 00:00:00           0
2 26718         336      NA            0 <NA> <NA> 00:00:00           0
3 26719         336      NA            0 <NA> <NA> 00:00:00           0
4 26726         336      NA            0 <NA> <NA> 00:00:00           0
  specie_id  mean statname stat n  vname month lon lat control greenhouse
1      1017 0.994     <NA>   NA 1 FRC_LC    NA  NA  NA      NA         NA
2      1178 1.590     <NA>   NA 1 FRC_LC    NA  NA  NA      NA         NA
3      1130 1.270     <NA>   NA 1 FRC_LC    NA  NA  NA      NA         NA
4      1170 1.390     <NA>   NA 1 FRC_LC    NA  NA  NA      NA         NA
  mean_unconverted stat_unconverted
1            0.994               NA
2            1.590               NA
3            1.270               NA
4            1.390               NA

now I am not so sure what the issue is and why the call to query traits returns an error?

@serbinsh
Copy link
Member Author

serbinsh commented Feb 1, 2019

Aha!

> data <- query.trait.data("stem_respiration_rate", PEcAn.utils::vecpaste(c("30","1014","1017","1130","1142","1170","1178","9303","9315")),
+                          con = con, update.check.only = FALSE, ids_are_cultivars = FALSE)
2019-02-01 10:37:26 INFO   [query.trait.data] :
   ---------------------------------------------------------
2019-02-01 10:37:26 INFO   [query.trait.data] :
   stem_respiration_rate
Error in if (nrow(result) == 0) { : argument is of length zero
>

Stem respiration rate?

@serbinsh
Copy link
Member Author

serbinsh commented Feb 1, 2019

Perhaps this is it:

  } else if (trait == 'stem_respiration_rate') {
#########################  STEM RESPIRATION   ############################
    ## Apply Arrhenius scaling to convert stem respiration at measurement temp
    ## to that at 25 degC (ref temp).
    data <- arrhenius.scaling.traits(data = data, covariates = covariates, temp.covariates = c('leafT', 'airT'))

Covariate options are leafT or airT BUT many of these entries for stem respiration use stem temperature (stemT), e.g. https://modex.bnl.gov/bety/traits/41237

This can be addressed by added stemT as an option to this scale, and removing leafT (since I dont see how that is relevant) but raises my questions about covariates. we may need to make sure uploading includes the correct temp covariate where right now most of the time leafT is the only required. @dlebauer?

@serbinsh
Copy link
Member Author

serbinsh commented Feb 1, 2019

Looks like my problem is that there is 1 Quercus rubra value and that species is in my PFT but as mentioned the covariate scaling does not include stemT

@serbinsh
Copy link
Member Author

serbinsh commented Feb 1, 2019

Updating the function like this:

  } else if (trait == 'stem_respiration_rate') {
#########################  STEM RESPIRATION   ############################
    ## Apply Arrhenius scaling to convert stem respiration at measurement temp
    ## to that at 25 degC (ref temp).
    data <- arrhenius.scaling.traits(data = data, covariates = covariates, temp.covariates = c('stemT', 'airT','T'))

results in the expected results:

> data <- query.trait.data("stem_respiration_rate", PEcAn.utils::vecpaste(c("30","1014","1017","1130","1142","1170","1178","9303","9315")),
+                          con = con, update.check.only = FALSE, ids_are_cultivars = FALSE)
2019-02-01 10:48:35 INFO   [query.trait.data] :
   ---------------------------------------------------------
2019-02-01 10:48:35 INFO   [query.trait.data] :
   stem_respiration_rate
2019-02-01 10:48:35 INFO   [query.trait.data] :
   Median stem_respiration_rate : 11.72
2019-02-01 10:48:35 INFO   [query.trait.data] :
   ---------------------------------------------------------
> data
     id citation_id site_id treatment_id       name                date
1 41237         405     311         1268 High Light 1988-12-31 06:00:00
      time cultivar_id specie_id     mean statname      stat  n
1 00:00:00          NA      1170 11.72036       SE 0.4507832 NA
                  vname month       lon      lat control greenhouse
1 stem_respiration_rate    12 -89.42352 43.07746    TRUE       TRUE
  mean_unconverted stat_unconverted
1             10.4              0.4

@infotroph
Copy link
Member

@serbinsh To make sure I'm following right: You're concluding that this is fully explained by the copy-paste error in stem resp scaling and doesn't need any changes to the if(nrow(result)==0) bit, yes?

@serbinsh
Copy link
Member Author

serbinsh commented Feb 1, 2019

LOL! yeah probably was a copy-paste error! Originally i thought it may be something else, but yeah, I think it was just the wrong covariates listed for stem respiration and my small PR seems to have fixed it

@serbinsh
Copy link
Member Author

Closing since the fix was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants