Exemplo n.º 1
0
    def SetDataDateTime(self, name, vals):
        """Set datetime dataset to be values given.
        vals is a list of python datetime objects
        """
        v = [utils.datetimeToFloat(x) for x in vals]
        ds = datasets.DatasetDateTime(v)
        op = operations.OperationDatasetSet(name, ds)
        self.document.applyOperation(op)

        if self.verbose:
            print "Set dataset '%s':" % name
            print " Values = %s" % str(ds.data)
Exemplo n.º 2
0
    def SetDataDateTime(self, name, vals):
        """Set datetime dataset to be values given.
        vals is a list of python datetime objects
        """
        v = [utils.datetimeToFloat(x) for x in vals]
        ds = datasets.DatasetDateTime(v)
        op = operations.OperationDatasetSet(name, ds)
        self.document.applyOperation(op)

        if self.verbose:
            print "Set dataset '%s':" % name
            print " Values = %s" % str(ds.data)
Exemplo 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 )
Exemplo 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)