コード例 #1
0
    def test_backward_fill (self):
        result = masked_array(self.data, mask=self.mask)
        result[0] = 1
        result[2] = 3

        assert_equal(backward_fill(self.test_array, maxgap=1), result)

        result[5] = 7
        result[6] = 7

        assert_equal(backward_fill(self.test_array), result)
コード例 #2
0
    def test_backward_fill(self):
        result = masked_array(self.data, mask=self.mask)
        result[0] = 1
        result[2] = 3

        assert_equal(backward_fill(self.test_array, maxgap=1), result)

        result[5] = 7
        result[6] = 7

        assert_equal(backward_fill(self.test_array), result)
コード例 #3
0
 def _fix_cachedcurrent(self, ensoindices):
     """
 Private function to convert cached ENSO indices.
 This function is used to ensure that:
 * the frequency of the indices matches the frequency of the indicator.
 * the date range of the indices matches the date range of the indicator.
 * the shape of the indices matches the shape of the indicator.
     """
     _currentfreq = ensoindices._dates.freq
     _freq = self._dates.freq
     # Check the frequency, and convert if needed
     if _currentfreq > _freq:
         # To a lower frequency ('Q'/'A')
         if self.ndim == 2:
             conversionfunc = None
         else:
             conversionfunc = lambda x: mode(x)[0].squeeze()
         ensoindices = ensoindices.convert(_freq, func=conversionfunc)
     elif _currentfreq < _freq:
         # To a higher frequency (eg, 'D')
         ensoindices = backward_fill(ensoindices.convert(_freq))
     # Reset to the original frequency if needed...
     (start, end) = self._dates.flat[[0, -1]]
     if tuple(ensoindices._dates.flat[[0, -1]]) != (start, end):
         ensoindices = ts.adjust_endpoints(ensoindices, start_date=start, end_date=end)
     # Reset the shape of the indices
     if ensoindices.shape != self.shape:
         ensoindices.shape = self.shape
     return ensoindices
コード例 #4
0
 def set_ensoindicator(self, indicator):
     if indicator is not None:
         if not isinstance(indicator, ENSOIndicator):
             raise TypeError("The input is not a valid ENSOIndicator ! " "(got '%s' instead)" % type(indicator))
         # Reset the frequency
         (sfreq, ifreq) = (self._dates.freq, indicator.freq)
         if ifreq != sfreq:
             if sfreq < ifreq:
                 indicator = indicator.convert(sfreq, func=ma.mean)
             elif sfreq > ifreq:
                 indicator = backward_fill(indicator.convert(sfreq))
         # Set the ENSO indices to the default (if we don't have any...)
         if indicator._cachedcurrent is None:
             indicator.set_indices()
         # Reset the dates
         dates = self._dates
         if dates.isfull():
             if len(dates) > 0:
                 (start, end) = dates.flat[[0, -1]]
                 if tuple(indicator._dates.flat[[0, -1]]) != (start, end):
                     indicator = ts.adjust_endpoints(indicator, start, end)
             else:
                 indicator = None
         else:
             indicator = indicator[self._dates]
     self._optinfo["ensoindicator"] = indicator
コード例 #5
0
 def _fix_cachedcurrent(self, ensoindices):
     """
 Private function to convert cached ENSO indices.
 This function is used to ensure that:
 * the frequency of the indices matches the frequency of the indicator.
 * the date range of the indices matches the date range of the indicator.
 * the shape of the indices matches the shape of the indicator.
     """
     _currentfreq = ensoindices._dates.freq
     _freq = self._dates.freq
     # Check the frequency, and convert if needed
     if _currentfreq > _freq:
         # To a lower frequency ('Q'/'A')
         if self.ndim == 2:
             conversionfunc = None
         else:
             conversionfunc = lambda x: mode(x)[0].squeeze()
         ensoindices = ensoindices.convert(_freq, func=conversionfunc)
     elif _currentfreq < _freq:
         # To a higher frequency (eg, 'D')
         ensoindices = backward_fill(ensoindices.convert(_freq))
     # Reset to the original frequency if needed...
     (start, end) = self._dates.flat[[0, -1]]
     if tuple(ensoindices._dates.flat[[0, -1]]) != (start, end):
         ensoindices = ts.adjust_endpoints(ensoindices,
                                           start_date=start, end_date=end)
     # Reset the shape of the indices
     if ensoindices.shape != self.shape:
         ensoindices.shape = self.shape
     return ensoindices
コード例 #6
0
 def set_ensoindicator(self, indicator):
     if indicator is not None:
         if not isinstance(indicator, ENSOIndicator):
             raise TypeError("The input is not a valid ENSOIndicator ! "\
                             "(got '%s' instead)" % type(indicator))
         # Reset the frequency
         (sfreq, ifreq) = (self._dates.freq, indicator.freq)
         if ifreq != sfreq:
             if sfreq < ifreq:
                 indicator = indicator.convert(sfreq, func=ma.mean)
             elif sfreq > ifreq:
                 indicator = backward_fill(indicator.convert(sfreq))
         # Set the ENSO indices to the default (if we don't have any...)
         if indicator._cachedcurrent is None:
             indicator.set_indices()
         # Reset the dates
         dates = self._dates
         if dates.isfull():
             if len(dates) > 0:
                 (start, end) = dates.flat[[0, -1]]
                 if tuple(indicator._dates.flat[[0, -1]]) != (start, end):
                     indicator = ts.adjust_endpoints(indicator, start, end)
             else:
                 indicator = None
         else:
             indicator = indicator[self._dates]
     self._optinfo['ensoindicator'] = indicator
コード例 #7
0
ファイル: utility_usage.py プロジェクト: jedfrechette/JDFlib
        ELECTRIC = time_series(masked_less(data[:, 0], 0), dates)
        GAS = time_series(masked_less(data[:, 1], 0), dates)
        WATER = time_series(masked_less(data[:, 2], 0), dates)
        START = dates[0]
        END = dates[-1]
        CLIMATE = get_nm_climate(
            start_date='%i%.2i%.2i' % (START.year, START.month, START.day),
            end_date='%i%.2i%.2i' % (END.year, END.month, END.day))
        CLIMATE.tofile('/tmp/test.txt')
        MAX_TEMP, MIN_TEMP, ACCUM_PRECIP = CLIMATE.split()

        FIG = tpl.tsfigure(figsize=(10, 7))
        FIG.subplots_adjust(hspace=0.1)

        GAS_PLOT = FIG.add_tsplot(313)
        GAS_PLOT.tsplot(backward_fill(GAS), zorder=20)
        GAS_PLOT.set_ylabel('Gas usage, therms')
        GAS_PLOT.grid(linestyle='-', color='0.9', zorder=0)
        TEMP_PLOT = GAS_PLOT.add_yaxis(position='right')
        TEMP_PLOT.tsplot(MIN_TEMP, color='0.5', zorder=10)
        TEMP_PLOT.tsplot(MAX_TEMP, color='0.5', zorder=10)
        TEMP_PLOT.set_ylabel(u'Temperature range, \u2109F')

        WATER_PLOT = FIG.add_tsplot(311, sharex=GAS_PLOT)
        WATER_PLOT.tsplot(backward_fill(WATER * 748), zorder=20)
        WATER_PLOT.grid(linestyle='-', color='0.9', zorder=1)
        WATER_PLOT.set_xticklabels(WATER_PLOT.get_xticklabels(), visible=False)
        WATER_PLOT.set_ylabel('Water usage, gal.')
        WATER_PLOT.set_title('Utility usage for 1613 Columbia Dr. SE, ' \
                             'Albuquerque, NM\n' \
                             'Usage is given per billing period (~30 days).\n' \