DOI-USGS / streamMetabolizer

streamMetabolizer uses inverse modeling to estimate aquatic metabolism (photosynthesis and respiration) from time series data on dissolved oxygen, water temperature, depth, and light.
http://usgs-r.github.io/streamMetabolizer/
Other
37 stars 22 forks source link

flattened call to metab()? #174

Open aappling-usgs opened 8 years ago

aappling-usgs commented 8 years ago

it's obnoxious to always call metab(specs(mm_name(...), ...), data, ...). thanks to geoknife conversation with @jread-usgs just now (https://github.com/USGS-R/geoknife/issues/269), i think i could make just one set of parentheses work reasonably. would look like this:

old way (which should & will stick around):

metab(specs(mm_name(...), ...), data, ...)
# or
mm_name() %>% specs() %>% metab()

new, complementary way?:

metab('bayes', ode_method='Euler', pool_K600=TRUE, split_dates=FALSE, 
  engine='stan', K600_daily_beta_num=7, n_chains=3)

where engine would get sent to mm_name(), then mm_name() output would get passed to specs(); all the other arguments are largely unique or intentionally redundant.

> intersect(names(formals(mm_name)), names(formals(streamMetabolizer::specs)))
[1] "engine"
> intersect(names(formals(metab)), names(formals(streamMetabolizer::specs)))
character(0)
> intersect(names(formals(metab)), names(formals(mm_name)))
character(0)

> names(formals(mm_name))
[1] "type"           "pool_K600"      "err_obs_iid"    "err_proc_acor" 
[5] "err_proc_iid"   "ode_method"     "deficit_src"    "engine"        
[9] "check_validity"
> names(formals(streamMetabolizer::specs))
 [1] "model_name"                "engine"                   
 [3] "day_start"                 "day_end"                  
 [5] "day_tests"                 "GPP_init"                 
 [7] "ER_init"                   "K600_init"                
 [9] "calc_DO_fun"               "ODE_method"               
[11] "split_dates"               "keep_mcmcs"               
[13] "GPP_daily_mu"              "GPP_daily_sigma"          
[15] "ER_daily_mu"               "ER_daily_sigma"           
[17] "K600_daily_mu"             "K600_daily_sigma"         
[19] "K600_daily_mu_mu"          "K600_daily_mu_sigma"      
[21] "K600_daily_beta_mu"        "K600_daily_beta_sigma"    
[23] "K600_daily_beta_num"       "K600_daily_beta_cuts"     
[25] "K600_daily_sigma_shape"    "K600_daily_sigma_rate"    
[27] "err_obs_iid_sigma_shape"   "err_obs_iid_sigma_rate"   
[29] "err_proc_acor_phi_shape"   "err_proc_acor_phi_rate"   
[31] "err_proc_acor_sigma_shape" "err_proc_acor_sigma_rate" 
[33] "err_proc_iid_sigma_shape"  "err_proc_iid_sigma_rate"  
[35] "priors"                    "params_out"               
[37] "n_chains"                  "n_cores"                  
[39] "adapt_steps"               "burnin_steps"             
[41] "saved_steps"               "thin_steps"               
[43] "verbose"                   "weights"                  
[45] "filters"                   "predictors"               
[47] "transforms"                "other_args"               
[49] "err.obs.sigma"             "err.obs.phi"              
[51] "err.proc.sigma"            "err.proc.phi"             
[53] "sim.seed"       
> names(formals(metab))
[1] "specs"      "data"       "data_daily" "info" 

it could work. it's not immediately essential but could improve the user experience. will ask for input from Bob & Mark & OWIDS team in next few weeks.

jordansread commented 8 years ago

:+1:

aappling-usgs commented 8 years ago

yesterday added option to call things like specs('mle', init.GPP.daily = 7) to have it choose the default name for mle. baby step in the direction of a completely flat call.