Skip to content

Feature/outputcorr - #208

Open
parvumflumen wants to merge 45 commits into
hydpy-dev:masterfrom
parvumflumen:feature/outputcorr
Open

parvumflumen wants to merge 45 commits into
hydpy-dev:masterfrom
parvumflumen:feature/outputcorr

Conversation

@parvumflumen

Copy link
Copy Markdown
Collaborator

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. Propagate decides whether the outlet node receives the corrected or the uncorrected value.
  • statcorr_arima010: correction submodel complying with the interface OutputCorrModel_V1.

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
…ft and ResidualTransitionTime to TransitionSteps
Add Parameter correctionmode
Update docstrings
Add docstring to __init__.py

@tyralla tyralla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/docs/rst/HydPy-StatCorr.rst Resolved

@tyralla tyralla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread hydpy/docs/rst/HydPy-StatCorr.rst Resolved
Comment thread hydpy/docs/rst/HydPy-StatCorr.rst Resolved
Comment thread hydpy/interfaces/statcorrinterfaces.py Resolved
Comment thread hydpy/interfaces/statcorrinterfaces.py Resolved
Comment thread hydpy/interfaces/statcorrinterfaces.py Resolved

@tyralla tyralla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment thread hydpy/models/statcorr/statcorr_model.py Resolved
Comment on lines +1023 to +1025
flu.correctedvalue = min(
max(flu.correctedvalue, con.minvalue), con.maxvalue
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sta.forecaststep += 1.0

]

@importtools.prepare_submodel( # type: ignore[call-overload, untyped-decorator]
"outputcorrmodels", statcorrinterfaces.OutputCorrModel_V1, dimensionality=1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outputcorrmodels could maybe be shortened. Just for convenience. Not very important.

Comment on lines +1227 to +1229
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|):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An AI relict from our previos refactorings?

Comment on lines +1246 to +1248
class Sub_OutputCorrModel(modeltools.AdHocModel):
"""Base class for submodels that comply with the submodel interfaces defined in
module |statcorrinterfaces|."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this (empty) base class?

@tyralla tyralla left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now reviewed statcorr_model. statcorr_main and statcorr_arima010 will follow tomorrow (sorry for the delay).

@tyralla tyralla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

>>> from numpy import inf
>>> control.minvalue(-inf)
>>> control.maxvalue(inf)
>>> control.averagingwindow(0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

>>> control.minvalue(-inf)
>>> control.maxvalue(inf)
>>> control.averagingwindow(0)
>>> control.transitionsteps(0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

Comment on lines +886 to +887
>>> from hydpy import pub
>>> pub.options.simulationmode = "historical"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

>>> states.lowvariability(0.0)
>>> states.forecaststep(0.0)
>>> states.averagedresidual(0.0)
>>> states.residual(1.0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be moved to a later example

>>> states.forecaststep(0.0)
>>> states.averagedresidual(0.0)
>>> states.residual(1.0)
>>> states.residualanchor(5.0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be moved to a later example


>>> from hydpy.models.statcorr import *
>>> parameterstep()
>>> control.maxabsshift(100.0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

>>> from hydpy.models.statcorr import *
>>> parameterstep()
>>> control.maxabsshift(100.0)
>>> control.maxrelshift(10.0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

>>> model.calc_correctedvalue_v1()
>>> fluxes.correctedvalue
correctedvalue(0.0)
>>> del pub.options.simulationmode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants