Closed davidorme closed 7 months ago
Attention: 21 lines
in your changes are missing coverage. Please review.
Comparison is base (
82565ca
) 93.83% compared to head (b3a03ca
) 93.48%. Report is 5 commits behind head on develop.
Files | Patch % | Lines |
---|---|---|
pyrealm/pmodel/optimal_chi.py | 87.74% | 19 Missing :warning: |
pyrealm/pmodel/pmodel.py | 75.00% | 2 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@davidorme , would Final
attributes (see here) do what you want, instead of using @property
?
Also, and this might be controversial and/or philosophical: I would put the abstract base class and each derivative in its own file, because otherwise the file might become large, and if people derive their own subclasses they might want to keep that with their module, and not all add it into this one file.
If, on the other hand, you believe there won't be any additional implementations of that abstract class it is fine to keep everything together in one file.
@davidorme , would
Final
attributes (see here) do what you want, instead of using@property
?
That's interesting. I'm a bit conflicted about Final
because it seems to step over a line between indicating typing and controlling the usage of objects - I think I've just got a narrow view on what mypy
does though.
More broadly, I should have deleted those @property
comments. I've used that approach before but it is really defensive and adds complexity - if people manually change the properties of class attributes, then they should expect to get bitten 😄 I've always tended to be that defensive, but I've learned that this is often at the expense of making the code less transparent.
if people derive their own subclasses they might want to keep that with their module, and not all add it into this one file.
My intention in the implementation here is that someone can include a new subclass outside of the package code. If they have a python file that does this:
from pyrealm.pmodel.calc_optimal_chi_new import CalcOptimalChiNew
class MyCustomCalcOptChi(CalcOptimalChiNew, method = 'custom_opt_chi', is_c4=False):
...
then the __init_subclass__
would add the method to the registry and they could then use PModel(..., method='custom_opt_chi
). Once, that is, this approach is rolled out so that PModel does something like:
try:
opt_chi_method = OPTIMAL_CHI_CLASS_REGISTRY[method]
except KeyError:
...
self.opt_chi = opt_chi_method(...)
f people derive their own subclasses they might want to keep that with their module
Of course if people wanted to contribute that method to the package, then this could get out of hand, but that seems a way away :smile: I can see the value in splitting the ABC from the subclasses though.
Description
This is PR implements the first stage of addressing #119, allowing the main
PModel
code to be used within subdaily caculations. These changes provide a complete refactor of theCalcOptimalChi
class, which has a bunch of different approaches as methods, into theNewCalcOptimalChi
abstract base class (ABC), which then set of subclasses providing the different approaches.The main aims here are:
chi
using modified values of thexi
variable. The ABC requires subclasses to provideset_beta
andestimate_chi
: both of these methods are used as part of__init__
for a derived class, butestimate_chi
can also be used separately to inject newxi
values.One thing we might do in future but seems paranoid is make the
method
andis_c4
class attributes read only, but class attributes in ABCs seem finicky: using@property
seems like one approach but then causesmypy
issues with setting the values. That is paranoid though.The PR now:
CalcOptimalChi
rootzonestress
option intoPModelEnvironment
for a more consistent interface and cleaner signatures.OPTIMAL_CHI_CLASS_REGISTRY
interface intoPModel
and confirms the test suite passes with the new implementation.The last completed changes are to:
pmodel.calc_optimal_chi.py
modulepmodel.new_calc_optimal_chi.py
objects and filessphinx
referencesType of change
Key checklist
pre-commit
checks:$ pre-commit run -a
$ poetry run pytest
Further checks