Ejemplo n.º 1
0
 def test_phases(self):
     "Test indices"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator = ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     # Test cold/neutral
     cold = series.cold
     assert_equal(cold._mask,
                  [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
                    0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
                    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,])
     neutral = series.neutral
     assert_equal(neutral._mask,
                  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
                    1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1,
                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
                    1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,])
     warm = series.warm
     assert_equal(warm._mask,
                  [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,])
Ejemplo n.º 2
0
 def test_pickling(self):
     "Tests pickling"
     import cPickle
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     pickled = cPickle.loads(cPickle.dumps(series))
     assert_equal(series, pickled)
     assert_equal(pickled.ensoindicator, pickled.ensoindicator)
     assert_equal(series.ensoindices, pickled.ensoindices)
Ejemplo n.º 3
0
 def test_pickling(self):
     "Tests pickling"
     import cPickle
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator = ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     pickled = cPickle.loads(cPickle.dumps(series))
     assert_equal(series, pickled)
     assert_equal(pickled.ensoindicator, pickled.ensoindicator)
     assert_equal(series.ensoindices, pickled.ensoindices)
Ejemplo n.º 4
0
 def test_creation(self):
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     local_ensoi = series.ensoindicator
     assert_equal(local_ensoi, ensoi)
     assert_equal(local_ensoi.optinfo, ensoi.optinfo)
Ejemplo n.º 5
0
 def test_apply_on_phase(self):
     "Test apply on phase"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     func = ma.mean
     _cold = func(series[(series.ensoindices == -1).filled()])
     _neut = func(series[(series.ensoindices == 0).filled()])
     _warm = func(series[(series.ensoindices == +1).filled()])
     _glob = func(series)
     control = ma.array([(_cold, _neut, _warm, _glob)],
                        dtype=[('cold', float), ('neutral', float),
                               ('warm', float), ('global', float)])
     control['warm'] = masked
     result = apply_on_phase(series, func)
Ejemplo n.º 6
0
 def test_reshape(self):
     "Test reshape"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator = ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     #
     series = series.reshape(1, -1)
     assert_equal(series.ensoindicator.shape, series.shape)
     self.failUnless(series.ensoindicator.shape != ensoi.shape)
     assert_equal(series.ensoindicator, ensoi.reshape(1, -1))
     #
     series.shape = (-1, 1)
     assert_equal(series.ensoindicator.shape, series.shape)
     self.failUnless(series.ensoindicator.shape != ensoi.shape)
     assert_equal(series.ensoindicator, ensoi.reshape(-1, 1))
Ejemplo n.º 7
0
 def test_apply_on_phase(self):
     "Test apply on phase"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator = ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     func = ma.mean
     _cold = func(series[(series.ensoindices==-1).filled()])
     _neut = func(series[(series.ensoindices==0).filled()])
     _warm = func(series[(series.ensoindices==+1).filled()])
     _glob = func(series)
     control = ma.array([(_cold, _neut, _warm, _glob)],
                        dtype=[('cold',float),('neutral',float),
                               ('warm',float),('global',float)])
     control['warm'] = masked
     result = apply_on_phase(series, func)
Ejemplo n.º 8
0
 def test_creation_shifted(self):
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates - 24,
                            ensoindicator=ensoi)
     local_enso = series.ensoindicator
     assert_equal(local_enso._mask, [1] * 24 + [0] * (len(ensoi) - 24))
     assert_equal(local_enso.dates, series.dates)
     assert_equal(local_enso.compressed(), ensoi[:(len(ensoi) - 24)])
     assert_equal(local_enso.optinfo, ensoi.optinfo)
Ejemplo n.º 9
0
 def test_indices(self):
     "Test indices"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator = ensoi)
     # Try without initializiation: it should fail
     try:
         indc = series.ensoindices
     except ValueError:
         pass
     # So, initialize it:
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     indc = series.ensoindices
     assert_equal(indc,
                  [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,
                   -1,-1,-1,-1,-1, 0, 0,-1,-1,-1,-1,-1,
                   -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+1,+1,
                   +1,+1,+1,+1,+1,+1,+1, 0, 0, 0, 0, 0,])
Ejemplo n.º 10
0
 def test_indices_convert(self):
     "Test the conversion of ensoindices from one frequency to another."
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator = ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     control = ts.time_series([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,
                               -1,-1,-1,-1,-1, 0, 0,-1,-1,-1,-1,-1,
                               -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+1,+1,
                               +1,+1,+1,+1,+1,+1,+1, 0, 0, 0, 0, 0,],
                               dates=ensoi.dates)
     assert_equal(series.ensoindices, control)
     # Conversion 'M' to 'D'
     dseries = series.convert('D')
     assert_equal(dseries.ensoindices,
                  ts.lib.backward_fill(control.convert('D')))
     # Conversion 'M' to 'A'
     aseries = series.convert('A', func=ma.mean)
     assert_equal(aseries.ensoindices,
                  mode(control.convert('A'), axis=1)[0].squeeze())
Ejemplo n.º 11
0
 def test_getitem_with_string(self):
     "Test getitem w/ a string"
     ensoi = self.ensoi
     series = ClimateSeries(zip(
         np.random.rand(len(ensoi)),
         np.random.rand(len(ensoi)),
     ),
                            dtype=[('A', float), ('B', float)],
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     # With field
     series_A = series['A']
     assert_equal(series_A.ensoindicator, ensoi)
     assert_equal(series['B'].ensoindicator, ensoi)
     # With date
     series_first = series['1980-01':'1981-01']
     assert_equal(series_first, series[:12])
Ejemplo n.º 12
0
 def test_reshape(self):
     "Test reshape"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     #
     series = series.reshape(1, -1)
     assert_equal(series.ensoindicator.shape, series.shape)
     self.failUnless(series.ensoindicator.shape != ensoi.shape)
     assert_equal(series.ensoindicator, ensoi.reshape(1, -1))
     #
     series.shape = (-1, 1)
     assert_equal(series.ensoindicator.shape, series.shape)
     self.failUnless(series.ensoindicator.shape != ensoi.shape)
     assert_equal(series.ensoindicator, ensoi.reshape(-1, 1))
Ejemplo n.º 13
0
 def test_indices(self):
     "Test indices"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     # Try without initializiation: it should fail
     try:
         indc = series.ensoindices
     except ValueError:
         pass
     # So, initialize it:
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     indc = series.ensoindices
     assert_equal(indc, [
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         -1,
         -1,
         -1,
         -1,
         -1,
         -1,
         -1,
         0,
         0,
         -1,
         -1,
         -1,
         -1,
         -1,
         -1,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         0,
         0,
         0,
         0,
         0,
     ])
Ejemplo n.º 14
0
 def test_phases(self):
     "Test indices"
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     # Test cold/neutral
     cold = series.cold
     assert_equal(cold._mask, [
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         1,
         1,
         0,
         0,
         0,
         0,
         0,
         0,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
     ])
     neutral = series.neutral
     assert_equal(neutral._mask, [
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         0,
         0,
         1,
         1,
         1,
         1,
         1,
         1,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         0,
         0,
         0,
         0,
         0,
     ])
     warm = series.warm
     assert_equal(warm._mask, [
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         1,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         1,
         1,
         1,
         1,
         1,
     ])
Ejemplo n.º 15
0
 def test_indices_convert(self):
     "Test the conversion of ensoindices from one frequency to another."
     ensoi = self.ensoi
     series = ClimateSeries(np.random.rand(len(ensoi)),
                            dates=ensoi._dates,
                            ensoindicator=ensoi)
     series.set_ensoindices(minimum_size=5, reference_season='NDJ')
     control = ts.time_series([
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         -1,
         -1,
         -1,
         -1,
         -1,
         -1,
         -1,
         0,
         0,
         -1,
         -1,
         -1,
         -1,
         -1,
         -1,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         +1,
         0,
         0,
         0,
         0,
         0,
     ],
                              dates=ensoi.dates)
     assert_equal(series.ensoindices, control)
     # Conversion 'M' to 'D'
     dseries = series.convert('D')
     assert_equal(dseries.ensoindices,
                  ts.lib.backward_fill(control.convert('D')))
     # Conversion 'M' to 'A'
     aseries = series.convert('A', func=ma.mean)
     assert_equal(aseries.ensoindices,
                  mode(control.convert('A'), axis=1)[0].squeeze())