Пример #1
0
    def check(self, value, incond):
        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 do_check2(value, conds):
            ret = True
            cond = conds.split('|')
            for c in cond: ret = ret and do_check(value, c)
            return ret

        if isiterable(incond) and not isinstance(incond, str):
           a = False
           for c in incond: a = a or do_check2(value, c)
           return a
        else:
           return do_check(value, incond)
Пример #2
0
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
Пример #3
0
 def do2(self):
     if self._use_do2 is not None:
         if isiterable(self._use_do2):
             for f in self._use_do2: f()
         else:
             self._use_do2()
         self.update_hl()
     return self.figobj
Пример #4
0
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
Пример #5
0
 def _en_numpy(self, v, name, s=True):
     from ifigure.utils.cbook import isiterable, isndarray
     if not name in v: return None, s and False
     if isiterable(v[name]) and not isndarray(v[name]):
         try:
             v[name] = np.array(v[name])
         except:
             return v[name], True and s
     return v[name], True and s
Пример #6
0
 def _en_numpy(self, v, name, s=True):
     from ifigure.utils.cbook import isiterable, isndarray
     if not name in v: return None, s and False
     if isiterable(v[name]) and not isndarray(v[name]):
         try:
             v[name] = np.array(v[name])
         except:
             return v[name], True and s
     return v[name], True and s
Пример #7
0
 def get_elinewidth(self, a):
     v = None
     if self._mpl_cmd == 'errorbar':
         for a in self._eb_container[1]:v = a.get_linewidth()
         for a in self._eb_container[2]:v = a.get_linewidth()
         if isiterable(v): v = v[0]
         return v
     else:
         return v
Пример #8
0
 def get_elinewidth(self, a):
     v = None
     if self._mpl_cmd == 'errorbar':
         for a in self._eb_container[1]:
             v = a.get_linewidth()
         for a in self._eb_container[2]:
             v = a.get_linewidth()
         if isiterable(v): v = v[0]
         return v
     else:
         return v
Пример #9
0
 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
Пример #10
0
 def _fill_setter(self, prop, value):
     from ifigure.utils.cbook import isiterable
     for a in self._artists:
         if isinstance(a, PolyCollection):
             m0 = getattr(a, 'get_'+prop)
             m = getattr(a, 'set_'+prop)
             if isiterable(m0()):
                 m([value]*len(m0()))
             else:
                 m(value)
         elif isinstance(a, Polygon):
             m = getattr(a, 'set_'+prop)
             m(value)
         else:
             dprint1('FigFill::Unknown artist type')
Пример #11
0
    def _set_ticker(self, a):
        try:
            if not isiterable(self.ticks):
                if self.scale == 'linear':
                    a.set_major_locator(mticker.AutoLocator())
                elif self.scale == 'log':
                    a.set_major_locator(mticker.LogLocator(self.base))
                elif self.scale == 'symlog':
                    from matplotlib.scale import SymmetricalLogScale
                    if isMPL33:
                        scale = SymmetricalLogScale(
                            a,
                            base=self.base,
                            linthresh=self.symloglin,
                            linscale=self.symloglinscale)
                    else:
                        scale = SymmetricalLogScale(
                            a,
                            basex=self.base,
                            linthreshx=self.symloglin,
                            linscalex=self.symloglinscale)
                    a.set_major_locator(
                        mticker.SymmetricalLogLocator(scale.get_transform()))


#                    scale.set_default_locators_and_formatters(a)

                else:
                    a.set_major_locator(mticker.AutoLocator())
                #a.get_axes().locator_params(self.name[0], nbins = 10)
                if self.ticks is not None:
                    value = self.ticks
                else:
                    #figpage = a.get_axes().figobj.get_figpage()
                    figpage = a.axes.figobj.get_figpage()
                    if self.name[0] == 'x':
                        value = figpage.getp('nticks')[0]
                    elif self.name[0] == 'y':
                        value = figpage.getp('nticks')[1]
                    elif self.name[0] == 'z':
                        value = figpage.getp('nticks')[2]
                    else:
                        pass
                try:
                    # this works onlyfor MaxNLocator
                    #a.get_axes().locator_params(self.name[0], nbins = value)
                    a.axes.locator_params(self.name[0], nbins=value)
                except BaseException:
                    # for Symlog and LogLocator
                    a.get_major_locator().numticks = value
            else:
                a.set_ticks(self.ticks)

            if self.format == 'default':
                if self.scale == 'linear':
                    a.set_major_formatter(mticker.ScalarFormatter())
                elif self.scale == 'log':
                    a.set_major_formatter(
                        mticker.LogFormatterMathtext(self.base))
                elif self.scale == 'symlog':
                    a.set_major_formatter(
                        mticker.LogFormatterMathtext(self.base))
                else:
                    a.set_major_formatter(mticker.ScalarFormatter())
            elif self.format == 'scalar':
                a.set_major_formatter(mticker.ScalarFormatter())
            elif self.format == 'scalar(mathtext)':
                a.set_major_formatter(
                    mticker.ScalarFormatter(useOffset=True, useMathText=True))
                a.get_major_formatter().get_offset()
            elif self.format == 'log':
                a.set_major_formatter(mticker.LogFormatter(self.base))
            elif self.format == 'log(mathtext)':
                a.set_major_formatter(mticker.LogFormatterMathtext(self.base))
            elif self.format == 'log(exp)':
                a.set_major_formatter(mticker.LogFormatterExponent(self.base))
            elif self.format == 'none':
                a.set_major_formatter(mticker.NullFormatter())
            else:
                a.set_major_formatter(mticker.FormatStrFormatter(self.format))
        except BaseException:
            import traceback
            traceback.print_exc()
Пример #12
0
    def _set_ticker(self, a):
        try:
            if not isiterable(self.ticks):
                if self.scale == 'linear':            
                     a.set_major_locator(mticker.AutoLocator())
                elif self.scale == 'log':
                     a.set_major_locator(mticker.LogLocator(self.base))                
                elif self.scale == 'symlog':
                    from matplotlib.scale import SymmetricalLogScale
                    scale = SymmetricalLogScale(a, basex = self.base,
                                                linthreshx = self.symloglin,
                                                linscalex = self.symloglinscale)
                    a.set_major_locator(mticker.SymmetricalLogLocator(scale.get_transform()))
#                    scale.set_default_locators_and_formatters(a)

                else:
                    a.set_major_locator(mticker.AutoLocator())
                #a.get_axes().locator_params(self.name[0], nbins = 10)
                if self.ticks is not None:
                    value = self.ticks
                else:
                    #figpage = a.get_axes().figobj.get_figpage()
                    figpage = a.axes.figobj.get_figpage()
                    if self.name[0] == 'x':
                        value = figpage.getp('nticks')[0]
                    elif self.name[0] == 'y':
                        value = figpage.getp('nticks')[1]
                    elif self.name[0] == 'z':
                        value = figpage.getp('nticks')[2]
                    else:
                        pass
                try:
                    ## this works onlyfor MaxNLocator
                    #a.get_axes().locator_params(self.name[0], nbins = value)
                    a.axes.locator_params(self.name[0], nbins = value)
                except:
                    ## for Symlog and LogLocator 
                    a.get_major_locator().numticks = value
            else:
                a.set_ticks(self.ticks)

            if self.format == 'default':
                if self.scale == 'linear':
                     a.set_major_formatter(mticker.ScalarFormatter())
                elif self.scale == 'log':
                     a.set_major_formatter(mticker.LogFormatterMathtext(self.base))
                elif self.scale == 'symlog':
                     a.set_major_formatter(mticker.LogFormatterMathtext(self.base))
                else:
                     a.set_major_formatter(mticker.ScalarFormatter())
            elif self.format == 'scalar':
                a.set_major_formatter(mticker.ScalarFormatter())
            elif self.format == 'scalar(mathtext)':
                a.set_major_formatter(mticker.ScalarFormatter(useOffset = True, useMathText = True))
                a.get_major_formatter().get_offset()
            elif self.format == 'log':
                a.set_major_formatter(mticker.LogFormatter(self.base))
            elif self.format == 'log(mathtext)':
                a.set_major_formatter(mticker.LogFormatterMathtext(self.base))
            elif self.format == 'log(exp)':
                a.set_major_formatter(mticker.LogFormatterExponent(self.base))
            elif self.format == 'none':
                a.set_major_formatter(mticker.NullFormatter())
            else:
                a.set_major_formatter(mticker.FormatStrFormatter(self.format))
        except:
            import traceback
            traceback.print_exc()
Пример #13
0
    def check(self, value, incond):
        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 do_check2(value, conds):
            ret = True
            cond = conds.split('|')
            for c in cond:
                ret = ret and do_check(value, c)
            return ret

        if isiterable(incond) and not isinstance(incond, str):
            a = False
            for c in incond:
                a = a or do_check2(value, c)
            return a
        else:
            return do_check(value, incond)