DOI-USGS / DOI-USGS/streamMetabolizer

SYNTAX ERROR, MESSAGE(S) FROM PARSER when editing the ER function in the metab_bayes to (q10temp)

Open
#406 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Stan
Stars
47
Forks
25
PR merge metrics
No merged PRs in 30d

Description

### Brief problem description
I have created a new .stan file named "b_np_oipi_tr_psrqkm.stan" following the naming generated by mm_name('bayes', GPP_fun='satlight', ER_fun='q10temp',pool_K600='none'). Then I edited the .stan file to include ER model as function of water temperature as per manual q10temp . However, I get a syntax error when I included temp.water as a variable in the transformed parameter ER_inst[i].
```
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Variable identifier may not contain a period (.)
```
See below for the full code.

Based on Rstan manual variable identifiers in Stan may not contain a period character. And when I changed the variable name to water_temp I got the error

```
Error in mod$fit_ptr() :
Exception: variable does not exist; processing stage=data initialization; variable name=temp_water; base type=vector_d (in ‘model4b1c66371d71_b_np_oipi_tr_psrqkm’ at line 30)
```

After troubleshooting in Stan forum, it was found that the temp.water is hard coded in the function and can't be renamed. But the mystery is that DO.sat Do.obs are written in the form DO_stat in the stan data block and they don't cause the same error while only temp_water causes the error above in Italic. Any idea how to include the temperature function without running into this error?

### What I saw on my computer

```
dat<-data.frame(solar.time=as.POSIXct(site$solar.time,tz="UTC",format="%d/%m/%Y %H:%M"),DO.obs=ma(site$DO.obs,10),DO.sat=site$DO.sat,depth=site$depth,temp.water=site$temp.water,light=site$light)

## Sat model with light and ER function
mm_saturator_ER<-
+ mm_name('bayes', GPP_fun='satlight', ER_fun='q10temp',pool_K600='none') %>%
+ specs(alpha_meanlog=.4,alpha_sdlog=.2,Pmax_mu=6,Pmax_sigma=.3, day_start = 4,day_end = 28,n_cores=4, n_chains=4, burnin_steps=500, saved_steps=500) %>%
+ metab(dat)
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Variable identifier may not contain a period (.)
found period at position (indexed from 0)=4
found identifier=temp.water
Variable identifier may not contain a period (.)
found period at position (indexed from 0)=4
found identifier=temp.water
error in 'model4b1c4e6d2fdf_b_np_oipi_tr_psrqkm' at line 29, column 11
-------------------------------------------------
27: vector[d] DO_obs[n];
28: vector[d] DO_sat[n];
29: vector[d] temp.water[n];
^
30: vector[d] light[n];
-------------------------------------------------

PARSER EXPECTED:
Timing stopped at: 0.08 0 0.09
Warning message:
In metab_fun(specs = specs, data = data, data_daily = data_daily, :
Modeling failed
Errors:
failed to parse Stan model 'b_np_oipi_tr_psrqkm' due to the above error

```

### Session information

Run the following code line (or `sessionInfo()` if that doesn't work) and paste in your output.

```r
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] unitted_0.2.9 wql_0.4.9 fpp_0.5
[4] tseries_0.10-47 lmtest_0.9-37 expsmooth_2.3
[7] fma_2.4 forecast_8.12 forcats_0.5.0
[10] stringr_1.4.0 purrr_0.3.4 readr_1.3.1
[13] tibble_3.0.3 tidyverse_1.3.0 scales_1.1.1
[16] cowplot_1.0.0 reshape_0.8.8 lubridate_1.7.9
[19] xts_0.12-0 zoo_1.8-8 tidyr_1.1.2
[22] imputeTS_3.1 devtools_2.3.1 usethis_1.6.1
[25] rstan_2.21.2 StanHeaders_2.21.0-6 ggplot2_3.3.2
[28] dplyr_1.0.2 streamMetabolizer_0.11.4

loaded via a namespace (and not attached):
[1] nlme_3.1-149 ggtext_0.1.0 matrixStats_0.56.0
[4] fs_1.5.0 httr_1.4.2 LakeMetabolizer_1.5.0
[7] rprojroot_1.3-2 tools_4.0.3 backports_1.1.9
[10] utf8_1.1.4 R6_2.4.1 DBI_1.1.0
[13] lazyeval_0.2.2 colorspace_1.4-1 nnet_7.3-14
[16] withr_2.2.0 tidyselect_1.1.0 gridExtra_2.3
[19] prettyunits_1.1.1 processx_3.4.3 curl_4.3
[22] compiler_4.0.3 rvest_0.3.6 cli_2.0.2
[25] xml2_1.3.2 desc_1.2.0 labeling_0.3
[28] rLakeAnalyzer_1.11.4.1 fracdiff_1.5-1 quadprog_1.5-8
[31] callr_3.4.3 digest_0.6.25 pkgconfig_2.0.3
[34] sessioninfo_1.1.1 dbplyr_1.4.4 readxl_1.3.1
[37] rlang_0.4.9 TTR_0.24.2 rstudioapi_0.11
[40] quantmod_0.4.17 farver_2.0.3 generics_0.0.2
[43] jsonlite_1.7.1 inline_0.3.16 magrittr_1.5
[46] loo_2.3.1 Rcpp_1.0.5 munsell_0.5.0
[49] fansi_0.4.1 lifecycle_0.2.0 stringi_1.4.6
[52] pkgbuild_1.1.0 plyr_1.8.6 grid_4.0.3
[55] blob_1.2.1 parallel_4.0.3 crayon_1.3.4
[58] lattice_0.20-41 haven_2.3.1 gridtext_0.1.1
[61] hms_0.5.3 ps_1.3.4 pillar_1.4.6
[64] reshape2_1.4.4 codetools_0.2-16 stats4_4.0.3
[67] pkgload_1.1.0 reprex_0.3.0 urca_1.3-0
[70] glue_1.4.2 V8_3.2.0 modelr_0.1.8
[73] stinepack_1.4 remotes_2.2.0 RcppParallel_5.0.2
[76] deSolve_1.28 vctrs_0.3.4 cellranger_1.1.0
[79] testthat_2.3.2 gtable_0.3.0 assertthat_0.2.1
[82] broom_0.7.0 timeDate_3043.102 memoise_1.1.0
[85] ellipsis_0.3.1

```
### Sample data
[sample_data.txt](https://github.com/USGS-R/streamMetabolizer/files/6000721/sample_data.txt)
### Stan model file
[b_np_oipi_tr_psrqkm.txt](https://github.com/USGS-R/streamMetabolizer/files/6000729/b_np_oipi_tr_psrqkm.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.