tilbud / rCMEM

GNU General Public License v3.0
2 stars 4 forks source link

Dividing by 0 in depthOfNonRootVolume #17

Closed HolmquistJ closed 4 years ago

HolmquistJ commented 4 years ago

https://github.com/tilbud/rCTM/blob/f262c175991e6582937e93bbf26490b06662d576/R/depthOfNonRootVolume.R#L41-L49

I'm doing the fullBlownMem build and I'm running into a problem in cases where the marsh elevation doesn't keep pace with SLR, and the surface falls outside the plant growing tolerance. In those cases all the rootMasses become 0, but all of the min and max depths of the cohorts that previously had roots are now NA's. I think I traced the issue back to the depthOfNonRoot function. When totalRootVolume is 0, rootWidth is 0 and so is coef1. If coefficient11 is 0 then ansDepth for those with roots become NAN since you're dividing by 0. Could this use a quick ifelse statement.

HolmquistJ commented 4 years ago

@ktoddbrown could this be handled if there was a broader application of the 'beyond' roots addition, the beyondRoots zone could be defined by root depth or all 0's. Could we also handle this in the biomass function? Return maxRootDepth of 0 when biomass is 0.