Esempio n. 1
0
    def GetData(self, name):
        """Return the data with the name.

        For a 1D dataset, returns a tuple (None if not defined)
            (data, serr, nerr, perr)
        For a 2D dataset, returns
            (data, xrange, yrange)
        For a text dataset, return a list of text
        For a date dataset, return a list of python datetime objects

        Return copies, so that the original data can't be indirectly modified
        """

        d = self.document.getData(name)
        if d.displaytype == 'text':
            return d.data[:]
        elif d.displaytype == 'date':
            return [utils.floatToDateTime(x) for x in d.data]
        elif d.dimensions == 2:
            return (d.data.copy(), d.xrange, d.yrange)
        else:
            data = serr = nerr = perr = None
            if d.data is not None:
                data = d.data.copy()
            if d.serr is not None:
                serr = d.serr.copy()
            if d.nerr is not None:
                nerr = d.nerr.copy()
            if d.perr is not None:
                perr = d.perr.copy()

            return (data, serr, nerr, perr)
Esempio n. 2
0
    def GetData(self, name):
        """Return the data with the name.

        For a 1D dataset, returns a tuple (None if not defined)
            (data, serr, nerr, perr)
        For a 2D dataset, returns
            (data, xrange, yrange)
        For a text dataset, return a list of text
        For a date dataset, return a list of python datetime objects

        Return copies, so that the original data can't be indirectly modified
        """

        d = self.document.getData(name)
        if d.displaytype == 'text':
            return d.data[:]
        elif d.displaytype == 'date':
            return [utils.floatToDateTime(x) for x in d.data]
        elif d.dimensions == 2:
            return (d.data.copy(), d.xrange, d.yrange)
        else:
            data = serr = nerr = perr = None
            if d.data is not None:
                data = d.data.copy()
            if d.serr is not None:
                serr = d.serr.copy()
            if d.nerr is not None:
                nerr = d.nerr.copy()
            if d.perr is not None:
                perr = d.perr.copy()

            return (data, serr, nerr, perr)
Esempio n. 3
0
    def bestTickFinder(self, minval, maxval, numticks, extendbounds,
                       intervals, intervals_sec):
        """Try to find best choice of numticks ticks between minval and maxval
        intervals is an array similar to self.intervals
        intervals_sec is an array similar to self.intervals_sec

        Returns a tuple (minval, maxval, estimatedsize, ticks, textformat)"""

        delta = maxval - minval

        # iterate over different intervals and find one closest to what we want
        estimated = delta / intervals_sec

        tick1 = max(estimated.searchsorted(numticks)-1, 0)
        tick2 = min(tick1+1, len(estimated)-1)

        del1 = abs(estimated[tick1] - numticks)
        del2 = abs(estimated[tick2] - numticks)

        if del1 < del2:
            best = tick1
        else:
            best = tick2
        besttt, format = intervals[best]

        mindate = utils.floatToDateTime(minval)
        maxdate = utils.floatToDateTime(maxval)

        # round min and max to nearest
        minround = utils.tupleToDateTime(utils.roundDownToTimeTuple(mindate, besttt))
        maxround = utils.tupleToDateTime(utils.roundDownToTimeTuple(maxdate, besttt))

        if minround == mindate:
            mintick = minround
        else:
            # rounded down, so move on to next tick
            mintick = utils.addTimeTupleToDateTime(minround, besttt)
        maxtick = maxround

        # extend bounds if requested
        deltamin = utils.datetimeToFloat(mindate)-utils.datetimeToFloat(mintick)
        if extendbounds and (deltamin != 0. and deltamin < delta*0.15):
            mindate = utils.addTimeTupleToDateTime(minround,
                                                   [-x for x in besttt])
            mintick = mindate
        deltamax = utils.datetimeToFloat(maxdate)-utils.datetimeToFloat(maxtick)
        if extendbounds and (deltamax != 0. and deltamax < delta*0.15):
            maxdate = utils.addTimeTupleToDateTime(maxtick, besttt)
            maxtick = maxdate

        # make ticks
        ticks = []
        dt = mintick
        while dt <= maxtick:
            ticks.append( utils.datetimeToFloat(dt))
            dt = utils.addTimeTupleToDateTime(dt, besttt)

        return ( utils.datetimeToFloat(mindate),
                 utils.datetimeToFloat(maxdate),
                 intervals_sec[best],
                 N.array(ticks), format )
Esempio n. 4
0
    def bestTickFinder(self, minval, maxval, numticks, extendmin, extendmax,
                       intervals, intervals_sec):
        """Try to find best choice of numticks ticks between minval and maxval
        intervals is an array similar to self.intervals
        intervals_sec is an array similar to self.intervals_sec

        Returns a tuple (minval, maxval, estimatedsize, ticks, textformat)"""

        delta = maxval - minval

        # iterate over different intervals and find one closest to what we want
        estimated = delta / intervals_sec

        tick1 = max(estimated.searchsorted(numticks) - 1, 0)
        tick2 = min(tick1 + 1, len(estimated) - 1)

        del1 = abs(estimated[tick1] - numticks)
        del2 = abs(estimated[tick2] - numticks)

        if del1 < del2:
            best = tick1
        else:
            best = tick2
        besttt, format = intervals[best]

        mindate = utils.floatToDateTime(minval)
        maxdate = utils.floatToDateTime(maxval)

        # round min and max to nearest
        minround = utils.tupleToDateTime(
            utils.roundDownToTimeTuple(mindate, besttt))
        maxround = utils.tupleToDateTime(
            utils.roundDownToTimeTuple(maxdate, besttt))

        if minround == mindate:
            mintick = minround
        else:
            # rounded down, so move on to next tick
            mintick = utils.addTimeTupleToDateTime(minround, besttt)
        maxtick = maxround

        # extend bounds if requested
        deltamin = utils.datetimeToFloat(mindate) - utils.datetimeToFloat(
            mintick)
        if extendmin and (deltamin != 0. and deltamin < delta * 0.15):
            mindate = utils.addTimeTupleToDateTime(minround,
                                                   [-x for x in besttt])
            mintick = mindate
        deltamax = utils.datetimeToFloat(maxdate) - utils.datetimeToFloat(
            maxtick)
        if extendmax and (deltamax != 0. and deltamax < delta * 0.15):
            maxdate = utils.addTimeTupleToDateTime(maxtick, besttt)
            maxtick = maxdate

        # make ticks
        ticks = []
        dt = mintick
        while dt <= maxtick:
            ticks.append(utils.datetimeToFloat(dt))
            dt = utils.addTimeTupleToDateTime(dt, besttt)

        return (utils.datetimeToFloat(mindate), utils.datetimeToFloat(maxdate),
                intervals_sec[best], N.array(ticks), format)