Пример #1
0
 def test_error_01(self):
     """Concat error test."""
     obs1 = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42))
     self.assertRaises(TypeError, obshydro.Observations.concat,
                       *(obs1, '33'))
Пример #2
0
 def test_base_01(self):
     """Simple test."""
     # The simpliest __init_: datetime and res
     obs = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42))
     self.assertEqual(obs['res'].tolist(), [33, 37, 42])
Пример #3
0
 def test_str_02(self):
     """Test __str__ method with a small Observations."""
     s = sitehydro.Stationhydro(code='A044581001')
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33),
                               obshydro.Observation('2012-10-03 08:00', 42))
     serie = obshydro.Serie(entite=s, grandeur='Q', observations=o)
     self.assertTrue(serie.__str__().rfind('Serie') > -1)
     self.assertTrue(serie.__str__().rfind('Statut') > -1)
     self.assertTrue(serie.__str__().rfind('Observations') > -1)
Пример #4
0
 def test_base_02(self):
     """Serie on a station with no statut."""
     s = sitehydro.Stationhydro(code='A044581001')
     g = 'Q'
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33),
                               obshydro.Observation('2012-10-03 08:00', 42))
     serie = obshydro.Serie(entite=s, grandeur=g, observations=o)
     self.assertEqual((serie.entite, serie.grandeur, serie.statut,
                       serie.observations, serie._strict),
                      (s, g, 0, o, True))
Пример #5
0
 def test_base_01(self):
     """Concat base test."""
     obs1 = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42))
     obs2 = obshydro.Observations(
         obshydro.Observation('2014-10-03 06:00', 330),
         obshydro.Observation('2014-10-03 07:00', 370),
         obshydro.Observation('2014-10-03 08:00', 420))
     expected = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00', 33),
         obshydro.Observation('2012-10-03 07:00', 37),
         obshydro.Observation('2012-10-03 08:00', 42),
         obshydro.Observation('2014-10-03 06:00', 330),
         obshydro.Observation('2014-10-03 07:00', 370),
         obshydro.Observation('2014-10-03 08:00', 420))
     concat = obshydro.Observations.concat(obs1, obs2)
     self.assertTrue(numpy.array_equal(concat, expected))
Пример #6
0
 def test_error_01(self):
     """Entite error."""
     s = sitehydro.Stationhydro(code='A044581001', strict=False)
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33))
     obshydro.Serie(**{'entite': s, 'grandeur': 'H', 'observations': o})
     self.assertRaises(
         TypeError, obshydro.Serie, **{
             'entite': 'X',
             'grandeur': 'H',
             'observations': o
         })
Пример #7
0
 def test_str_03(self):
     """Test __str__ method with a big Observations."""
     s = sitehydro.Stationhydro(code='A044581001', libelle='Toulouse')
     o = obshydro.Observations(*[
         obshydro.Observation('20%i-01-01 00:00' % x, x)
         for x in xrange(10, 50)
     ])
     serie = obshydro.Serie(entite=s, grandeur='H', observations=o)
     self.assertTrue(serie.__str__().rfind('Serie') > -1)
     self.assertTrue(serie.__str__().rfind('Statut') > -1)
     self.assertTrue(serie.__str__().rfind('Observations') > -1)
Пример #8
0
 def test_error_01(self):
     """List of observation error."""
     # check that init works when call regurlaly...
     o = obshydro.Observation('2012-10-03 06:00',
                              33,
                              mth=4,
                              qal=0,
                              cnt=True)
     obshydro.Observations(*[o, o])
     # ...and fails otherwise
     self.assertRaises(
         TypeError,
         obshydro.Observations,
         # *[o, o]  # is good !
         *[o, 33]  # is wrong !!
     )
Пример #9
0
 def test_base_01(self):
     """Serie on a site."""
     s = sitehydro.Sitehydro(code='A0445810',
                             libelle='Le Rhône à Marseille')
     g = 'Q'
     t = 16
     o = obshydro.Observations(obshydro.Observation('2012-10-03 06:00', 33),
                               obshydro.Observation('2012-10-03 07:00', 37),
                               obshydro.Observation('2012-10-03 08:00', 42))
     i = True
     serie = obshydro.Serie(entite=s,
                            grandeur=g,
                            statut=t,
                            observations=o,
                            strict=i)
     self.assertEqual((serie.entite, serie.grandeur, serie.statut,
                       serie.observations, serie._strict), (s, g, t, o, i))
Пример #10
0
 def test_base_02(self):
     """Base case test."""
     # Datetime, res and others attributes
     obs = obshydro.Observations(
         obshydro.Observation('2012-10-03 06:00',
                              33,
                              mth=4,
                              qal=0,
                              cnt=True),
         obshydro.Observation('2012-10-03 07:00',
                              37,
                              mth=0,
                              qal=12,
                              cnt=False),
         obshydro.Observation('2012-10-03 08:00',
                              42,
                              mth=12,
                              qal=20,
                              cnt=True))
     self.assertEqual(obs['mth'].tolist(), [4, 0, 12])
     self.assertEqual(obs['qal'].tolist(), [0, 12, 20])
     self.assertEqual(obs['cnt'].tolist(), [True, False, True])
Пример #11
0
def _observations_from_element(element):
    """Return a obshydro.Observations from a <ObssHydro> element."""
    if element is not None:

        # prepare a list of Observation
        observations = []
        for o in element:
            args = {}
            args['dte'] = _value(o, 'DtObsHydro', _UTC)
            args['res'] = _value(o, 'ResObsHydro')
            mth = _value(o, 'MethObsHydro', int)
            if mth is not None:
                args['mth'] = mth
            qal = _value(o, 'QualifObsHydro', int)
            if qal is not None:
                args['qal'] = qal
            # we can't use bool injection here because bool('False') is True
            cnt = _value(o, 'ContObsHydro')
            if cnt is not None:
                args['cnt'] = True if (cnt == 'True') else False
            observations.append(_obshydro.Observation(**args))

        # build Observations
        return _obshydro.Observations(*observations)