Esempio n. 1
0
 def test_mdi(self):
     data = np.arange(12, dtype=np.float32).reshape(3, 4)
     compressed_data = mo_pack.compress_wgdos(data,
                                              missing_data_indicator=4.0)
     expected_data = data
     data[1, 0] = 4.0
     self.assert_equal_when_decompressed(compressed_data, data, mdi=4.0)
Esempio n. 2
0
 def test_accuracy(self):
     data = np.array([[0.1234, 0.2345, 0.3456], [0.4567, 0.5678, 0.6789]],
                     dtype=np.float32)
     compressed = mo_pack.compress_wgdos(data, accuracy=-4)
     decompressed_data = mo_pack.decompress_wgdos(compressed, 2, 3)
     expected = np.array([[0.12340003, 0.18590003, 0.34560001],
                          [0.40810001, 0.56779999, 0.63029999]],
                         dtype=np.float32)
     np.testing.assert_array_equal(decompressed_data, expected)
Esempio n. 3
0
        def _wgdos_pack_field(data, mdi, acc):
            """
            WGDOS-pack a field using the MO packing library 'mo_pack'.

            Args:
                * data (array):
                    a 2-dimensional array containing the field data.
                    .. note::
                        this must be a contiguous array; some slices and other
                        array views may be unsuitable to pass here.
                * mdi (float):
                    the value representing missing data in the field.
                * acc (int):
                   the accuracy to pack the field to.  This a power of 2 so,
                   expect the packed values to be within (2**acc)/2 above or
                   below the original values.

            Returns:
                data_bytes (string):
                    packed byte data.

            """
            data_bytes = mo_pack.compress_wgdos(data.astype("f4"), acc, mdi)
            return data_bytes
Esempio n. 4
0
 def test_different_shape(self):
     data = np.arange(24, dtype=np.float32).reshape(8, 3)
     compressed_data = mo_pack.compress_wgdos(data)
     decompressed_data = mo_pack.decompress_wgdos(compressed_data, 4, 6)
     np.testing.assert_array_equal(decompressed_data, data.reshape(4, 6))
Esempio n. 5
0
 def test_incorrect_size(self):
     data = np.arange(77, dtype=np.float32).reshape(7, 11)
     compressed_data = mo_pack.compress_wgdos(data)
     with self.assertRaises(ValueError):
         decompressed_data = mo_pack.decompress_wgdos(compressed_data, 5, 6)
Esempio n. 6
0
 def test_pack_wgdos(self):
     data = np.arange(42, dtype=np.float32).reshape(7, 6)
     compressed_data = mo_pack.compress_wgdos(data)
     self.assert_equal_when_decompressed(compressed_data, data)