Ejemplo n.º 1
0
    def test_parse_domain(self):

        tests = [('10N,10S,10E,20E', {'N': 10., 'S':-10.,
                                      'W': 10., 'E': 20.}),
                 ('10S,10N,20E,10E', {'N': 10., 'S':-10.,
                                      'W': 10., 'E': 20.}),
                 ('10N,10S,10W,20E', {'N': 10., 'S':-10.,
                                      'W':-10, 'E': 20.}),
                 ('10N,20N,10W,20E', {'N': 20., 'S': 10.,
                                      'W':-10, 'E': 20.}),
                 ('10N,20N,170W,170E', {'N': 20., 'S': 10.,
                                        'W': 170., 'E':-170.}),
                 ('10N,20N,170E,170W', {'N': 20., 'S': 10.,
                                        'W': 170., 'E':-170.}),
                 ('10N,20N,190E,170E', {'N': 20., 'S': 10.,
                                        'W': 170., 'E':-170.})
                 ]

        for domain_str, expected in tests:
            actual = utils.parse_domain(domain_str)
            self.assertEqual(expected, actual)

        bad_queries = ['100N,10S,10E,20E',
                       '10#,10S,10E,20E',
                       '10E,10S,10E,20E',
                       '10N,10S,10N,20E',
                       '10N,10E',
                       '10N,10S,10E,400E',
                       '10N,10,10E,20E']

        for bad in bad_queries:
            self.assertRaises(utils.BadQuery,
                              lambda: utils.parse_domain(bad))
Ejemplo n.º 2
0
    def test_parse_gridded_request(self):

        tests = [('GFS:14S,20S,154W,146W|0.5,0.5|0,3..120|WIND',
                  {'domain': utils.parse_domain('14S,20S,154W,146W'),
                   'model': 'gfs',
                   'type': 'gridded',
                   'resolution': 0.5,
                   'hours': list(np.arange(41.) * 3),
                   'variables': ['wind'],
                   }),
                 ('GFS:14S,20S,154W,146W|0.5,0.5|0,3..120',
                  {'domain': utils.parse_domain('14S,20S,154W,146W'),
                   'model': 'gfs',
                   'type': 'gridded',
                   'resolution': 0.5,
                   'hours': list(np.arange(41.) * 3),
                   'variables': ['wind']
                   }),
                 (u'GFS:14S,20S,154W,146W\u015a0.5,0.5',
                  {'domain': utils.parse_domain('14S,20S,154W,146W'),
                   'model': 'gfs',
                   'type': 'gridded',
                   'resolution': 0.5,
                   'hours': [24., 48., 72.],
                   'variables': ['wind']
                   }),
                 ('GFS:14S,20S,154W,146W',
                  {'domain': utils.parse_domain('14S,20S,154W,146W'),
                   'model': 'gfs',
                   'type': 'gridded',
                   'resolution': None,
                   'hours': [24., 48., 72.],
                   'variables': ['wind']
                   }),
                 ('GFS : 14S,20S,154W, 146W/  0.5, 0.5 |0, 3.. 120| WIND,',
                  {'domain': utils.parse_domain('14S,20S,154W,146W'),
                   'model': 'gfs',
                   'type': 'gridded',
                   'resolution': 0.5,
                   'hours': list(np.arange(41.) * 3),
                   'variables': ['wind']
                   }),
                 ('GFS : 14S,20S,154W, 146W/  0.5 |0, 3.. 120| WIND,',
                  {'domain': utils.parse_domain('14S,20S,154W,146W'),
                   'model': 'gfs',
                   'type': 'gridded',
                   'resolution': 0.5,
                   'hours': list(np.arange(41.) * 3),
                   'variables': ['wind']
                   }),
                 ('GFS : 14S,20S,154W, 146W/  native |0, 3.. 120| WIND,',
                  {'domain': utils.parse_domain('14S,20S,154W,146W'),
                   'model': 'gfs',
                   'type': 'gridded',
                   'resolution': None,
                   'hours': list(np.arange(41.) * 3),
                   'variables': ['wind']
                   })]

        for request, expected in tests:
            self.maxDiff = 3000
            actual = saildocs.parse_gridded_request(request)
            self.assertDictEqual(actual, expected)