breos.utils#
Utility functions for breos library.
Functions
|
Count the number of leap years in a range. |
|
Get the number of hours per timestep based on frequency. |
|
Get the number of timesteps per day based on frequency. |
|
Get the number of timesteps per year based on frequency. |
|
Check if a year is a leap year. |
Get the number of available CPU cores for parallel processing. |
|
|
Shift a DatetimeIndex-bearing object by whole years without Feb. |
|
Validate name as a safe filename component and return it lower-cased. |
- breos.utils.count_leap_years(start_year, num_years)[source]#
Count the number of leap years in a range.
- breos.utils.get_hours_per_step(freq)[source]#
Get the number of hours per timestep based on frequency.
- Parameters:
freq (
str) – Frequency string (‘h’ for hourly, ‘15min’ for 15-minute)- Return type:
- Returns:
Hours per timestep (1.0 for hourly, 0.25 for 15-min)
- Raises:
ValueError – If freq is not recognized
- breos.utils.get_steps_per_day(freq)[source]#
Get the number of timesteps per day based on frequency.
- breos.utils.get_steps_per_year(freq, leap_year=False)[source]#
Get the number of timesteps per year based on frequency.
- breos.utils.number_of_cores()[source]#
Get the number of available CPU cores for parallel processing.
- Return type:
- Returns:
Number of CPU cores (leaves 1 core free for system)
- breos.utils.remap_datetime_index_years(obj, year_offset)[source]#
Shift a DatetimeIndex-bearing object by whole years without Feb. 29 crashes.
Feb. 29 entries whose target year is not a leap year are dropped. That avoids both
Timestamp.replacefailures and duplicate Feb. 28 labels that would later makereindexfail.- Parameters:
year_offset (int)
- breos.utils.safe_path_slug(name)[source]#
Validate name as a safe filename component and return it lower-cased.
Input is lower-cased, then validated: allowed characters are ASCII letters, digits,
_,-. The result must start with an alphanumeric character and be at most 64 characters. Anything else (path separators,.., NUL bytes, spaces, dots) is rejected so the value cannot be used to escape an intended output directory when interpolated into a filename.