hec.interval
Provides standard time intervals
Exception specific to Interval operations
Class to hold information about time series recurrence intervals.
Intervals are a restriction of the TimeSpan base class that also hold extra information.
- Restriction: At most one of
years,months,days,hours, andminutescan be non-zero, andsecondsmust be zero. - Extension:
- Each interval has a name that may be context specific.
- Each also has a specified number of minutes:
- For non-calendar-based intervals, the minutes are the actual number of minutes in the interval
- For calendar-based intervals, the minutes are a characteristic number based on standard calendar items:
- Tri-Month: minutes = 10 * 1440 = 14400
- Semi-Month: minutes = 15 * 1440 = 21600
- 1 Month: minutes = 30 * 1440 = 43200
- 1 Year: minutes = 365 * 1440 = 525600
- 1 Decade: minutes = 365 * 1440 * 10 = 5256000
- 1 Century: minutes = 365 * 1440 * 100 = 52560000
Intervals should not need to be created by the user, as intervals for the following three contexts are created during initialization of the interval module:
- CWMS Context: Contains Intervals used with CWMS
- DSS Context: Contains Intervals used with HEC-DSS files
- DSS Block Size Context: Contains Intervals for the record block sizes in HEC-DSS files
Each context has its own set of four static methods that retrieve Interval objects or their names:
get_anyContext()get_anyContext_name()get_allContext()get_allContext_names()
Where Context is Cwms, Dss, or DssBlock.
There are similar static methods that retrieve Interval objects or their names from all contexts:
Initializer used by module
Dictionary that holds interval minutes, accessed by interval name. Includes all contexts.
Click to show contents.
| Name | Minutes | Context(s) |
|---|---|---|
| 0 | 0 | CWMS |
| Irr | 0 | CWMS |
| IR-Century | 0 | DSS |
| IR-Day | 0 | DSS |
| IR-Decade | 0 | DSS |
| IR-Month | 0 | DSS |
| IR-Year | 0 | DSS |
| 1Minute | 1 | CWMS, DSS |
| 2Minute | 2 | DSS |
| 2Minutes | 2 | CWMS |
| 3Minute | 3 | DSS |
| 3Minutes | 3 | CWMS |
| 4Minute | 4 | DSS |
| 4Minutes | 4 | CWMS |
| 5Minute | 5 | DSS |
| 5Minutes | 5 | CWMS |
| 6Minute | 6 | DSS |
| 6Minutes | 6 | CWMS |
| 10Minute | 10 | DSS |
| 10Minutes | 10 | CWMS |
| 12Minute | 12 | DSS |
| 12Minutes | 12 | CWMS |
| 15Minute | 15 | DSS |
| 15Minutes | 15 | CWMS |
| 20Minute | 20 | DSS |
| 20Minutes | 20 | CWMS |
| 30Minute | 30 | DSS |
| 30Minutes | 30 | CWMS |
| 1Hour | 60 | CWMS, DSS |
| 2Hour | 120 | DSS |
| 2Hours | 120 | CWMS |
| 3Hour | 180 | DSS |
| 3Hours | 180 | CWMS |
| 4Hour | 240 | DSS |
| 4Hours | 240 | CWMS |
| 6Hour | 360 | DSS |
| 6Hours | 360 | CWMS |
| 8Hour | 480 | DSS |
| 8Hours | 480 | CWMS |
| 12Hour | 720 | DSS |
| 12Hours | 720 | CWMS |
| 1Day | 1440 | CWMS, DSS |
| 2Day | 2880 | DSS |
| 2Days | 2880 | CWMS |
| 3Day | 4320 | DSS |
| 3Days | 4320 | CWMS |
| 4Day | 5760 | DSS |
| 4Days | 5760 | CWMS |
| 5Day | 7200 | DSS |
| 5Days | 7200 | CWMS |
| 6Day | 8640 | DSS |
| 6Days | 8640 | CWMS |
| 1Week | 10080 | CWMS, DSS |
| Tri-Month | 14400 | DSS |
| Semi-Month | 21600 | DSS |
| 1Month | 43200 | CWMS, DSS, DSS BLOCK SIZE |
| 1Year | 525600 | CWMS, DSS, DSS BLOCK SIZE |
| 1Decade | 5256000 | DSS BLOCK SIZE |
| 1Century | 52560000 | DSS BLOCK SIZE |
Retuns list of matched Interval objects in the any context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in all contexts are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
Returns:
List[Interval]: A list of matched
Intervalobjects (may be empty)
Retuns list of matched Interval objects in the CWMS context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in the context are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
List[Interval]: A list of matched
Intervalobjects (may be empty)
Retuns list of names of matched Interval objects in the CWMS context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in the context are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
List[str]: A list of names of matched
Intervalobjects (may be empty)
Retuns list of matched Interval objects in the DSS context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in the context are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
List[Interval]: A list of matched
Intervalobjects (may be empty)
Retuns list of names of matched Interval objects in the DSS block size context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in the context are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
List[str]: A list of names of matched
Intervalobjects (may be empty)
Retuns list of matched Interval objects in the DSS block size context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in the context are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
List[Interval]: A list of matched
Intervalobjects (may be empty)
Retuns list of names of matched Interval objects in the DSS context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in the context are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
List[str]: A list of names of matched
Intervalobjects (may be empty)
Retuns list of names of matched Interval objects in the any context
Arguments:
- matcher (Optional[Callable[[Interval], bool]]): A function that returns True or False when passed an
Intervalobject parameter. Defaults to None. If None, allIntervalobjects in all contexts are matched.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
Returns:
List[str]: A list of names of matched
Intervalobjects (may be empty)
Retuns a matched Interval object in any context
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
Optional[Interval]: A matched
Intervalobject or None
Retuns a matched Interval object in the CWMS context, or None if there is no such object
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_no_not_found and get_default_exception_on_not_found
Returns:
Optional[Interval]: A matched
Intervalobject or None
Retuns the name of a matched Interval object in the CWMS context, or None if there is no such object
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
Optional[str]: The name of a matched
Intervalobject or None
Retuns a matched Interval object in the DSS context, or None if there is no such object
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
Optional[Interval]: A matched
Intervalobject or None
Retuns a matched Interval object in the DSS block size context, or None if there is no such object
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
Optional[Interval]: A matched
Intervalobject or None
Retuns the name of a matched Interval object in the DSS block size context, or None if there is no such object
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
Optional[str]: The name of a matched
Intervalobject or None
Retuns the name of a matched Interval object in the DSS context, or None if there is no such object
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_exception_on_not_found and get_default_exception_on_not_found
Returns:
Optional[str]: The name of a matched
Intervalobject or None
Retuns the name of a matched Interval object in the any context, or None if there is no such object
Arguments:
- matcher (Callable[[Interval], bool]): A function that returns True or False when passed an
Intervalobject parameter.
Examples:lambda i : i.is_irregularlambda i : i.minutes < 60lambda i : i.name.find("Week") != -1
- exception_on_not_found (bool): Specifies whether to raise an exception if no Intervals are found. If None, the default behavior is used. Optional. Defaults to None. See set_default_excpetion_on_not_found and get_default_exception_on_not_found
Returns:
Optional[str]: The name of a matched
Intervalobject or None
Returns a CWMS interval with the specified name or minutes
Arguments:
- key (Union[str, int]): The name or (actual or characteristic) minutes of the interval to retrieve.
Raises:
- IntervalException: if no CWMS interval exists with the specified key
- TypeError: If the key is not a string or integer
Returns:
Interval: The CWMS interval
Generates a pandas DatetimeIndex from this interval.
Arguments:
- start_time (Any): A time in the first interval. If
offsetis None, this will be the first time, otherwise the first time will be the top of the interval containing this time plus the specifiedoffset. If the time includes no time zone, it will be assumed to be intime_zone, if specified, if any. Must be anHecTimeobject or an object suitable for theHecTimeconstructor - end_time (Optional[Any]): The generated series will end on or before this time, if specified. If the time includes no time zone, it will be assumed to be in
time_zone, if specified. If specified, must be anHecTimeobject or an object suitable for theHecTimeconstructor. Eitherend_timeorcount, but not both, must be specified. Defaults to None. - count (Optional[int]): The number of times in the index. Either
end_timeorcount, but not both, must be specified. Defaults to None. - offset (Optional[Any]): The offset of each time into the interval. If None, the offset is determined from
start_time. If specified, must be anTimeSpanobject or an object suitable for theTimeSpanconstructor. Defaults to None. - time_zone (Optional[Any]): The time zone of the generated times. Must be specified if the interval is a local-regular interval. Defaults to None.
- name (Optional[str]): The name of the index. If the generated index is to be used in a
TimeSeriesobject, specify the name as "name". Defaults to None.
Raises:
- IntervalException: If invalid parameters are specified
Returns:
pd.DatetimeIndex: The generated index.
Notes:
There is a somewhat subtle interplay between
start_timeandoffset. Ifoffsetis None or not specified, the index is generated as follows:
- The offset used is the offset of
start_timeinto the Interval object being used- The offset handles end-of-month dates and leap years by adjusting the actual offset at each time to keep dates as aligned as possible
Otherwise the offset is used literally.
See the following examples:
| Index on 1Month interval Values in red exceed the end of the month | ||||
|---|---|---|---|---|
| start_time | "2025‑01‑31 08:00:00" | "2025‑01‑01 00:00:00" | ||
| offset | None | TimeSpan("P30DT8H") | timedelta( days=30, hours=8, ) | |
| index | ||||
| 2025‑01‑31 08:00:00 | 2025‑01‑31 08:00:00 | 2025‑01‑31 08:00:00 | 2025‑01‑31 08:00:00 | |
| 2025‑02‑28 08:00:00 | 2025‑03‑03 08:00:00 | 2025‑03‑03 08:00:00 | 2025‑03‑03 08:00:00 | |
| 2025‑03‑31 08:00:00 | 2025‑03‑31 08:00:00 | 2025‑03‑31 08:00:00 | 2025‑03‑31 08:00:00 | |
| 2025‑04‑30 08:00:00 | 2025‑05‑01 08:00:00 | 2025‑05‑01 08:00:00 | 2025‑05‑01 08:00:00 | |
| 2025‑05‑31 08:00:00 | 2025‑05‑31 08:00:00 | 2025‑05‑31 08:00:00 | 2025‑05‑31 08:00:00 | |
| 2025‑06‑30 08:00:00 | 2025‑07‑01 08:00:00 | 2025‑07‑01 08:00:00 | 2025‑07‑01 08:00:00 | |
| 2025‑07‑31 08:00:00 | 2025‑07‑31 08:00:00 | 2025‑07‑31 08:00:00 | 2025‑07‑31 08:00:00 | |
| 2025‑08‑31 08:00:00 | 2025‑08‑31 08:00:00 | 2025‑08‑31 08:00:00 | 2025‑08‑31 08:00:00 | |
| 2025‑09‑30 08:00:00 | 2025‑10‑01 08:00:00 | 2025‑10‑01 08:00:00 | 2025‑10‑01 08:00:00 | |
| 2025‑10‑31 08:00:00 | 2025‑10‑31 08:00:00 | 2025‑10‑31 08:00:00 | 2025‑10‑31 08:00:00 | |
| 2025‑11‑30 08:00:00 | 2025‑12‑01 08:00:00 | 2025‑12‑01 08:00:00 | 2025‑12‑01 08:00:00 | |
| 2025‑12‑31 08:00:00 | 2025‑12‑31 08:00:00 | 2025‑12‑31 08:00:00 | 2025‑12‑31 08:00:00 | |
| Index on 1Year interval Values in red don't match the starting day-of-month | ||||
|---|---|---|---|---|
| start_time | "2025‑05‑11 00:00:00" | "2025‑01‑01 00:00:00" | ||
| offset | None | TimeSpan("P1M10D") | timedelta( days=130, ) | |
| index | ||||
| 2025‑05‑11 00:00:00 | 2025‑05‑11 00:00:00 | 2025‑05‑11 00:00:00 | 2025‑05‑11 00:00:00 | |
| 2026‑05‑11 00:00:00 | 2026‑05‑11 00:00:00 | 2026‑05‑11 00:00:00 | 2026‑05‑11 00:00:00 | |
| 2027‑05‑11 00:00:00 | 2027‑05‑11 00:00:00 | 2027‑05‑11 00:00:00 | 2027‑05‑11 00:00:00 | |
| 2028‑05‑11 00:00:00 | 2028‑05‑11 00:00:00 | 2028‑05‑11 00:00:00 | 2028‑05‑10 00:00:00 | |
| 2029‑05‑11 00:00:00 | 2029‑05‑11 00:00:00 | 2029‑05‑11 00:00:00 | 2029‑05‑11 00:00:00 | |
| 2030‑05‑11 00:00:00 | 2030‑05‑11 00:00:00 | 2030‑05‑11 00:00:00 | 2030‑05‑11 00:00:00 | |
| 2031‑05‑11 00:00:00 | 2031‑05‑11 00:00:00 | 2031‑05‑11 00:00:00 | 2031‑05‑11 00:00:00 | |
| 2032‑05‑11 00:00:00 | 2032‑05‑11 00:00:00 | 2032‑05‑11 00:00:00 | 2032‑05‑10 00:00:00 | |
| 2033‑05‑11 00:00:00 | 2033‑05‑11 00:00:00 | 2033‑05‑11 00:00:00 | 2033‑05‑11 00:00:00 | |
| 2034‑05‑11 00:00:00 | 2034‑05‑11 00:00:00 | 2034‑05‑11 00:00:00 | 2034‑05‑11 00:00:00 | |
| 2035‑05‑11 00:00:00 | 2035‑05‑11 00:00:00 | 2035‑05‑11 00:00:00 | 2035‑05‑11 00:00:00 | |
| 2036‑05‑11 00:00:00 | 2036‑05‑11 00:00:00 | 2036‑05‑11 00:00:00 | 2036‑05‑10 00:00:00 | |
Retrieves the default behavior if any of the get... methods do not find an Interval object to return.
Returns:
bool: True if the default behavior is to raise an exception when no Interval is found or False if
Noneis returned when no Interval is found
Returns an HEC-DSS interval with the specified name or minutes
Arguments:
- key (Union[str, int]): The name or (actual or characteristic) minutes of the interval to retrieve.
Raises:
- IntervalException: if no Dss interval exists with the specified key
- TypeError: If the key is not a string or integer
Returns:
Interval: The Dss interval
Returns the HEC-DSS block size for a specified interval.
Arguments:
- interval (Union[str, int, "Interval"]): The interval to return the block size for. May be an Interval object, or its name or (actual or characteristic) minutes.
Returns:
Interval: An interval object representing the HEC-DSS block size
Whether this object represents a normal irregular or pseudo-regular interval
Operations:
Read-only
Whether this object represents a regular or local regular interval
Operations:
Read-only
Whether this object represents a local regular interval
Operations:
Read-only
Whether this object represents a pseudo-regular interval
Operations:
Read-only
Sets the default behavior if any of the get... methods do not find an Interval object to return.
Arguments:
- state (bool): Whether to raise an exception if no Interval is found (True) or return None (False)