示例#1
0
  def nticks(self, vmin, vmax, mult=None):
  # {{{
    if mult is None: mult = self.mult
    d1 = self.get_tick_prior(vmin)
    d2 = self.get_tick_prior(vmax)

    return tu.date_diff(self._taxis, d1, d2, units='minutes') / mult
示例#2
0
  def get_tick_prior(self, val):
  # {{{
    ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''

    def unpack(dt): return dt.get('year', 1), dt.get('month', 1), dt.get('day', 1), dt.get('hour', 0), dt.get('minute', 0), dt.get('second', 0)
    def pack(yr, mn, dy, hr, mi, sc): return {'year':yr, 'month':mn, 'day':dy, 'hour':hr, 'minute':mi, 'second':sc}

    dt = self._taxis.val_as_date(val, allfields=True)
    yr, mn, dy, hr, mi, sc = unpack(dt)

    if val > self._taxis.date_as_val(pack(yr, mn, dy, hr, mi, sc)): 
      yr, mn, dy, hr, mi, sc = unpack(tu.wrapdate(self._taxis, pack(yr, mn, dy, hr, mi, sc+1), allfields=True))

    # Find first hour on given multiple prior to the given hour
    from numpy import floor_divide
    sc = floor_divide(sc - 1, self.mult) * self.mult

    # If we've wrapped, decrement the year
    d = tu.wrapdate(self._taxis, pack(yr, mn, dy, hr, mi, sc), allfields=True)
    d1 = tu.wrapdate(self._taxis, pack(yr, mn, dy, hr, mi+1, 0), allfields=True)

    if tu.date_diff(self._taxis, d, d1, 'seconds') < self.mult / 2:
      return d1
    else:
      return d
示例#3
0
  def get_tick_prior(self, val):
  # {{{
    ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''

    def unpack(dt): return dt.get('year', 1), dt.get('month', 1), dt.get('day', 1)

    dt = self._taxis.val_as_date(val, allfields=True)
    yr, mn, dy = unpack(dt)

    if val > self._taxis.date_as_val({'year':yr, 'month':mn, 'day':dy}): 
      yr, mn, dy = unpack(tu.wrapdate(self._taxis, {'year':yr, 'month':mn, 'day':dy+1}, allfields=True))

    # Find first day on given multiple prior to the given day
    from numpy import floor_divide
    dy = floor_divide(dy - 2, self.mult) * self.mult + 1

    # If we've wrapped, decrement the year
    d = tu.wrapdate(self._taxis, {'year':yr, 'month':mn, 'day':dy}, allfields=True)
    d1 = tu.wrapdate(self._taxis, {'year':yr, 'month':mn + 1, 'day':1}, allfields=True)

    if tu.date_diff(self._taxis, d, d1, 'days') < self.mult / 2:
      return d1
    else:
      return d
示例#4
0
    def nticks(self, vmin, vmax, mult=None):
        # {{{
        if mult is None: mult = self.mult
        d1 = self.get_tick_prior(vmin)
        d2 = self.get_tick_prior(vmax)

        return tu.date_diff(self._taxis, d1, d2, units='minutes') / mult
示例#5
0
    def get_tick_prior(self, val):
        # {{{
        ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''
        def unpack(dt):
            return dt.get('year', 1), dt.get('month',
                                             1), dt.get('day',
                                                        1), dt.get('hour', 0)

        def pack(yr, mn, dy, hr):
            return {'year': yr, 'month': mn, 'day': dy, 'hour': hr}

        dt = self._taxis.val_as_date(val, allfields=True)
        yr, mn, dy, hr = unpack(dt)

        if val > self._taxis.date_as_val(pack(yr, mn, dy, hr)):
            yr, mn, dy, hr = unpack(
                tu.wrapdate(self._taxis,
                            pack(yr, mn, dy, hr + 1),
                            allfields=True))

        # Find first hour on given multiple prior to the given hour
        from numpy import floor_divide
        hr = floor_divide(hr - 1, self.mult) * self.mult

        # If we've wrapped, decrement the year
        d = tu.wrapdate(self._taxis, pack(yr, mn, dy, hr), allfields=True)
        d1 = tu.wrapdate(self._taxis, pack(yr, mn, dy + 1, 0), allfields=True)

        if tu.date_diff(self._taxis, d, d1, 'hours') < self.mult / 2:
            return d1
        else:
            return d
示例#6
0
 def next_tick(self, val):
 # {{{
   d = self._taxis.val_as_date(val, allfields=True)
   d1 = d.copy()
   d['second'] += self.mult
   d1['minute'] += 1; d1['second'] = 0
   if tu.date_diff(self._taxis, d, d1, 'seconds') < self.mult / 2:
     return self._taxis.date_as_val(d1)
   else:
     return self._taxis.date_as_val(d)
示例#7
0
 def next_tick(self, val):
 # {{{
   d = self._taxis.val_as_date(val, allfields=True)
   d1 = d.copy()
   d['day'] += self.mult
   d1['month'] += 1; d1['day'] = 1
   if tu.date_diff(self._taxis, d, d1, 'days') < self.mult / 2.:
     return self._taxis.date_as_val(d1)
   else:
     return self._taxis.date_as_val(d)
示例#8
0
 def next_tick(self, val):
     # {{{
     d = self._taxis.val_as_date(val, allfields=True)
     d1 = d.copy()
     d['second'] += self.mult
     d1['minute'] += 1
     d1['second'] = 0
     if tu.date_diff(self._taxis, d, d1, 'seconds') < self.mult / 2:
         return self._taxis.date_as_val(d1)
     else:
         return self._taxis.date_as_val(d)
示例#9
0
 def next_tick(self, val):
     # {{{
     d = self._taxis.val_as_date(val, allfields=True)
     d1 = d.copy()
     d['day'] += self.mult
     d1['month'] += 1
     d1['day'] = [1]
     if tu.date_diff(self._taxis, d, d1, 'days') < self.mult / 2.:
         return self._taxis.date_as_val(d1)
     else:
         return self._taxis.date_as_val(d)
示例#10
0
    def get_tick_prior(self, val):
        # {{{
        ''' get_tick_prior(val) - returns the date of the first tick prior to the
    date represented by val. If a tick lies on val, it returns the date of the
    previous tick.'''
        def unpack(dt):
            return dt.get('year', 1), dt.get('month', 1), dt.get('day', 1)

        dt = self._taxis.val_as_date(val, allfields=True)
        yr, mn, dy = unpack(dt)

        if val > self._taxis.date_as_val({'year': yr, 'month': mn, 'day': dy}):
            yr, mn, dy = unpack(
                tu.wrapdate(self._taxis, {
                    'year': yr,
                    'month': mn,
                    'day': dy + 1
                },
                            allfields=True))

        # Find first day on given multiple prior to the given day
        from numpy import floor_divide
        dy = floor_divide(dy - 2, self.mult) * self.mult + 1

        # If we've wrapped, decrement the year
        d = tu.wrapdate(self._taxis, {
            'year': yr,
            'month': mn,
            'day': dy
        },
                        allfields=True)
        d1 = tu.wrapdate(self._taxis, {
            'year': yr,
            'month': mn + 1,
            'day': 1
        },
                         allfields=True)

        if tu.date_diff(self._taxis, d, d1, 'days') < self.mult / 2:
            return d1
        else:
            return d
示例#11
0
 def date_diff(self, dt1, dt2, units = None):
   from pygeode import timeutils
   from warnings import warn
   warn ("Deprecated.  Use timeutils module.")
   return timeutils.date_diff(self, dt1, dt2, units)
示例#12
0
 def date_diff(self, dt1, dt2, units = None):
   from pygeode import timeutils
   from warnings import warn
   warn ("Deprecated.  Use timeutils module.")
   return timeutils.date_diff(self, dt1, dt2, units)