Beispiel #1
0
def um_to_pp(filename, read_data=False, word_depth=None):
    """
    Extract individual PPFields from within a UM Fieldsfile-like file.

    Returns an iterator over the fields contained within the FieldsFile,
    returned as :class:`iris.fileformats.pp.PPField` instances.

    Args:

    * filename (string):
        Specify the name of the FieldsFile.

    Kwargs:

    * read_data (boolean):
        Specify whether to read the associated PPField data within
        the FieldsFile.  Default value is False.

    Returns:
        Iteration of :class:`iris.fileformats.pp.PPField`.

    For example::

        >>> for field in um.um_to_pp(filename):
        ...     print(field)

    """
    if word_depth is None:
        ff2pp = FF2PP(filename, read_data=read_data)
    else:
        ff2pp = FF2PP(filename, read_data=read_data, word_depth=word_depth)

    # Note: unlike the original wrapped case, we will return an actual
    # iterator, rather than an object that can provide an iterator.
    return iter(ff2pp)
Beispiel #2
0
 def test__bad_lbvc(self):
     self.mock_field.lbvc = 312
     ff2pp = FF2PP("dummy_filename")
     with self.assertRaisesRegex(
         ValueError, "LBVC of 312, expected only 0 or 65"
     ):
         ff2pp._adjust_field_for_lbc(self.mock_field)
Beispiel #3
0
 def test__bad_lbtim(self):
     self.mock_field.lbtim = 717
     ff2pp = FF2PP("dummy_filename")
     with self.assertRaisesRegex(
         ValueError, "LBTIM of 717, expected only 0 or 11"
     ):
         ff2pp._adjust_field_for_lbc(self.mock_field)
Beispiel #4
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 #5
0
 def test_increasing_field_values(self):
     # Field where its values a increasing.
     ff2pp = FF2PP('dummy')
     field_x = np.array([1, 2, 3])
     com = np.array([0, 1, 2, 3, 4])
     result = ff2pp._det_border(field_x, 1)
     self.assertArrayEqual(result, com)
Beispiel #6
0
 def test__lbhem_too_large(self):
     ff2pp = FF2PP("dummy_filename")
     field = self.mock_field
     field.lbhem = 105
     with self.assertRaisesRegex(
         ValueError, "more than the total number of levels in the file = 3"
     ):
         _ = list(ff2pp._fields_over_all_levels(field))
Beispiel #7
0
 def test__lbhem_too_small(self):
     ff2pp = FF2PP('dummy_filename')
     field = self.mock_field
     field.lbhem = 100
     with self.assertRaisesRegex(
             ValueError,
             'hence >= 101'):
         _ = list(ff2pp._fields_over_all_levels(field))
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__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 #10
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 #11
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)