Repository navigation
Feature/outputcorr - #208
parvumflumen wants to merge 45 commits into
Conversation
Add pylint ignore statement in statcorr/__init__.py Add simulationmode in doctest in xmltools.py
Add statcorr references in model_families.rst and submodel_interfaces.rst
Fix pylint warnings
…ft and ResidualTransitionTime to TransitionSteps
Add Parameter correctionmode Update docstrings Add docstring to __init__.py
ac7c733 to
513287e
Compare
tyralla
left a comment
There was a problem hiding this comment.
Thanks for the PR. I am looking forward to using this new feature soon!
I left a few initial remarks; some of them are quite general. It would be very helpful if you could respond to them before I start to dig into the details.
# Conflicts: # hydpy/core/optiontools.py # hydpy/core/typingtools.py
tyralla
left a comment
There was a problem hiding this comment.
I have now gone through all modules and RST files except statcorr_model and statcorr_arima010. I left quite a few remarks regarding "what to document where and in what detail". I will continue with the remaining modules once they are settled.
tyralla
left a comment
There was a problem hiding this comment.
I left only a few more minor remarks in the modules already discussed. I'll review the remaining modules this Wednesday.
| NDIM: Final[Literal[0]] = 0 | ||
|
|
||
|
|
||
| class CorrectedValue(sequencetools.FluxSequence): |
There was a problem hiding this comment.
Just a note: This could be a factor sequence, too, as the actually corrected property is intentionally undefined.
(I thought about turning it into an aide sequence for a second, but that's not a good idea.)
| NDIM: Final[Literal[0]] = 0 | ||
|
|
||
|
|
||
| class IsActive(sequencetools.FluxSequence): |
There was a problem hiding this comment.
This is definitely not a flux. But I am not sure if using FactorSequence is really better. StateSequence sounds best, but shouldn't be used if previous states are never of importance. If in doubt, leave as is...
|
|
||
|
|
||
| class AveragedResidual(sequencetools.StateSequence): | ||
| """The mean-value-based residual (mean observed minus mean simulated value) |
There was a problem hiding this comment.
As far as I know, residuals are usually defined as sim - obs. (If LARSIM defined it otherwise, its fine - just in case that's a typo)
| flu.correctedvalue = min( | ||
| max(flu.correctedvalue, con.minvalue), con.maxvalue | ||
| ) |
There was a problem hiding this comment.
This could also be extracted into a new method called Update_CorrectedValue_V1.
| def __call__(model: modeltools.Model, /) -> None: | ||
| sta = model.sequences.states.fastaccess | ||
| if model.runsettings.simulationmode == modelutils.FORECAST: | ||
| sta.forecaststep = sta.forecaststep + 1.0 |
| ] | ||
|
|
||
| @importtools.prepare_submodel( # type: ignore[call-overload, untyped-decorator] | ||
| "outputcorrmodels", statcorrinterfaces.OutputCorrModel_V1, dimensionality=1 |
There was a problem hiding this comment.
outputcorrmodels could maybe be shortened. Just for convenience. Not very important.
| The main model does not need to pass any information to the submodel. In | ||
| particular, the submodel determines the length of its log from its own | ||
| parameters (see |NmbLogEntries|): |
There was a problem hiding this comment.
An AI relict from our previos refactorings?
| class Sub_OutputCorrModel(modeltools.AdHocModel): | ||
| """Base class for submodels that comply with the submodel interfaces defined in | ||
| module |statcorrinterfaces|.""" |
There was a problem hiding this comment.
Do we need this (empty) base class?
tyralla
left a comment
There was a problem hiding this comment.
While trying to understand Calc_CorrectedValue_V1 better before reviewing the application models, a found many doctest lines distracting. Some of them are unnecessary (they do not affect any test) and some of them appear too early (they only affect later tests). I left some remarks for the first example of Calc_CorrectedValue_V1 but did not go through the following examples and did not analyse the other methods for similar possibilities to improve the doctest.
| >>> parameterstep() | ||
| >>> control.maxabsshift(100.0) | ||
| >>> control.maxrelshift(10.0) | ||
| >>> from numpy import inf |
| >>> from numpy import inf | ||
| >>> control.minvalue(-inf) | ||
| >>> control.maxvalue(inf) | ||
| >>> control.averagingwindow(0) |
| >>> control.minvalue(-inf) | ||
| >>> control.maxvalue(inf) | ||
| >>> control.averagingwindow(0) | ||
| >>> control.transitionsteps(0) |
| >>> from hydpy import pub | ||
| >>> pub.options.simulationmode = "historical" |
There was a problem hiding this comment.
can be removed
(but pub would have to be imported below)
| >>> pub.options.simulationmode = "historical" | ||
| >>> fluxes.isactive = 0.0 | ||
| >>> states.reductionfactor(0.5) | ||
| >>> states.lowvariability(0.0) |
| >>> states.lowvariability(0.0) | ||
| >>> states.forecaststep(0.0) | ||
| >>> states.averagedresidual(0.0) | ||
| >>> states.residual(1.0) |
There was a problem hiding this comment.
could be moved to a later example
| >>> states.forecaststep(0.0) | ||
| >>> states.averagedresidual(0.0) | ||
| >>> states.residual(1.0) | ||
| >>> states.residualanchor(5.0) |
There was a problem hiding this comment.
could be moved to a later example
|
|
||
| >>> from hydpy.models.statcorr import * | ||
| >>> parameterstep() | ||
| >>> control.maxabsshift(100.0) |
| >>> from hydpy.models.statcorr import * | ||
| >>> parameterstep() | ||
| >>> control.maxabsshift(100.0) | ||
| >>> control.maxrelshift(10.0) |
| >>> model.calc_correctedvalue_v1() | ||
| >>> fluxes.correctedvalue | ||
| correctedvalue(0.0) | ||
| >>> del pub.options.simulationmode |
There was a problem hiding this comment.
We usually hide such resettings (which affect other tests) by using the .. testsetup:: directive.
Would be good to do the same here and elsewhere.
This pull request adds the new model family HydPy-StatCorr for the statistical correction of simulated discharge based on observed values. It follows the ARIMA(0,1,0) and LEG error correction of LARSIM, but is more flexible.
New models
statcorr_main: main model. It reads the simulated discharge from its inlet node(s), passes it to one or more correction submodels, and delivers the corrected discharge (CorrectedQ) to the outlet node.Propagatedecides whether the outlet node receives the corrected or the uncorrected value.statcorr_arima010: correction submodel complying with the interfaceOutputCorrModel_V1.