def test_no_land_mask(self): with mock.patch('numpy.frombuffer', return_value=np.arange(3)): with self.assertRaises(ValueError) as err: pp._data_bytes_to_shaped_array(mock.Mock(), self.create_lbpack(120), None, (3, 4), np.dtype('>f4'), -999, mask=None) self.assertEqual(str(err.exception), ('No mask was found to unpack the data. ' 'Could not load.'))
def test_no_land_mask(self): with mock.patch('numpy.frombuffer', return_value=np.arange(3)): with self.assertRaises(ValueError) as err: pp._data_bytes_to_shaped_array(mock.Mock(), self.create_lbpack(120), None, (3, 4), np.dtype('>f4'), -999, mask=None) self.assertEqual(str(err.exception), ('No mask was found to unpack the data. ' 'Could not load.'))
def test_boundary_decompression(self): boundary_packing = mock.Mock(rim_width=4, x_halo=3, y_halo=2) lbpack = mock.Mock(n1=0) r = pp._data_bytes_to_shaped_array(self.data_payload_bytes, lbpack, boundary_packing, self.data_shape, self.decompressed.dtype, -99) self.assertMaskedArrayEqual(r, self.decompressed)
def test_boundary_decompression(self): boundary_packing = mock.Mock(rim_width=4, x_halo=3, y_halo=2) lbpack = mock.Mock(n1=0, boundary_packing=boundary_packing) r = pp._data_bytes_to_shaped_array(self.data_payload_bytes, lbpack, self.data_shape, self.decompressed.dtype, -99) self.assertMaskedArrayEqual(r, self.decompressed)
def check_read_data(self, field_data, lbpack, mask): # Calls pp._data_bytes_to_shaped_array with the necessary mocked # items, an lbpack instance, the correct data shape and mask instance. with mock.patch('numpy.frombuffer', return_value=field_data): return pp._data_bytes_to_shaped_array(mock.Mock(), self.create_lbpack(lbpack), mask.shape, np.dtype('>f4'), -999, mask=mask)
def test_boundary_decompression(self): boundary_packing = mock.Mock(rim_width=4, x_halo=3, y_halo=2) lbpack = mock.Mock(n1=0) r = pp._data_bytes_to_shaped_array(self.data_payload_bytes, lbpack, boundary_packing, self.data_shape, self.decompressed.dtype, -9223372036854775808) r = ma.masked_array(r, np.isnan(r), fill_value=-9223372036854775808) self.assertMaskedArrayEqual(r, self.decompressed)
def check_read_data(self, field_data, lbpack, mask): # Calls pp._data_bytes_to_shaped_array with the necessary mocked # items, an lbpack instance, the correct data shape and mask instance. with mock.patch('numpy.frombuffer', return_value=field_data): data = pp._data_bytes_to_shaped_array(mock.Mock(), self.create_lbpack(lbpack), None, mask.shape, np.dtype('>f4'), -999, mask=mask) return ma.masked_array(data, np.isnan(data), fill_value=-999)
def test_no_land_mask(self): # Check that without a mask, it returns the raw (compressed) data. with mock.patch('numpy.frombuffer', return_value=np.arange(3)): result = pp._data_bytes_to_shaped_array( mock.Mock(), self.create_lbpack(120), None, (3, 4), np.dtype('>f4'), -999, mask=None) self.assertArrayAllClose(result, np.arange(3))
def test_boundary_decompression(self): boundary_packing = mock.Mock(rim_width=4, x_halo=3, y_halo=2) lbpack = mock.Mock(n1=0) r = pp._data_bytes_to_shaped_array(self.data_payload_bytes, lbpack, boundary_packing, self.data_shape, self.decompressed.dtype, -9223372036854775808) r = ma.masked_array(r, np.isnan(r), fill_value=-9223372036854775808) self.assertMaskedArrayEqual(r, self.decompressed)