示例#1
0
    def test_grib1_hybrid_height(self):
        gm = gribapi.grib_new_from_samples('regular_gg_ml_grib1')
        gw = GribWrapper(gm)
        results = grib1_convert(gw)

        factory, = results[0]
        self.assertEqual(factory.factory_class,
                         iris.aux_factory.HybridPressureFactory)
        delta, sigma, ref = factory.args
        self.assertEqual(delta, {'long_name': 'level_pressure'})
        self.assertEqual(sigma, {'long_name': 'sigma'})
        self.assertEqual(ref, Reference(name='surface_pressure'))

        ml_ref = iris.coords.CoordDefn('model_level_number', None, None,
                                       cf_units.Unit('1'), {'positive': 'up'},
                                       None)
        lp_ref = iris.coords.CoordDefn(None, 'level_pressure', None,
                                       cf_units.Unit('Pa'), {}, None)
        s_ref = iris.coords.CoordDefn(None, 'sigma', None, cf_units.Unit('1'),
                                      {}, None)

        aux_coord_defns = [coord._as_defn() for coord, dim in results[8]]
        self.assertIn(ml_ref, aux_coord_defns)
        self.assertIn(lp_ref, aux_coord_defns)
        self.assertIn(s_ref, aux_coord_defns)
示例#2
0
    def test_not_edition_1(self):
        def func(grib_message, key):
            return 2

        emsg = "GRIB edition 2 is not supported by 'GribWrapper'"
        with mock.patch('gribapi.grib_get_long', func):
            with self.assertRaisesRegexp(TranslationError, emsg):
                GribWrapper(None)
示例#3
0
 def test_reduced_proxy_args(self):
     grib_message = 'reduced_gg'
     shape = (self.lookup(grib_message, 'numberOfValues'))
     for offset in self.expected:
         with mock.patch('iris.fileformats.grib.GribDataProxy') as mock_gdp:
             gw = GribWrapper(grib_message, self.grib_fh)
         mock_gdp.assert_called_once_with((shape, ), self.dtype, self.path,
                                          offset)
示例#4
0
 def test_regular_proxy_args(self):
     grib_message = 'regular_ll'
     shape = (self.lookup(grib_message,
                          'Nj'), self.lookup(grib_message, 'Ni'))
     for offset in self.expected:
         with mock.patch('iris.fileformats.grib.GribDataProxy') as mock_gdp:
             gw = GribWrapper(grib_message, self.grib_fh)
         mock_gdp.assert_called_once_with(shape, self.dtype, self.path,
                                          offset)
示例#5
0
 def test_regular_sequential(self):
     tell_tale = np.arange(1, 5) * _message_length
     grib_fh = mock.Mock(tell=mock.Mock(side_effect=tell_tale))
     auto_regularise = False
     grib_message = 'regular_ll'
     for i, _ in enumerate(tell_tale):
         gw = GribWrapper(grib_message, grib_fh, auto_regularise)
         self.assertIsInstance(gw._data, NumpyArrayAdapter)
         proxy = gw._data.concrete
         self.assertIsInstance(proxy, GribDataProxy)
         self.assertEqual(proxy.shape, (10, 20))
         self.assertEqual(proxy.dtype, np.float)
         self.assertIs(proxy.fill_value, np.nan)
         self.assertEqual(proxy.path, grib_fh.name)
         self.assertEqual(proxy.offset, _message_length * i)
         self.assertEqual(proxy.regularise, auto_regularise)
示例#6
0
 def test_reduced_mixed(self):
     tell_tale = np.arange(1, 5) * _message_length
     expected = tell_tale - _message_length
     grib_fh = mock.Mock(tell=mock.Mock(side_effect=tell_tale))
     auto_regularise = False
     grib_message = 'reduced_gg'
     for offset in expected:
         gw = GribWrapper(grib_message, grib_fh, auto_regularise)
         self.assertIsInstance(gw._data, NumpyArrayAdapter)
         proxy = gw._data.concrete
         self.assertIsInstance(proxy, GribDataProxy)
         self.assertEqual(proxy.shape, (200, ))
         self.assertEqual(proxy.dtype, np.float)
         self.assertIs(proxy.fill_value, np.nan)
         self.assertEqual(proxy.path, grib_fh.name)
         self.assertEqual(proxy.offset, offset)
         self.assertEqual(proxy.regularise, auto_regularise)
示例#7
0
 def test_edition_1(self):
     grib_message = 'regular_ll'
     grib_fh = mock.Mock(tell=self.tell)
     wrapper = GribWrapper(grib_message, grib_fh)
     self.assertEqual(wrapper.grib_message, grib_message)