示例#1
0
文件: gen.py 项目: jeffmaxey/tsio
def generate_source_map(ts, external_interfaces):
    """ Map reading sources with time series.

    Parameters
    ----------
    ts: :py:class:`TimeSeries`
        A time series.
    external_interfaces: list(objects)
        Instances of external reading classes.

    Returns
    -------
    dict
        Dictionary with ``{source_index: time_series_collection}`` pairs.
    """
    source_map = dict()
    ts_collection = convert_to_ts_collection(ts)
    for ts in ts_collection:
        for i, external_interface in enumerate(external_interfaces):
            if external_interface.is_member(ts):
                try:
                    source_map[i].add(ts)
                except KeyError:
                    source_map[i] = TimeSeriesCollection([ts])
                break
    return source_map
示例#2
0
文件: gen.py 项目: jeffmaxey/tsio
def flatten(ts, components=True, depth=np.inf):
    """ Create a :py:class:`TimeSeriesCollection` with passed time series and their components.

    Parameters
    ----------
    ts: type convertible to :py:obj:`TimeSeriesCollection`
        Time series collection whose components are to be "flattened".
    components: list(str), optional
        Components to include in the final time series collection. Default is all components.
    depth: int, optional
        Depth of components to include in the final time series collection. Default is infinity.

    Returns
    -------
    :py:obj:`TimeSeriesCollection`
        Flattened time series collection.
    """
    if isinstance(components, list):
        components = [key.upper() for key in components]
    flattened = TimeSeriesCollection()
    temp_ts_collection = convert_to_ts_collection(ts)
    counter = 0
    while counter < depth:
        ts_collection = temp_ts_collection
        if not ts_collection:
            break
        flattened.add_list(ts_collection)
        temp_ts_collection = TimeSeriesCollection()
        counter += 1
        for ts in ts_collection:
            instantiate_components(ts, components, temp_ts_collection)
    return flattened
示例#3
0
文件: gen.py 项目: jeffmaxey/tsio
    def read_attributes(self, ts_collection, components=True, depth=np.inf, attributes=None, use_external=True,
                        **kwargs):
        """ Read time series attributes from the database.

        Parameters
        ----------
        ts_collection: type convertible to :py:class:`TimeSeriesCollection`
            Time series to be read.
        components: list(str), optional
            Optional collection of component names to be read and instantiated. Default is all components.
        depth: int, optional
            Depth of component instantiation. ``depth = 1`` means no components are instantiated. Default is infinity.
        attributes: list(str), optional
            Optional collection of attribute names to be read. Default is all attributes.
        use_external: bool, optional
            Whether to use the external reading classes. Default is True.
        """
        ts = convert_to_ts_collection(ts_collection)
        super().read_attributes(ts_collection=ts, components=components, depth=depth, attributes=attributes)
        if use_external:
            flat_collection = flatten(ts)
            source_map = generate_source_map(flat_collection, self.external_interfaces)
            for interface_code, ts_collection in source_map.items():
                self.interfaces_map[interface_code].read_attributes(ts_collection=ts_collection, attributes=attributes,
                                                                    **kwargs)