Beispiel #1
0
 def test__lbpack_2(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     field.raw_lbpack = 2
     data_depth, data_type = ff2pp._payload(field)
     self.assertEqual(data_depth, 2220)
     self.assertEqual(data_type, np.dtype('>f4'))
Beispiel #2
0
 def test_decreasing_field_values(self):
     # Field where its values a decreasing.
     ff2pp = FF2PP('dummy')
     field_x = np.array([3, 2, 1])
     com = np.array([4, 3, 2, 1, 0])
     result = ff2pp._det_border(field_x, 1)
     self.assertArrayEqual(result, com)
Beispiel #3
0
 def test__lbhem_too_large(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     field.lbhem = 105
     with self.assertRaisesRegexp(
             ValueError,
             'more than the total number of levels in the file = 3'):
         results = list(ff2pp._fields_over_all_levels(field))
Beispiel #4
0
 def test__lbhem_too_small(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     field.lbhem = 100
     with self.assertRaisesRegexp(
             ValueError,
             'hence >= 101'):
         results = list(ff2pp._fields_over_all_levels(field))
Beispiel #5
0
 def test__lbpack_unsupported(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     field.raw_lbpack = 1239
     with self.assertRaisesRegexp(
             NotYetImplementedError,
             'PP fields with LBPACK of 1239 are not supported.'):
         ff2pp._payload(field)
Beispiel #6
0
 def test__lbpack_lbc_error(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     field.raw_lbpack = 1
     field.boundary_packing = 0  # Anything not None will do here.
     with self.assertRaisesRegexp(ValueError,
                                  'packed LBC data is not supported'):
         ff2pp._payload(field)
Beispiel #7
0
 def test__basic(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     ff2pp._adjust_field_for_lbc(field)
     self.assertEqual(field.lbtim, 11)
     self.assertEqual(field.lbvc, 65)
     self.assertEqual(field.boundary_packing.rim_width, 8)
     self.assertEqual(field.boundary_packing.y_halo, 5)
     self.assertEqual(field.boundary_packing.x_halo, 4)
     self.assertEqual(field.lbnpt, 1009)
     self.assertEqual(field.lbrow, 2011)
Beispiel #8
0
 def _test(self,
           mock_field,
           expected_depth,
           expected_dtype,
           word_depth=None):
     with mock.patch('iris.fileformats.ff.FFHeader', return_value=None):
         kwargs = {}
         if word_depth is not None:
             kwargs['word_depth'] = word_depth
         ff2pp = FF2PP('dummy_filename', **kwargs)
         data_depth, data_dtype = ff2pp._payload(mock_field)
         self.assertEqual(data_depth, expected_depth)
         self.assertEqual(data_dtype, expected_dtype)
Beispiel #9
0
    def test_unequal_spacing_eitherside(self):
        # Ensure that we do not interpret the case where there is not the same
        # spacing on the lower edge as the upper edge.
        ff2pp = FF2PP('dummy')
        field_x = np.array([1, 2, 10])

        msg = ('The x or y coordinates of your boundary condition field may '
               'be incorrect, not having taken into account the boundary '
               'size.')

        with mock.patch('warnings.warn') as warn:
            result = ff2pp._det_border(field_x, None)
        warn.assert_called_with(msg)
        self.assertIs(result, field_x)
Beispiel #10
0
 def test__is_lbc(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     results = list(ff2pp._fields_over_all_levels(field))
     self._check_expected_levels(results, 3)
Beispiel #11
0
 def test__bad_lbvc(self):
     self.mock_field.lbvc = 312
     ff2pp = FF2PP('dummy_filename')
     with self.assertRaisesRegexp(ValueError,
                                  'LBVC of 312, expected only 0 or 65'):
         ff2pp._adjust_field_for_lbc(self.mock_field)
Beispiel #12
0
 def test__bad_lbtim(self):
     self.mock_field.lbtim = 717
     ff2pp = FF2PP('dummy_filename')
     with self.assertRaisesRegexp(ValueError,
                                  'LBTIM of 717, expected only 0 or 11'):
         ff2pp._adjust_field_for_lbc(self.mock_field)
Beispiel #13
0
 def test__word_depth(self):
     ff2pp = FF2PP('dummy_filename', word_depth=4)
     field = self.mock_field
     data_depth, data_type = ff2pp._payload(field)
     self.assertEqual(data_depth, 2220)
     self.assertEqual(data_type, np.dtype('>f4'))
Beispiel #14
0
 def test__basic(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     data_depth, data_type = ff2pp._payload(field)
     self.assertEqual(data_depth, 4440)
     self.assertEqual(data_type, np.dtype('>f8'))
Beispiel #15
0
def _collations_from_filename(filename):
    fields = iter(FF2PP(filename))
    return group_structured_fields(fields)