AleMorales / MaespaGrowth

Modified version of the Maespa model to simulate growth of trees using simple allocation and respiration rules
1 stars 0 forks source link

Julia version #1

Open rafaqz opened 6 years ago

rafaqz commented 6 years ago

Hi Alejandro,

I though you might be interested in this seeing your list of Julia packages:

https://github.com/rafaqz/Photosynthesis.jl

Its a rewrite of Maespa/Maestra in Julia, minus the spatial/canopy elements. I haven't totally finished testing it against the original Fortran but mostly it's working. It uses dispatch instead of if/else blocks so you can override anything without changing the code.

If you are doing any more work in that direction it would be great to collaborate on getting a really solid photosynthesis library working in Julia.

AleMorales commented 6 years ago

That looks great!

I do have some code in https://github.com/AleMorales/ecophys.jl for C3 and C4 photosynthesis (they are implementations of the models by Yin & Struik, 2009, NJAS) and a bunch of code stored locally that I need to upload at some point.

My experience with photosynthesis is that the core equations are quite common (except for metabolic models of photosynthesis) but the way the equations are combined varies greatly, so I like the modular approach your are following. In that sense you may want to take a look at https://github.com/AleMorales/ModularTypes.jl which was built for exactly the kind of modularity you are using.

I don't know what is the best way forward as probably we both need to keep our code around (I definitely do, as manuscripts are being written that rely on that code), but I am interested in the idea of a future package (or series of packages) consolidating our efforts.

Two comments about Photosynthesis.jl:

I noticed you are using Unitful. That is really useful, but as far as I remember, Unitful numbers are not compatible with some of the numerical libraries (e.g. for optimization) so an efficient interface will be required. This may affect your design, I am not sure.

You mention YplantQMC in the repository. I am building a 3D plant modelling platform that will include a multithreaded julia ray tracer and hope to get it ready soonish and upload it here. I also plan to work on more classic turbid-medium based canopy models (like Maespa) though this is not a priority at the moment.

rafaqz commented 6 years ago

A standalone ray tracer would be great Especially if we work out how to integrate the packages easily. I was all of your other packages too (and kind of wished I found them before I spent 2 months rewriting maespa!)

A good reason for using Unitful is that it gives you an api for separate packages to talk to each other with no boilerplate. I have run that model in DiffEqSensistivity analysis with Dual numbers! But its tricky.

I rewrote this to flatten the nested structs of parameters down to vectors: https://github.com/rafaqz/Flatten It takes the unit val field and rebuilds from a unitless vectors, so numerical tools don't see the units at all.

But you need to do this dance with DiffEqSensisitvity to match all the combinations of units, dual numbers and normal numbers it will pass to the parametrized functions: https://github.com/rafaqz/DynamicEnergyBudgets.jl/blob/master/src/sensitivity.jl

But we should be able to standardise and automate it all eventually. I'll have to get my head around MultiTraits, seems like we've been on similar journey! I wrote https://github.com/rafaqz/Mixers.jl for mixin macros to deal with field reuse leaf types where Julias composition gets annoying. But I'm not sure of the best strategy yet.

rafaqz commented 6 years ago

Oops that link should have been https://github.com/rafaqz/Flatten.jl