natcap / invest

InVEST®: models that map and value the goods and services from nature that sustain and fulfill human life.
Apache License 2.0
170 stars 70 forks source link

Rework Coastal Blue Carbon to eliminate timeseries iteration #368

Open phargogh opened 4 years ago

phargogh commented 4 years ago

I'm documenting this while it's on my mind as we're nearing the end of #316 , #209 , will full knowledge that it might not be worth addressing. The recently-completed iteration of Coastal Blue Carbon takes a timeseries approach to the model, where (for the most part) each year is computed in sequence and (again, for the most part) each output raster is represented as a task. The advantages of this approach include:

  1. The model is implemented as it is described in the user's guide, and so is easier to debug and interpret
  2. The model outputs a lot of spatial rasters, which aids in debugging and also in certain analyses where the finer granularity of outputs is helpful
  3. The division of many of these outputs into so many tasks is helpful in that much of the computation can be parallelized.

One of the drawbacks of this approach is that it requires a lot of bookkeeping that might not be necessary. It turns out that all of the math of the model implies that a closed-form solution is possible, though it doesn't eliminate the need for some degree of bookkeeping according to transitions. Here's my reasoning:

  1. All accumulation happens linearly, based on the rate of accumulation, the initial stocks, and how long it's been since the last landcover change (when the accumulation rate might have changed).
  2. Emissions happen in a non-linear fashion, but the emissions between one year and another can be found by adjusting the years used in the emissions calculations, simply taking the difference between a wider range of years. This works because of the evaluation theorem of integral calculus.

In all honesty, it's possible that this is just a fun idea and not something that ends up being practical because of how the model handles the various transition events and a true, general-case closed-form solution might not be possible or might be harder to express and debug. If this ends up being the case, then implementing this proposed change might not be worth it at all.

phargogh commented 4 years ago

Note to self: for yet another rebuild to be worth it, the rewrite should have a tangible benefit to us, either in terms of performance or in terms of maintenance.

Because it's still a timeseries model, performance improvements are unlikely unless we make the intermediate rasters optional.

Would it be easier to maintain a closed-form version of this? I'm not so sure.