Пример #1
0
    def recache(self):
        #if self.axes is None: print 'recache no axes'
        #else: print 'recache units', self.axes.xaxis.units, self.axes.yaxis.units
        x = ma.asarray(self.convert_xunits(self._xorig), float)
        y = ma.asarray(self.convert_yunits(self._yorig), float)

        x = ma.ravel(x)
        y = ma.ravel(y)
        if len(x)==1 and len(y)>1:
            x = x * npy.ones(y.shape, float)
        if len(y)==1 and len(x)>1:
            y = y * npy.ones(x.shape, float)

        if len(x) != len(y):
            raise RuntimeError('xdata and ydata must be the same length')

        mx = ma.getmask(x)
        my = ma.getmask(y)
        mask = ma.mask_or(mx, my)
        if mask is not ma.nomask:
            x = ma.masked_array(x, mask=mask).compressed()
            y = ma.masked_array(y, mask=mask).compressed()
            self._segments = unmasked_index_ranges(mask)
        else:
            self._segments = None

        self._x = npy.asarray(x, float)
        self._y = npy.asarray(y, float)

        self._logcache = None
Пример #2
0
    def _update_x_y_logcache(self):
        # check cache
        need_update = False
        try:
            for key, var_id in self._cache_inputs.iteritems():
                if id(getattr(self, key)) != var_id:
                    need_update = True
                    break
        except:
            need_update = True

        if not need_update:
            return

        # update cache
        for key in self._cache_inputs.keys():
            try:
                self._cache_inputs[key] = id(getattr(self, key))
            except:
                pass

        # make sure that result values exist and release
        # previous values
        self._cached__x = None
        self._cached__y = None
        self._cached__segments = None
        self._cached__logcache = None

        if self.is_unitsmgr_set():
            unitsmgr = self.get_unitsmgr()
            x, y = unitsmgr._convert_units((self._x_orig, self._xunits), (self._y_orig, self._yunits))
        else:
            x, y = (self._x_orig, self._y_orig)

        x = ma.ravel(x)
        y = ma.ravel(y)
        if len(x) == 1 and len(y) > 1:
            x = x * ones(y.shape, Float)
        if len(y) == 1 and len(x) > 1:
            y = y * ones(x.shape, Float)

        if len(x) != len(y):
            raise RuntimeError("xdata and ydata must be the same length")

        mx = ma.getmask(x)
        my = ma.getmask(y)
        mask = ma.mask_or(mx, my)
        if mask is not ma.nomask:
            x = ma.masked_array(x, mask=mask).compressed()
            y = ma.masked_array(y, mask=mask).compressed()
            self._cached__segments = unmasked_index_ranges(mask)
        else:
            self._cached__segments = None

        self._cached__x = asarray(x, Float)
        self._cached__y = asarray(y, Float)

        self._cached__logcache = None
Пример #3
0
    def set_data(self, *args):
        """
        Set the x and y data

        ACCEPTS: (array xdata, array ydata)
        """

        if len(args) == 1:
            x, y = args[0]
        else:
            x, y = args

        try:
            del self._xc, self._yc
        except AttributeError:
            pass

        self._masked_x = None
        self._masked_y = None
        mx = ma.getmask(x)
        my = ma.getmask(y)
        if mx is not None:
            mx = ravel(mx)
            self._masked_x = x
        if my is not None:
            my = ravel(my)
            self._masked_y = y
        mask = ma.mask_or(mx, my)
        if mask is not None:
            x = ma.masked_array(ma.ravel(x), mask=mask).compressed()
            y = ma.masked_array(ma.ravel(y), mask=mask).compressed()
            self._segments = unmasked_index_ranges(mask)
        else:
            self._segments = None

        self._x = asarray(x, Float)
        self._y = asarray(y, Float)

        if len(self._x.shape) > 1:
            self._x = ravel(self._x)
        if len(self._y.shape) > 1:
            self._y = ravel(self._y)

        # What is the rationale for the following two lines?
        # And why is there not a similar pair with _x and _y reversed?
        if len(self._y) == 1 and len(self._x) > 1:
            self._y = self._y * ones(self._x.shape, Float)

        if len(self._x) != len(self._y):
            raise RuntimeError("xdata and ydata must be the same length")

        if self._useDataClipping:
            self._xsorted = self._is_sorted(self._x)

        self._logcache = None
Пример #4
0
    def set_data(self, *args):
        """
        Set the x and y data

        ACCEPTS: (array xdata, array ydata)
        """

        if len(args)==1:
            x, y = args[0]
        else:
            x, y = args

        self._x_orig = x
        self._y_orig = y

        if (self._xunits and hasattr(x, 'convert_to')):
            x = x.convert_to(self._xunits).get_value()
        if (hasattr(x, 'get_value')):
            x = x.get_value()
        if (self._yunits and hasattr(y, 'convert_to')):
            y = y.convert_to(self._yunits).get_value()
        if (hasattr(y, 'get_value')):
            y = y.get_value()

        x = ma.ravel(x)
        y = ma.ravel(y)
        if len(x)==1 and len(y)>1:
            x = x * ones(y.shape, Float)
        if len(y)==1 and len(x)>1:
            y = y * ones(x.shape, Float)

        if len(x) != len(y):
            raise RuntimeError('xdata and ydata must be the same length')

        mx = ma.getmask(x)
        my = ma.getmask(y)
        mask = ma.mask_or(mx, my)
        if mask is not ma.nomask:
            x = ma.masked_array(x, mask=mask).compressed()
            y = ma.masked_array(y, mask=mask).compressed()
            self._segments = unmasked_index_ranges(mask)
        else:
            self._segments = None

        self._x = asarray(x, Float)
        self._y = asarray(y, Float)

        self._logcache = None
Пример #5
0
    def set_data(self, *args):
        """
        Set the x and y data

        ACCEPTS: (array xdata, array ydata)
        """

        if len(args) == 1:
            x, y = args[0]
        else:
            x, y = args

        try:
            del self._xc, self._yc
        except AttributeError:
            pass

        self._x_orig = x
        self._y_orig = y

        x = ma.ravel(x)
        y = ma.ravel(y)
        if len(x) == 1 and len(y) > 1:
            x = x * ones(y.shape, Float)
        if len(y) == 1 and len(x) > 1:
            y = y * ones(x.shape, Float)

        if len(x) != len(y):
            raise RuntimeError("xdata and ydata must be the same length")

        mx = ma.getmask(x)
        my = ma.getmask(y)
        mask = ma.mask_or(mx, my)
        if mask is not None:
            x = ma.masked_array(x, mask=mask).compressed()
            y = ma.masked_array(y, mask=mask).compressed()
            self._segments = unmasked_index_ranges(mask)
        else:
            self._segments = None

        self._x = asarray(x, Float)
        self._y = asarray(y, Float)

        if self._useDataClipping:
            self._xsorted = self._is_sorted(self._x)

        self._logcache = None
Пример #6
0
    def set_data(self, *args):
        """
        Set the x and y data

        ACCEPTS: (array xdata, array ydata)
        """

        if len(args) == 1:
            x, y = args[0]
        else:
            x, y = args

        try:
            del self._xc, self._yc
        except AttributeError:
            pass

        self._x_orig = x
        self._y_orig = y

        x = ma.ravel(x)
        y = ma.ravel(y)
        if len(x) == 1 and len(y) > 1:
            x = x * ones(y.shape, Float)
        if len(y) == 1 and len(x) > 1:
            y = y * ones(x.shape, Float)

        if len(x) != len(y):
            raise RuntimeError('xdata and ydata must be the same length')

        mx = ma.getmask(x)
        my = ma.getmask(y)
        mask = ma.mask_or(mx, my)
        if mask is not None:
            x = ma.masked_array(x, mask=mask).compressed()
            y = ma.masked_array(y, mask=mask).compressed()
            self._segments = unmasked_index_ranges(mask)
        else:
            self._segments = None

        self._x = asarray(x, Float)
        self._y = asarray(y, Float)

        if self._useDataClipping: self._xsorted = self._is_sorted(self._x)

        self._logcache = None
Пример #7
0
    def _autolev(self, z, N, filled, badmask):
        '''
        Select contour levels to span the data.

        We need one more level for filled contours than for
        line contours, because for the latter we need to specify
        the lower and upper boundary of each range. For example,
        a single contour boundary, say at z = 0, requires only
        one contour line, but two filled regions, and therefore
        two levels.  These are taken as the lower boundaries of
        the regions.
        '''
        rz = ma.masked_array(z, badmask)
        zmax = ma.maximum(rz)  # was: zmax = amax(rz)
        zmin = ma.minimum(rz)
        if filled:
            lev = linspace(zmin, zmax, N + 2)[:-1]
        else:
            lev = linspace(zmin, zmax, N + 2)[1:-1]
        return lev
Пример #8
0
    def _autolev(self, z, N, filled, badmask):
        '''
        Select contour levels to span the data.

        We need one more level for filled contours than for
        line contours, because for the latter we need to specify
        the lower and upper boundary of each range. For example,
        a single contour boundary, say at z = 0, requires only
        one contour line, but two filled regions, and therefore
        two levels.  These are taken as the lower boundaries of
        the regions.
        '''
        rz = ma.masked_array(z, badmask)
        zmax = ma.maximum(rz)     # was: zmax = amax(rz)
        zmin = ma.minimum(rz)
        if filled:
            lev = linspace(zmin, zmax, N+2)[:-1]
        else:
            lev = linspace(zmin, zmax, N+2)[1:-1]
        return lev