Generate an equally-spaced sequence of cftime.datetime objects between and including two dates (whose length equals the number of periods).
(start, end, periods)
| 863 | |
| 864 | |
| 865 | def _generate_linear_date_range(start, end, periods): |
| 866 | """Generate an equally-spaced sequence of cftime.datetime objects between |
| 867 | and including two dates (whose length equals the number of periods).""" |
| 868 | if TYPE_CHECKING: |
| 869 | import cftime |
| 870 | else: |
| 871 | cftime = attempt_import("cftime") |
| 872 | |
| 873 | total_seconds = (end - start).total_seconds() |
| 874 | values = np.linspace(0.0, total_seconds, periods, endpoint=True) |
| 875 | units = f"seconds since {format_cftime_datetime(start)}" |
| 876 | calendar = start.calendar |
| 877 | return cftime.num2date( |
| 878 | values, units=units, calendar=calendar, only_use_cftime_datetimes=True |
| 879 | ) |
| 880 | |
| 881 | |
| 882 | def _generate_linear_date_range_with_freq(start, end, periods, freq): |
no test coverage detected
searching dependent graphs…