dates
- anemoi.utils.dates.as_datetime(date: date | datetime | str, keep_time_zone: bool = False) datetime
Convert a date to a datetime object, removing any time zone information.
- Parameters:
date (datetime.date or datetime.datetime or str) – The date to convert.
keep_time_zone (bool, optional) – If True, the time zone information is kept, by default False.
- Returns:
The datetime object.
- Return type:
- anemoi.utils.dates.as_datetime_list(date: date | datetime | str, default_increment: int = 1) list[datetime]
Convert a date to a list of datetime objects.
- Parameters:
date (datetime.date or datetime.datetime or str) – The date to convert.
default_increment (int, optional) – The default increment in hours, by default 1.
- Returns:
A list of datetime objects.
- Return type:
- anemoi.utils.dates.as_timedelta(frequency: int | str | timedelta) timedelta
Convert anything to a timedelta object.
- Parameters:
frequency (int or str or datetime.timedelta) –
The frequency to convert. If an integer, it is assumed to be in hours. If a string, it can be in the format:
”1h” for 1 hour
”1d” for 1 day
”1m” for 1 minute
”1s” for 1 second
”1:30” for 1 hour and 30 minutes
”1:30:10” for 1 hour, 30 minutes and 10 seconds
”PT10M” for 10 minutes (ISO8601)
If a timedelta object is provided, it is returned as is.
- Returns:
The timedelta object.
- Return type:
- Raises:
ValueError – Exception raised if the frequency cannot be converted to a timedelta.
- anemoi.utils.dates.frequency_to_timedelta(frequency: int | str | timedelta) timedelta
Convert a frequency to a timedelta object.
- Parameters:
frequency (int or str or datetime.timedelta) – The frequency to convert.
- Returns:
The timedelta object.
- Return type:
- anemoi.utils.dates.frequency_to_string(frequency: timedelta) str
Convert a frequency (i.e. a datetime.timedelta) to a string.
- Parameters:
frequency (datetime.timedelta) – The frequency to convert.
- Returns:
A string representation of the frequency.
- Return type:
- anemoi.utils.dates.frequency_to_seconds(frequency: int | str | timedelta) int
Convert a frequency to seconds.
- Parameters:
frequency (int or str or datetime.timedelta) – The frequency to convert.
- Returns:
Number of seconds.
- Return type:
- class anemoi.utils.dates.DateTimes(start: date | datetime | str, end: date | datetime | str, increment: int = 24, *, day_of_month: tuple[int, list[int]] | None = None, day_of_week: tuple[str, list[str]] | None = None, calendar_months: int | str | list[int | str] | None = None)
Bases:
objectThe DateTimes class is an iterator that generates datetime objects within a given range.
- class anemoi.utils.dates.Year(year: int, **kwargs)
Bases:
DateTimesYear is defined as the months of January to December.
- class anemoi.utils.dates.Winter(year: int, **kwargs)
Bases:
DateTimesWinter is defined as the months of December, January and February.
- class anemoi.utils.dates.Spring(year: int, **kwargs)
Bases:
DateTimesSpring is defined as the months of March, April and May.
- class anemoi.utils.dates.Summer(year: int, **kwargs)
Bases:
DateTimesSummer is defined as the months of June, July and August.
- class anemoi.utils.dates.Autumn(year: int, **kwargs)
Bases:
DateTimesAutumn is defined as the months of September, October and November.
- class anemoi.utils.dates.ConcatDateTimes(*dates: DateTimes)
Bases:
objectConcatDateTimes is an iterator that generates datetime objects from a list of dates.
- class anemoi.utils.dates.EnumDateTimes(dates: list[date | datetime | str])
Bases:
objectEnumDateTimes is an iterator that generates datetime objects from a list of dates.
- anemoi.utils.dates.datetimes_factory(*args: Any, **kwargs: Any) DateTimes | ConcatDateTimes | EnumDateTimes
Create a DateTimes, ConcatDateTimes, or EnumDateTimes object.
- Parameters:
*args (Any) – Positional arguments.
**kwargs (Any) – Keyword arguments.
- Returns:
The created object.
- Return type: