Exemple #1
0
 def test_unsupported_scanning_mode(self):
     message = _make_test_message({
         3: self.section_3(1),
         6: SECTION_6_NO_BITMAP
     })
     with self.assertRaisesRegexp(TranslationError, 'scanning mode'):
         message.data
 def test(self):
     sections = [{'discipline': mock.sentinel.discipline},       # section 0
                 {'centre': 'ecmf',                              # section 1
                  'tablesVersion': mock.sentinel.tablesVersion},
                 None,                                           # section 2
                 mock.sentinel.grid_definition_section,          # section 3
                 mock.sentinel.product_definition_section,       # section 4
                 mock.sentinel.data_representation_section,      # section 5
                 mock.sentinel.bitmap_section]                   # section 6
     field = _make_test_message(sections)
     metadata = {'factories': [], 'references': [],
                 'standard_name': None,
                 'long_name': None, 'units': None, 'attributes': {},
                 'cell_methods': [], 'dim_coords_and_dims': [],
                 'aux_coords_and_dims': []}
     expected = copy.deepcopy(metadata)
     centre = 'European Centre for Medium Range Weather Forecasts'
     expected['attributes'] = {'centre': centre}
     # The call being tested.
     grib2_convert(field, metadata)
     self.assertEqual(metadata, expected)
     this = iris_grib._load_convert
     this.reference_time_coord.assert_called_with(sections[1])
     this.grid_definition_section.assert_called_with(sections[3],
                                                     expected)
     args = (sections[4], expected, sections[0]['discipline'],
             sections[1]['tablesVersion'], None)
     this.product_definition_section.assert_called_with(*args)
 def test_unsupported_quasi_regular__number_of_octets(self):
     message = _make_test_message(
         {3: {'sourceOfGridDefinition': 0,
              'numberOfOctectsForNumberOfPoints': 1,
              'gridDefinitionTemplateNumber': 0},
          6: SECTION_6_NO_BITMAP})
     with self.assertRaisesRegexp(TranslationError, 'quasi-regular'):
         message.data
 def test_unsupported_template(self):
     message = _make_test_message(
         {3: {'sourceOfGridDefinition': 0,
              'numberOfOctectsForNumberOfPoints': 0,
              'interpretationOfNumberOfPoints': 0,
              'gridDefinitionTemplateNumber': 2}})
     with self.assertRaisesRegexp(TranslationError, 'template'):
         message.data
 def test(self):
     message = _make_test_message(
         {3: _example_section_3(999, 0),
          6: SECTION_6_NO_BITMAP,
          7: {'codedValues': np.arange(12)}})
     with self.assertRaisesRegexp(TranslationError,
                                  'template 999 is not supported'):
         data = message.data
 def test_bitmap__invalid_indicator(self):
     values = np.arange(12)
     message = _make_test_message({3: self._section_3,
                                   6: {'bitMapIndicator': 100,
                                       'bitmap': None},
                                   7: {'codedValues': values}})
     with self.assertRaisesRegexp(TranslationError, 'unsupported bitmap'):
         message.data.ndarray()
 def test(self):
     message = _make_test_message(
         {3: _example_section_3(999, 0),
          6: SECTION_6_NO_BITMAP,
          7: {'codedValues': np.arange(12)}})
     with self.assertRaisesRegex(TranslationError,
                                 'template 999 is not supported'):
         data = message.data
Exemple #8
0
 def test_supported_templates(self):
     template_nums = [0, 1, 2, 3, 4, 40, 41, 42, 50, 51, 61]
     for template_num in template_nums:
         message = _make_test_message(
             {5: {
                 'dataRepresentationTemplateNumber': template_num
             }})
         data_representation_section(message.sections[5])
 def test_unsupported_template(self):
     message = _make_test_message(
         {3: {'sourceOfGridDefinition': 0,
              'numberOfOctectsForNumberOfPoints': 0,
              'interpretationOfNumberOfPoints': 0,
              'gridDefinitionTemplateNumber': 2}})
     with self.assertRaisesRegex(TranslationError, 'template'):
         message.data
 def test_unsupported_quasi_regular__number_of_octets(self):
     message = _make_test_message(
         {3: {'sourceOfGridDefinition': 0,
              'numberOfOctectsForNumberOfPoints': 1,
              'gridDefinitionTemplateNumber': 0},
          6: SECTION_6_NO_BITMAP})
     with self.assertRaisesRegex(TranslationError, 'quasi-regular'):
         message.data
 def test_bitmap__invalid_indicator(self):
     values = np.arange(12)
     message = _make_test_message({3: self._section_3,
                                   6: {'bitMapIndicator': 100,
                                       'bitmap': None},
                                   7: {'codedValues': values}})
     with self.assertRaisesRegex(TranslationError, 'unsupported bitmap'):
         as_concrete_data(message.data)
Exemple #12
0
 def test_unsupported_template(self):
     message = _make_test_message(
         {5: {
             'dataRepresentationTemplateNumber': 5
         }})
     err_msg = r'Template \[5\] is not supported'
     with self.assertRaisesRegex(TranslationError, err_msg):
         data_representation_section(message.sections[5])
 def test_bitmap_unsupported(self):
     # bitMapIndicator in range 1-254.
     # Note that bitMapIndicator = 1-253 and bitMapIndicator = 254 mean two
     # different things, but load_convert treats them identically.
     message = _make_test_message({6: {'bitMapIndicator': 100,
                                       'bitmap': None}})
     with self.assertRaisesRegexp(TranslationError, 'unsupported bitmap'):
         bitmap_section(message.sections[6])
Exemple #14
0
 def test_unsupported_grid_definition(self):
     message = _make_test_message({
         3: {
             'sourceOfGridDefinition': 1
         },
         6: SECTION_6_NO_BITMAP
     })
     with self.assertRaisesRegexp(TranslationError, 'source'):
         message.data
 def test_no_bitmap(self):
     values = np.arange(12)
     message = _make_test_message({3: self._section_3,
                                   6: SECTION_6_NO_BITMAP,
                                   7: {'codedValues': values}})
     result = message.data.ndarray()
     expected = values.reshape(self.shape)
     self.assertEqual(result.shape, self.shape)
     self.assertArrayEqual(result, expected)
 def test_no_bitmap(self):
     values = np.arange(12)
     message = _make_test_message({3: self._section_3,
                                   6: SECTION_6_NO_BITMAP,
                                   7: {'codedValues': values}})
     result = as_concrete_data(message.data)
     expected = values.reshape(self.shape)
     self.assertEqual(result.shape, self.shape)
     self.assertArrayEqual(result, expected)
 def test_bitmap__shapes_mismatch(self):
     # Test the behaviour where bitmap and codedValues shapes do not match.
     # Too many or too few unmasked values in codedValues will cause this.
     values = np.arange(6)
     message = _make_test_message({3: self._section_3,
                                   6: {'bitMapIndicator': 0,
                                       'bitmap': self.bitmap},
                                   7: {'codedValues': values}})
     with self.assertRaisesRegexp(TranslationError, 'do not match'):
         message.data.masked_array()
 def test_bitmap__shapes_mismatch(self):
     # Test the behaviour where bitmap and codedValues shapes do not match.
     # Too many or too few unmasked values in codedValues will cause this.
     values = np.arange(6)
     message = _make_test_message({3: self._section_3,
                                   6: {'bitMapIndicator': 0,
                                       'bitmap': self.bitmap},
                                   7: {'codedValues': values}})
     with self.assertRaisesRegex(TranslationError, 'do not match'):
         as_concrete_data(message.data)
 def _test(self, scanning_mode):
     message = _make_test_message(
         {3: self.section_3(scanning_mode),
          6: SECTION_6_NO_BITMAP,
          7: {'codedValues': np.arange(12)}})
     data = message.data
     self.assertTrue(is_lazy_data(data))
     self.assertEqual(data.shape, (3, 4))
     self.assertEqual(data.dtype, np.floating)
     self.assertArrayEqual(as_concrete_data(data),
                           np.arange(12).reshape(3, 4))
 def _test(self, scanning_mode):
     message = _make_test_message(
         {3: self.section_3(scanning_mode),
          6: SECTION_6_NO_BITMAP,
          7: {'codedValues': np.arange(12)}})
     data = message.data
     self.assertTrue(is_lazy_data(data))
     self.assertEqual(data.shape, (3, 4))
     self.assertEqual(data.dtype, np.floating)
     self.assertArrayEqual(as_concrete_data(data),
                           np.arange(12).reshape(3, 4))
 def test_bitmap_unsupported(self):
     # bitMapIndicator in range 1-254.
     # Note that bitMapIndicator = 1-253 and bitMapIndicator = 254 mean two
     # different things, but load_convert treats them identically.
     message = _make_test_message(
         {6: {
             'bitMapIndicator': 100,
             'bitmap': None
         }})
     with self.assertRaisesRegex(TranslationError, 'unsupported bitmap'):
         bitmap_section(message.sections[6])
 def _test(self, scanning_mode):
     message = _make_test_message(
         {3: self.section_3(scanning_mode),
          6: SECTION_6_NO_BITMAP,
          7: {'codedValues': np.arange(12)}})
     data = message.data
     self.assertIsInstance(data, biggus.Array)
     self.assertEqual(data.shape, (3, 4))
     self.assertEqual(data.dtype, np.floating)
     self.assertIs(data.fill_value, np.nan)
     self.assertArrayEqual(data.ndarray(), np.arange(12).reshape(3, 4))
Exemple #23
0
    def test_edition_2(self):
        def func(field, metadata):
            return metadata['factories'].append(factory)

        sections = [{'editionNumber': 2}]
        field = _make_test_message(sections)
        this = 'iris_grib._load_convert.grib2_convert'
        factory = mock.sentinel.factory
        with mock.patch(this, side_effect=func) as grib2_convert:
            # The call being tested.
            result = convert(field)
            self.assertTrue(grib2_convert.called)
            metadata = ([factory], [], None, None, None, {}, [], [], [])
            self.assertEqual(result, metadata)
 def test_bitmap_present(self):
     # Test the behaviour where bitmap and codedValues shapes
     # are not equal.
     input_values = np.arange(5)
     output_values = np.array([-1, -1, 0, 1, -1, -1, -1, 2, -1, 3, -1, 4])
     message = _make_test_message({3: self._section_3,
                                   6: {'bitMapIndicator': 0,
                                       'bitmap': self.bitmap},
                                   7: {'codedValues': input_values}})
     result = message.data.masked_array()
     expected = np.ma.masked_array(output_values,
                                   np.logical_not(self.bitmap))
     expected = expected.reshape(self.shape)
     self.assertMaskedArrayEqual(result, expected)
 def test_bitmap_present(self):
     # Test the behaviour where bitmap and codedValues shapes
     # are not equal.
     input_values = np.arange(5)
     output_values = np.array([-1, -1, 0, 1, -1, -1, -1, 2, -1, 3, -1, 4])
     message = _make_test_message({3: self._section_3,
                                   6: {'bitMapIndicator': 0,
                                       'bitmap': self.bitmap},
                                   7: {'codedValues': input_values}})
     result = as_concrete_data(message.data)
     expected = ma.masked_array(output_values,
                                np.logical_not(self.bitmap))
     expected = expected.reshape(self.shape)
     self.assertMaskedArrayEqual(result, expected)
Exemple #26
0
 def _test(self, scanning_mode):
     message = _make_test_message({
         3: self.section_3(scanning_mode),
         6: SECTION_6_NO_BITMAP,
         7: {
             'codedValues': np.arange(12)
         }
     })
     data = message.data
     self.assertIsInstance(data, biggus.Array)
     self.assertEqual(data.shape, (3, 4))
     self.assertEqual(data.dtype, np.floating)
     self.assertIs(data.fill_value, np.nan)
     self.assertArrayEqual(data.ndarray(), np.arange(12).reshape(3, 4))
Exemple #27
0
    def test_edition_2(self):
        def func(field, metadata):
            return metadata['factories'].append(factory)

        sections = [{'editionNumber': 2}]
        field = _make_test_message(sections)
        this = 'iris_grib._load_convert.grib2_convert'
        factory = mock.sentinel.factory
        with mock.patch(this, side_effect=func) as grib2_convert:
            # The call being tested.
            result = convert(field)
            self.assertTrue(grib2_convert.called)
            metadata = ([factory], [], None, None, None, {}, [], [], [])
            self.assertEqual(result, metadata)
Exemple #28
0
 def test_edition_1_bad(self):
     sections = [{'editionNumber': 1}]
     field = _make_test_message(sections)
     emsg = 'edition 1 is not supported'
     with self.assertRaisesRegex(TranslationError, emsg):
         convert(field)
Exemple #29
0
 def test_edition_1_bad(self):
     sections = [{'editionNumber': 1}]
     field = _make_test_message(sections)
     emsg = 'edition 1 is not supported'
     with self.assertRaisesRegexp(TranslationError, emsg):
         convert(field)
 def test(self):
     # Check that the `sections` attribute defers to the `sections`
     # attribute on the underlying _RawGribMessage.
     message = _make_test_message(mock.sentinel.SECTIONS)
     self.assertIs(message.sections, mock.sentinel.SECTIONS)
 def test_unsupported_scanning_mode(self):
     message = _make_test_message(
         {3: self.section_3(1),
          6: SECTION_6_NO_BITMAP})
     with self.assertRaisesRegexp(TranslationError, 'scanning mode'):
         message.data
Exemple #32
0
 def test(self):
     # Check that the `sections` attribute defers to the `sections`
     # attribute on the underlying _RawGribMessage.
     message = _make_test_message(mock.sentinel.SECTIONS)
     self.assertIs(message.sections, mock.sentinel.SECTIONS)
 def test_unsupported_grid_definition(self):
     message = _make_test_message({3: {'sourceOfGridDefinition': 1},
                                   6: SECTION_6_NO_BITMAP})
     with self.assertRaisesRegexp(TranslationError, 'source'):
         message.data