Example #1
0
    def replace(self, s, data, attrs=None):
        """
        Replace the attributes of the plotter data in a string

        %(replace_note)s

        Parameters
        ----------
        s: str
            String where the replacements shall be made
        data: InteractiveBase
            Data object from which to use the coordinates and insert the
            coordinate and attribute informations
        attrs: dict
            Meta attributes that shall be used for replacements. If None, it
            will be gained from `data.attrs`

        Returns
        -------
        str
            `s` with inserted informations"""
        # insert labels
        s = s.format(**self.rc['labels'])
        # replace attributes
        attrs = attrs or data.attrs
        if hasattr(data, 'arr_name'):
            attrs = attrs.copy()
            attrs['arr_name'] = data.arr_name
        s = safe_modulo(s, attrs)
        # replace datetime.datetime like time informations
        if isinstance(data, InteractiveList):
            data = data[0]
        tname = self.decoder.get_tname(next(self.plotter.iter_base_variables),
                                       data.coords)
        if tname is not None and tname in data.coords:
            time = data.coords[tname]
            if not time.values.ndim:
                try:  # assume a valid datetime.datetime instance
                    s = pd.to_datetime(str(time.values[()])).strftime(s)
                except ValueError:
                    pass
        if six.PY2:
            return s.decode('utf-8')
        return s
Example #2
0
    def replace(self, s, data, attrs=None):
        """
        Replace the attributes of the plotter data in a string

        %(replace_note)s

        Parameters
        ----------
        s: str
            String where the replacements shall be made
        data: InteractiveBase
            Data object from which to use the coordinates and insert the
            coordinate and attribute informations
        attrs: dict
            Meta attributes that shall be used for replacements. If None, it
            will be gained from `data.attrs`

        Returns
        -------
        str
            `s` with inserted informations"""
        # insert labels
        s = s.format(**self.rc['labels'])
        # replace attributes
        attrs = attrs or data.attrs
        if hasattr(getattr(data, 'psy', None), 'arr_name'):
            attrs = attrs.copy()
            attrs['arr_name'] = data.psy.arr_name
        s = safe_modulo(s, attrs)
        # replace datetime.datetime like time informations
        if isinstance(data, InteractiveList):
            data = data[0]
        tname = self.any_decoder.get_tname(
            next(self.plotter.iter_base_variables), data.coords)
        if tname is not None and tname in data.coords:
            time = data.coords[tname]
            if not time.values.ndim:
                try:  # assume a valid datetime.datetime instance
                    s = pd.to_datetime(str(time.values[()])).strftime(s)
                except ValueError:
                    pass
        if six.PY2:
            return s.decode('utf-8')
        return s
Example #3
0
 def _iter_base_and_pattern(self, key):
     return zip(
         map(lambda s: safe_modulo(s, {'key': key}), self.base_str),
         self.patterns)