def _set_expression_vars(self, v): if v is not None: self._expression = str(v) if not isdynamic(v) else v[1:] self._nouse_expression = False if self._expression != '' else True else: self._expression = '' self._nouse_expression = False
def __new__(cls, *args, **kywds): if 'src' in kywds: obj = FigPlot.__new__(cls, *args, **kywds) # obj = set_hidden_vars(obj) obj._use_decimate = True return obj mpl_cmd, kywds = ProcessKeywords(kywds, 'mpl_command', 'plot') mpl_cmd = 'plot' p = ArgsParser() p.add_opt('x', None, ['numbers|nonstr', 'dynamic']) p.add_var('y', ['numbers|nonstr', 'dynamic']) p.add_opt('s', '', 'str') # optional argument # if mpl_cmd is 'errorbar': p.set_ndconvert("x", "y") p.set_squeeze_minimum_1D("x", "y") v, kywds, d, flag = p.process(*args, **kywds) if not flag: raise ValueError('Failed when processing argument') obj = FigPlot.__new__(cls, *args, **kywds) # obj = set_hidden_vars(obj) obj._use_decimate = True obj._mpl_cmd = mpl_cmd if (v["x"] is None and not isdynamic(v["y"])): v["x"] = np.arange(v["y"].shape[-1]) for name in v: obj.setvar(name, v[name]) obj.setvar("kywds", kywds) return obj
def __new__(cls, *args, **kywds): if kywds.has_key('src'): obj = FigPlot.__new__(cls, *args, **kywds) # obj = set_hidden_vars(obj) obj._use_decimate = True return obj mpl_cmd, kywds = ProcessKeywords(kywds, 'mpl_command', 'plot') mpl_cmd = 'plot' p = ArgsParser() p.add_opt('x', None, ['numbers|nonstr', 'dynamic']) p.add_var('y', ['numbers|nonstr', 'dynamic']) p.add_opt('s', '', 'str') ### optional argument # if mpl_cmd is 'errorbar': p.set_ndconvert("x","y") p.set_squeeze_minimum_1D("x","y") v, kywds,d, flag = p.process(*args, **kywds) if not flag: raise ValueError('Failed when processing argument') obj = FigPlot.__new__(cls, *args, **kywds) # obj = set_hidden_vars(obj) obj._use_decimate = True obj._mpl_cmd = mpl_cmd if (v["x"] is None and not isdynamic(v["y"])): v["x"] = np.arange(v["y"].shape[-1]) for name in v.keys(): obj.setvar(name, v[name]) obj.setvar("kywds", kywds) return obj
def __new__(cls, *args, **kywds): def set_hidden_vars(obj): obj._mpl_cmd = 'plot' obj._eb_container = (None, tuple(), tuple()) obj._other_artists = [] obj._objs = [] # for debug.... obj._data_extent = None obj._is_decimate = False obj._use_decimate = False obj._decimate_limit = _decimate_limit return obj if 'src' in kywds: obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) return obj mpl_cmd = kywds.pop('mpl_command', 'plot') p = ArgsParser() p.add_opt('x', None, ['numbers|nonstr', 'dynamic']) p.add_var('y', ['numbers|nonstr', 'dynamic']) p.add_opt('z', None, ['numbers|nonstr', 'dynamic']) p.add_opt('s', '', 'str') # optional argument p.add_key('cz', False, 'bool') # if mpl_cmd is 'errorbar': p.add_key('xerr', None) p.add_key('yerr', None) p.add_key('ecolor', None) p.add_key('elinewidth', None) p.add_key('array_idx', None) if 'cz' in kywds and kywds['cz']: p.add_key('cmap', 'jet') p.add_key('c', None) p.set_ndconvert("x", "y", "z", "xerr", "yerr", "c") p.set_squeeze_minimum_1D("x", "y", "z", "xerr", "yerr", "c") v, kywds, d, flag = p.process(*args, **kywds) if not flag: raise ValueError('Failed when processing argument') obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) obj._mpl_cmd = mpl_cmd if (v["x"] is None and not isdynamic(v["y"])): v["x"] = np.arange(v["y"].shape[-1]).astype(v["y"].dtype) if 'cmap' in v and v['cmap'] is not None: if isinstance(v['cmap'], Colormap): v['cmap'] = v['cmap'].name kywds['cmap'] = v['cmap'] del v['cmap'] for name in v: obj.setvar(name, v[name]) obj.setvar("kywds", kywds) return obj
def apply_squeeze(v, name, minimum_1D=False): if not v.has_key(name): return v if isdynamic(v[name]): return v try: if (v[name] is not None and not minimum_1D): v[name] = np.squeeze(v[name]) if (v[name] is not None and minimum_1D and v[name].dim > 1): v[name] = np.squeeze(v[name]) except: pass return v
def __new__(cls, *args, **kywds): def set_hidden_vars(obj): obj._mpl_cmd = 'plot' obj._eb_container = (None, tuple(), tuple()) obj._other_artists = [] obj._objs=[] ## for debug.... obj._data_extent=None obj._is_decimate = False obj._use_decimate = False obj._decimate_limit = _decimate_limit return obj if kywds.has_key('src'): obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) return obj mpl_cmd = kywds.pop('mpl_command', 'plot') p = ArgsParser() p.add_opt('x', None, ['numbers|nonstr', 'dynamic']) p.add_var('y', ['numbers|nonstr', 'dynamic']) p.add_opt('z', None, ['numbers|nonstr', 'dynamic']) p.add_opt('s', '', 'str') ### optional argument p.add_key('cz', False, 'bool') # if mpl_cmd is 'errorbar': p.add_key('xerr', None) p.add_key('yerr', None) p.add_key('ecolor', None) p.add_key('elinewidth', None) p.add_key('array_idx', None) if 'cz' in kywds and kywds['cz']: p.add_key('cmap', 'jet') p.add_key('c', None) p.set_ndconvert("x","y","z","xerr","yerr", "c") p.set_squeeze_minimum_1D("x","y","z","xerr","yerr", "c") v, kywds,d, flag = p.process(*args, **kywds) if not flag: raise ValueError('Failed when processing argument') obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) obj._mpl_cmd = mpl_cmd if (v["x"] is None and not isdynamic(v["y"])): v["x"] = np.arange(v["y"].shape[-1]).astype(v["y"].dtype) if 'cmap' in v and v['cmap'] is not None: if isinstance(v['cmap'], Colormap): v['cmap'] = v['cmap'].name kywds['cmap'] = v['cmap'] del v['cmap'] for name in v.keys(): obj.setvar(name, v[name]) obj.setvar("kywds", kywds) return obj
def do_check(value, cond): if cond == 'ndarray': return isndarray(value) if cond == 'can_ndreal_array': try: void = np.array(value).astype(np.float) return void.size > 0 except: pass return False elif cond == 'iter': return isiterable(value) elif cond == 'sequence': return issequence(value) elif cond == 'str': if six.PY2: return isinstance(value, str) or isinstance(value, unicode) else: return isinstance(value, str) elif cond == 'nonstr': if six.PY2: return not (isinstance(value, str) or isinstance(value, unicode)) else: return not isinstance(value, str) elif cond == 'int': return isinstance(value, int) elif cond == 'float': return isinstance(value, float) elif cond == 'real': return isinstance(value, float) or isinstance(value, int) elif cond == 'dynamic': return isdynamic(value) elif cond == 'bool': return isinstance(value, bool) elif cond == 'number': return isnumber(value) elif cond == 'empty': if (isinstance(value, list) and len(value) == 0): return True return False elif cond == 'numbers': if issequence(value): if len(value) == 0: return False return isnumber(value[0]) else: return False elif cond == 'any': return True print(('ArgsParser::Unknown condition (ignored)', cond)) return True
def convert_ndarray(v, name): if not v.has_key(name): return v if v[name] is None: return v if isdynamic(v[name]): return v if isiterable(v[name]) and not isndarray(v[name]): try: v[name] = np.array(v[name]) except: return v if not isiterable(v[name]): try: v[name] = np.array([v[name]]) except: return v if np.iscomplex(v[name]).any(): return v v[name] = v[name].astype(np.float) return v
def do_check(value, cond): if cond == 'ndarray': return isndarray(value) if cond == 'can_ndreal_array': try: void = np.array(value).astype(np.float) return void.size > 0 except: pass return False elif cond == 'iter': return isiterable(value) elif cond == 'sequence': return issequence(value) elif cond == 'str': return isinstance(value, str) or isinstance(value, unicode) elif cond == 'nonstr': return not (isinstance(value, str) or isinstance(value, unicode)) elif cond == 'int': return isinstance(value, int) elif cond == 'float': return isinstance(value, float) elif cond == 'real': return isinstance(value, float) or isinstance(value, int) elif cond == 'dynamic': return isdynamic(value) elif cond == 'bool': return isinstance(value, bool) elif cond == 'number': return isnumber(value) elif cond == 'empty': if (isinstance(value, list) and len(value) == 0): return True return False elif cond == 'numbers': if issequence(value): if len(value)==0: return False return isnumber(value[0]) else: return False elif cond == 'any': return True print('ArgsParser::Unknown condition (ignored)', cond) return True
def __new__(cls, *args, **kywds): if len(args) == 3: tri = args[0] args = args[1:] else: tri = None def set_hidden_vars(obj): obj._other_artists = [] obj._objs = [] # for debug.... obj._data_extent = None return obj if 'src' in kywds: obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) return obj p = ArgsParser() p.add_opt('x', None, ['numbers|nonstr', 'dynamic']) p.add_var('y', ['numbers|nonstr', 'dynamic']) p.add_key('color', 'b') p.add_key('linestyle', '-') p.add_key('linewidth', 1.0) p.set_ndconvert("x", "y") p.set_squeeze_minimum_1D("x", "y") p.add_key('mask', None) v, kywds, d, flag = p.process(*args, **kywds) if not flag: raise ValueError('Failed when processing argument') obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) if (v["x"] is None and not isdynamic(v["y"])): v["x"] = np.arange(v["y"].shape[-1]) for name in v: obj.setvar(name, v[name]) obj.setvar("kywds", kywds) obj.setvar("tri", tri) return obj
def __new__(cls, *args, **kywds): if len(args) == 3: tri = args[0] args = args[1:] else: tri = None def set_hidden_vars(obj): obj._other_artists = [] obj._objs=[] ## for debug.... obj._data_extent=None return obj if kywds.has_key('src'): obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) return obj p = ArgsParser() p.add_opt('x', None, ['numbers|nonstr', 'dynamic']) p.add_var('y', ['numbers|nonstr', 'dynamic']) p.add_key('color', 'b') p.add_key('linestyle', '-') p.add_key('linewidth', 1.0) p.set_ndconvert("x","y") p.set_squeeze_minimum_1D("x","y") p.add_key('mask', None) v, kywds, d, flag = p.process(*args, **kywds) if not flag: raise ValueError('Failed when processing argument') obj = FigObj.__new__(cls, *args, **kywds) obj = set_hidden_vars(obj) if (v["x"] is None and not isdynamic(v["y"])): v["x"] = np.arange(v["y"].shape[-1]) for name in v.keys(): obj.setvar(name, v[name]) obj.setvar("kywds", kywds) obj.setvar("tri", tri) return obj