traitecoevo / plant

Trait-Driven Models of Ecology and Evolution :evergreen_tree:
https://traitecoevo.github.io/plant
53 stars 20 forks source link

Integrate between specified heights #322

Open dfalster opened 2 years ago

dfalster commented 2 years ago

When calculating outputs from the size distribution, we will often want to specify the bounds of the integrals. While we can use a trapezoidal integration across the heights specified by the solver characteristics (previously called cohort boundaries), it's unlikely the heights of the solver correspond to the desired integral boundaries.

Suggested method is to

  1. Create an interpolator
  2. Interpolate to desired points (including boundaries of the integral). Could be finer than original points, which would improve accuracy if the curvature of the spline approximation reflects true non-linearities.
  3. Integrate between these, e.g. using trapezoidal integration.

Note, with spline interpolators the integral can b calculated analytically between knots (https://stackoverflow.com/questions/51540182/how-to-save-and-load-spline-interpolation-functions-in-r).