-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of Arrhenius methods #389
Conversation
… circular imports; updating functions to remove calc_ftemp_arrh; updating imports
pyrealm/constants/pmodel_const.py
Outdated
# Arrhenius values | ||
arrhenius_vcmax: dict = field( | ||
default_factory=lambda: dict( | ||
simple=dict(ha=65330), | ||
kattge_knorr=dict( | ||
entropy_intercept=668.39, | ||
entropy_slope=-1.07, | ||
ha=71513, | ||
hd=200000, | ||
), | ||
) | ||
) | ||
"""Coefficients of Arrhenius factor scaling for :math:`V_{cmax}`.""" | ||
|
||
arrhenius_jmax: dict = field( | ||
default_factory=lambda: dict( | ||
simple=dict(ha=43900), | ||
kattge_knorr=dict( | ||
entropy_intercept=659.70, | ||
entropy_slope=-0.75, | ||
ha=49884, | ||
hd=200000, | ||
), | ||
) | ||
) | ||
"""Coefficients of Arrhenius factor scaling for :math:`J_{max}`.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry to be a bit stupid (Python is not my first language), but I am confused about this. Can you explain to me what the field in all those dicts and lambdas does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a peculiarity of the dataclass
API. Default dataclass attributes get created from the class definition and so the value of mutable defaults ends up being shared and edited across all instances of the dataclass. So it forbids mutable defaults using the simple attr: type = val
system and instead you have to wrap the default value in a lambda through the field
constructor, which gives finer control over the attribute.
https://docs.python.org/3/library/dataclasses.html#mutable-default-values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Oh dear. 😆
From what I understand this looks sensible, and much cleaner. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #389 +/- ##
===========================================
+ Coverage 96.27% 96.34% +0.06%
===========================================
Files 34 35 +1
Lines 2659 2737 +78
===========================================
+ Hits 2560 2637 +77
- Misses 99 100 +1 ☔ View full report in Codecov by Sentry. |
es mean_growth_temperature to be set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, just one minor complaint about an outdated comment.
Description
This PR fixes #384, but also goes quite a bit further in trying to future proof the API of the
PModel
andSubdailyPModel
a bit. The basic story is:The
PModel
currently followsrpmodel
in using a modified Arrhenius equation parameterised by Kattge and Knorr (2007). This is inconsistent withSubdailyPModel
, is implemented a bit oddly (t_growth
should not be the same as the observed temperature) and there's no general agreement that using this form is better than the simple form at present.So, the simple equation (currently in
calc_ftemp_arrh
) should be used but it is highly likely that we're going to want to be alter the Arrhenius scaling in the near future.So this PR:
calc_ftemp_arrh
->calculate_simple_arrhenius_factor
andcalc_modified_arrhenius_factor
->calculate_kattge_knorr_arrhenius_factor
) and tidies the function implementation up a bit.pyrealm.pmodel.arrhenius
module that implements theArrheniusFactorABC
andARRHENIUS_METHOD_REGISTRY
. This ABC is really just a wrapper around the standalone functions that is tailored to run the calculations from within the context of aPModel
orSubdailyPModel
environment and the registry allows the implementations to be accessed via a short method name.method
attribute, which defines that short name. This name is used to:__init_subclass__
,method_arrhenius
argument to PModel, andtk
andtkref
) and then thecalculate_arrhenius_factor
method can be called with the coefficients for a given enzyme system. The base method checks the coefficients automatically and then calls the private_calculation_method
abstract method defined by the subclass.The PR then also:
I think the altered PModel API is sensible - even if the internals change a bit, the signatures should be stable.
Fixes #384
Type of change
Key checklist
pre-commit
checks:$ pre-commit run -a
$ poetry run pytest
Further checks