indextools — HydPy 4.0.1 documentation
Bases: Generic[hydpy.core.propertytools.InputType, hydpy.core.propertytools.OutputType], hydpy.core.propertytools.BaseDescriptor
A property for handling time-related indices.
Some models (e.g. lland_v1) require time related index values.
IndexerProperty provides some caching functionalities to avoid
recalculating the same indices for different model instances over
and over again. We illustrate this by taking property
monthofyear as an example.
Generally, Indexer needs to know the relevant initialisation
period before being able to calculate any time-related index values.
If you forget to define one first, you get the following error
message:
>>> from hydpy import pub >>> pub.indexer.monthofyear Traceback (most recent call last): ... hydpy.core.exceptiontools.AttributeNotReady: An Indexer object has been asked for an `monthofyear` array. Such an array has neither been determined yet nor can it be determined automatically at the moment. Either define an `monthofyear` array manually and pass it to the Indexer object, or make a proper Timegrids object available within the pub module.
For efficiency, repeated querying of monthofyear returns
the same numpy array() object:
>>> pub.timegrids = "27.02.2004", "3.03.2004", "1d" >>> monthofyear = pub.indexer.monthofyear >>> monthofyear array([1, 1, 1, 2, 2]) >>> pub.indexer.monthofyear array([1, 1, 1, 2, 2]) >>> pub.indexer.monthofyear is monthofyear True
When the Timegrids object handled by module pub changes,
IndexerProperty calculates and returns a new index array:
>>> pub.timegrids.init.firstdate += "1d" >>> pub.indexer.monthofyear array([1, 1, 2, 2]) >>> pub.indexer.monthofyear is monthofyear False
When in doubt, you can manually delete the cached numpy ndarray
and receive a freshly calculated index array afterwards:
>>> monthofyear = pub.indexer.monthofyear >>> pub.indexer.monthofyear is monthofyear True >>> del pub.indexer.monthofyear >>> pub.indexer.monthofyear array([1, 1, 2, 2]) >>> pub.indexer.monthofyear is monthofyear False
You are allowed to define alternative values manually, which seems advisable only for testing purposes:
>>> pub.indexer.monthofyear = 0, 1, 2, 3 >>> pub.indexer.monthofyear array([0, 1, 2, 3]) >>> pub.timegrids.init.firstdate -= "1d" >>> pub.indexer.monthofyear array([1, 1, 1, 2, 2])
When assigning inadequate data, you get errors like the following:
>>> pub.indexer.monthofyear = "wrong" Traceback (most recent call last): ... ValueError: While trying to assign a new `monthofyear` index array to an Indexer object, the following error occurred: invalid literal for int() with base 10: 'wrong'
>>> pub.indexer.monthofyear = [[0, 1, 2, 3], [4, 5, 6, 7]] Traceback (most recent call last): ... ValueError: The `monthofyear` index array of an Indexer object must be 1-dimensional. However, the given value has interpreted as a 2-dimensional object.
>>> pub.indexer.monthofyear = 0, 1, 2, 3 Traceback (most recent call last): ... ValueError: The `monthofyear` index array of an Indexer object must have a number of entries fitting to the initialization time period precisely. However, the given value has been interpreted to be of length `4` and the length of the Timegrid object representing the actual initialisation period is `5`.
-
fget: hydpy.core.propertytools.FGet[OutputType]¶
-
fset: hydpy.core.propertytools.FSet[InputType]¶
-
call_fget(obj) → numpy.ndarray[source]¶ Method for implementing unique getter functionalities.