-
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
Draft implementation of new OptimalChi structure #172
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #172 +/- ##
===========================================
- Coverage 93.83% 93.48% -0.36%
===========================================
Files 28 28
Lines 1395 1458 +63
===========================================
+ Hits 1309 1363 +54
- Misses 86 95 +9 ☔ View full report in Codecov by Sentry. |
@davidorme , would |
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. |
That's interesting. I'm a bit conflicted about More broadly, I should have deleted those |
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 try:
opt_chi_method = OPTIMAL_CHI_CLASS_REGISTRY[method]
except KeyError:
...
self.opt_chi = opt_chi_method(...) |
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 😄 I can see the value in splitting the ABC from the subclasses though. |
…ing xi injection from two methods
…tChi class, added requires to CalcOptimalChiNew
…nly via PmodelEnv
…to validate refactor
… to use new is_c4 attribute.
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
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.
The changes in the structure of OptimalChi look good to me. The changes certainly make the submodule more extendable in terms of methods and features.
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