scmdata.time

Time period handling and interpolation

A large portion of this module was originally from openscm. Thanks to the original author, Sven Willner

exception scmdata.time.InsufficientDataError[source]

Bases: Exception

Insufficient data is available to interpolate/extrapolate

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class scmdata.time.TimePoints(values)[source]

Bases: object

Handles time points by wrapping numpy.ndarray of numpy.datetime64..

as_cftime(date_cls=<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 of date_cls

Returns

Time points as a list of date_cls objects

Return type

list of cftime.datetime

days() numpy.ndarray[source]

Get day of each time point.

Returns

Day of each time point

Return type

numpy.ndarray of int

hours() numpy.ndarray[source]

Get hour of each time point.

Returns

Hour of each time point

Return type

numpy.ndarray of int

months() numpy.ndarray[source]

Get month of each time point.

Returns

Month of each time point

Return type

numpy.ndarray of int

to_index() pandas.core.indexes.base.Index[source]

Get time points as pandas.Index.

Returns

pandas.Index of numpy.dtype object with name "time" made from the time points represented as datetime.datetime.

Return type

pandas.Index

property values: numpy.ndarray

Time points

weekdays() numpy.ndarray[source]

Get weekday of each time point.

Returns

Day of the week of each time point

Return type

numpy.ndarray of int

years() numpy.ndarray[source]

Get year of each time point.

Returns

Year of each time point

Return type

numpy.ndarray of int

class scmdata.time.TimeseriesConverter(source_time_points: numpy.ndarray, target_time_points: numpy.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: numpy.ndarray) numpy.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: numpy.ndarray) numpy.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: numpy.ndarray, target: numpy.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

bool