scmdata.time
Time period handling and interpolation
A large portion of this module was originally from openscm. Thanks to the original author, Sven Willner
- class scmdata.time.TimePoints(values)[source]
Bases:
object
Handles time points by wrapping
numpy.ndarray
ofnumpy.datetime64
..- as_cftime(date_cls: ~typing.Type[~cftime._cftime.datetime] = <class 'cftime._cftime.DatetimeGregorian'>) list [source]
Format time points as
cftime.datetime
- Parameters:
date_cls (
cftime.datetime
) – The time points will be returned as instances ofdate_cls
- Returns:
Time points as a list of
date_cls
objects- Return type:
list of
cftime.datetime
- days() ndarray [source]
Get day of each time point.
- Returns:
Day of each time point
- Return type:
numpy.ndarray
ofint
- hours() ndarray [source]
Get hour of each time point.
- Returns:
Hour of each time point
- Return type:
numpy.ndarray
ofint
- months() ndarray [source]
Get month of each time point.
- Returns:
Month of each time point
- Return type:
numpy.ndarray
ofint
- to_index() Index [source]
Get time points as
pandas.Index
.- Returns:
pandas.Index
ofnumpy.dtype
object
with name"time"
made from the time points represented asdatetime.datetime
.- Return type:
- weekdays() ndarray [source]
Get weekday of each time point.
- Returns:
Day of the week of each time point
- Return type:
numpy.ndarray
ofint
- years() ndarray [source]
Get year of each time point.
- Returns:
Year of each time point
- Return type:
numpy.ndarray
ofint
- class scmdata.time.TimeseriesConverter(source_time_points: ndarray, target_time_points: ndarray, interpolation_type='linear', extrapolation_type='linear')[source]
Bases:
object
Interpolator used to convert data between different time bases
This is a modified version originally in
openscm.time.TimeseriesConverter
. The integral preserving interpolation was removed as it is outside the scope of this package.- Parameters:
source_time_points (np.ndarray) – Source timeseries time points
target_time_points (np.ndarray) – Target timeseries time points
interpolation_type ({"linear"}) – Interpolation type. Options are ‘linear’
extrapolation_type ({"linear", "constant", None}) – Extrapolation type. Options are None, ‘linear’ or ‘constant’
- Raises:
InsufficientDataError – Timeseries too short to extrapolate
- convert_from(values: ndarray) ndarray [source]
Convert value from source timeseries time points to target timeseries time points.
- Parameters:
values (np.ndarray) – Value
- Returns:
Converted data for timeseries
values
into the target timebase- Return type:
np.ndarray
- convert_to(values: ndarray) ndarray [source]
Convert value from target timeseries time points to source timeseries time points.
- Parameters:
values (np.ndarray) – Value
- Returns:
Converted data for timeseries
values
into the source timebase- Return type:
np.ndarray
- points_are_compatible(source: ndarray, target: ndarray) bool [source]
Are the two sets of time points compatible i.e. can I convert between the two?
- Parameters:
source – Source timeseries time points
target – Target timeseries time points
- Returns:
Can I convert between the time points?
- Return type: