scmdata.time
Time period handling and interpolation
A large portion of this module was originally from openscm. Thanks to the original author, Sven Willner
TimePoints
- class TimePoints(values)[source]
Bases:
object
Handles time points by wrapping
numpy.ndarray
ofnumpy.datetime64
..- as_cftime(date_cls=<class 'cftime._cftime.DatetimeGregorian'>)[source]
Format time points as
cftime.datetime
- Parameters:
date_cls (
cftime.datetime
) – The time points will be returned as instances ofdate_cls
- Returns:
list of
cftime.datetime
– Time points as a list ofdate_cls
objects
- days()[source]
Get day of each time point.
- Returns:
numpy.ndarray
ofint
– Day of each time point
- hours()[source]
Get hour of each time point.
- Returns:
numpy.ndarray
ofint
– Hour of each time point
- months()[source]
Get month of each time point.
- Returns:
numpy.ndarray
ofint
– Month of each time point
- to_index()[source]
Get time points as
pandas.Index
.- Returns:
pandas.Index
–pandas.Index
ofnumpy.dtype
object
with name"time"
made from the time points represented asdatetime.datetime
.
- weekdays()[source]
Get weekday of each time point.
- Returns:
numpy.ndarray
ofint
– Day of the week of each time point
- years()[source]
Get year of each time point.
- Returns:
numpy.ndarray
ofint
– Year of each time point
TimeseriesConverter
- class TimeseriesConverter(source_time_points, target_time_points, 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)[source]
Convert value from source timeseries time points to target timeseries time points.
- Parameters:
values (np.ndarray) – Value
- Returns:
np.ndarray – Converted data for timeseries
values
into the target timebase
- convert_to(values)[source]
Convert value from target timeseries time points to source timeseries time points.
- Parameters:
values (np.ndarray) – Value
- Returns:
np.ndarray – Converted data for timeseries
values
into the source timebase
- points_are_compatible(source, target)[source]
Are the two sets of time points compatible i.e. can I convert between the two?
- Parameters:
source (
numpy.ndarray
) – Source timeseries time pointstarget (
numpy.ndarray
) – Target timeseries time points
- Returns:
bool – Can I convert between the time points?