rubyforgood / ghgvc

Ecosystem Climate Regulation Services Calculator
http://www.ecosystemservicescalc.org
Other
4 stars 3 forks source link

Failing #75

Closed jaydorsey closed 4 years ago

jaydorsey commented 7 years ago

With a JSON string below, assigned to a variable data:

{"sites":{"site_1_data":{"lat":"-8.75","lng":"-65.21","ecosystems":{"Broadleaf_Evergreen_Forest":{"4":[""],"OM_ag":["300.2348334"],"OM_root":["33.61702128"],"OM_wood":["43.64411765"],"OM_litter":["6.904033613"],"OM_peat":["0"],"OM_SOM":["11.3607"],"fc_ag_wood_litter":["0.52"],"fc_root":["0"],"fc_peat":["0"],"fc_SOM":["0"],"Ec_CO2":["35.909"],"Ec_CH4":["0.294"],"Ec_N2O":["0.0059"],"k_ag_wood_litter":["0.167"],"k_root":["0.04"],"k_peat":["0"],"k_SOM":["0.4"],"termite":["3"],"Ed_CO2_ag_wood_litter":["41.66666667"],"Ed_CO2_root":["41.66666667"],"Ed_CO2_peat":["45"],"Ed_CO2_litter":["48.33333333"],"Ed_CH4_ag_wood_litter":["0.0275"],"Ed_CH4_root":["0"],"Ed_CH4_peat":["0"],"Ed_CH4_litter":["0"],"Ed_N2O_ag_wood_litter":["0"],"Ed_N2O_root":["0"],"Ed_N2O_peat":["0"],"Ed_N2O_litter":["0"],"F_CO2":["-14.52279202"],"F_CH4":["-0.22584375"],"F_N2O":["0.081607401"],"rd":["0"],"tR":["-9999"],"FR_CO2":["-9999"],"FR_CH4":["-9999"],"FR_N2O":["-9999"],"dfc_ag_wood_litter":["-9999"],"dfc_root":["0"],"dfc_peat":["0"],"dk_ag_wood_litter":["0.167"],"dk_root":["0.04"],"dk_peat":["0"],"age_transition":["-9999"],"new_F_CO2":["-9999"],"new_F_CH4":["-9999"],"new_F_N2O":["-9999"],"F_anth":["0"],"sw_radiative_forcing":["0.3979"],"latent":["0.5731"],"sensible":["MAP"],"code":["T2"],"vegtype":["Broadleaf Evergreen Forest"],"name":["Broadleaf_Evergreen_Forest"],"NACP_FI_AGB_US":["NA"],"NACP_LiDAR_Boreal_AGB":["0"],"LiDAR_AGB_Boreal_Eurasia":[""],"SOC":["51.7241"],"biophysical_net":["0.5731"],"in_synmap":["true"]}}}},"options":{"T_E":"50","T_A":"100","r":"0.00","co2":"TRUE","n2o":"TRUE","ch4":"TRUE","storage":"TRUE","flux":"TRUE","disturbance":"TRUE","includeANTH":"TRUE","includeBIO":"TRUE"}}

The command below fails on the Ruby app side (this repo):

connection.eval("ghgvcr::calc_ghgv(data)").to_ruby

With the following error messages listed:

Error in eco_params$options : $ operator is invalid for atomic vectors
Rserve::Connection::EvalError (eval failed: Packet[cmd=2130771970,len=<nil>, con='<nil>', status=error:'Unknown variable/method'(127)])

This looks like an error on the ghgvcr repo side of things (the R application), rather than the ruby/rails side. Noting here for triage & investigation further (even though likely broken on the ghgvcr repo).

Unclear if this is related to this bit of code leftover with the XML stuff (thought was ripped out):

https://github.com/jaydorsey/ghgvcR/blob/master/R/ghgvc.R#L49

Steps to Reproduce

Use the jay/compose_improvements branch for testing. The branch uses an image I pushed up that uses a slightly different path for the data folder (/app/data) so we could use compose locally without having to spend a lot of time thinking about how the data gets loaded/mounted (the command downloads the data to a mounted volume which is preserved across up/down calls)

docker-compose up on the branch and visit http://localhost:3000 and try to generate a graph to see the error

Desired behavior

@ValentineHerr I can schedule a time to chat about this if you've got time in the upcoming weeks, if you think it's something you can investigate & resolve.

potterzot commented 7 years ago

Just thought I'd chime in quickly if I can help, though I'm sort of out of the loop. The calc_ghgv takes the data passed in and converts from json to an R list via the code below:

#convert from json to list
eco_params <- if(is_xml) xmlToList(eco) else fromJSON(eco)

#get config information
options <- eco_params$options

If the above JSON is well formed, then was there a change to the fromJSON() function that would make this happen? I remember dealing with it not properly nesting at some point, but not sure.