You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve FactorAdaptor in the submodel context #199
While working on #188, I need to adjust the example explaining how to use FactorAdaptor. This is not possible without changing the implementation of FactorAdaptor, because it currently only works if the reference and the target parameter are members of the same model instance. However, in the current state of snow submodularisation, GLMelt is still a member of HydPy-H, but CFMax has been moved from HydPy-H to HydPy-Snow (and renamed DegreeDayFactor).
I will introduce a quick change that allows using a reference parameter from another (sub)model handled by the same element:
def__call__(self, target: parametertools.Parameter) ->None:
model=target.subpars.pars.model.element.modelcontrols= []
forsubmodelinmodel.find_submodels(include_mainmodel=True).values():
control=submodel.parameters.controlifhasattr(control, self._reference):
controls.append(control)
assertlen(controls) ==1# ToDo: Support to select the desired reference# parameter more explicitly (see Issue #199).ref=controls[0][self._reference]
ifself._mask:
mask=target.get_submask(self._mask)
values=ref.values[mask] ifref.NDIMelseref.valuetarget.values[mask] =self._rule.value*valueselse:
target.value=self._rule.value*ref.value
Note that after this change, the mask comes from the target parameter instead of the reference parameter. I think this is an improvement, but using a mask from the reference parameter might be preferable in some contexts. See the related discussion in #72.
I hope this quick improvement is enough for this (less commonly used feature) of the calibtools module. However, we should check later if related features show similar limitations and address the left ToDo remark.
Activity
Make class `FactorAdaptor` of module `calibtools` usable when the ref…