Exemplo n.º 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, False)
        lp_ref = iris.coords.CoordDefn(None, 'level_pressure', None,
                                       cf_units.Unit('Pa'), {}, None, False)
        s_ref = iris.coords.CoordDefn(None, 'sigma', None, cf_units.Unit('1'),
                                      {}, None, False)

        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)
Exemplo n.º 2
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, 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'))

        coords_and_dims = results[8]
        coord, = [
            co for co, _ in coords_and_dims
            if co.name() == 'model_level_number'
        ]
        self.assertEqual(coord.units, '1')
        self.assertEqual(coord.attributes['positive'], 'up')
        coord, = [
            co for co, _ in coords_and_dims if co.name() == 'level_pressure'
        ]
        self.assertEqual(coord.units, 'Pa')
        coord, = [co for co, _ in coords_and_dims if co.name() == 'sigma']
        self.assertEqual(coord.units, '1')
Exemplo n.º 3
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.assertRaisesRegex(TranslationError, emsg):
                GribWrapper(None)
Exemplo n.º 4
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_grib.GribDataProxy') as mock_gdp:
             gw = GribWrapper(grib_message, self.grib_fh)
         mock_gdp.assert_called_once_with((shape, ), self.dtype, self.path,
                                          offset)
Exemplo n.º 5
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_grib.GribDataProxy') as mock_gdp:
             gw = GribWrapper(grib_message, self.grib_fh)
         mock_gdp.assert_called_once_with(shape, self.dtype, self.path,
                                          offset)
Exemplo n.º 6
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)