def test_encode_decode_self_mz(self): mz_data = np.asarray(self.mz_data, dtype=np.float64) fp = pynumpress.optimal_linear_fixed_point(mz_data) encoded_mz_data = pynumpress.encode_linear(mz_data, fp) decoded_mz_data = pynumpress.decode_linear(encoded_mz_data) for i in range(len(decoded_mz_data)): self.assertAlmostEqual( decoded_mz_data[i], mz_data[i], places=4, msg="error at pos {0}".format(i), )
def test_encode_decode_linear(self): """ """ test_array = [ 100.00066, 100.00217, 100.00368, 100.00519, 111.73335, 111.73513, 111.73692, 111.7387, 111.74049, 111.74227, 111.74406, 111.74584, 111.74763, 111.74941, 111.7512, 111.75298, 111.75477, 112.00694, 112.00873, 112.01052, 112.01231, 112.0141, 112.01589, 112.01768 ] test_array = np.asarray(test_array, dtype=np.float64) fp = pynumpress.optimal_linear_fixed_point(test_array) encoded_array = pynumpress.encode_linear( test_array, fp ) decoded_array = pynumpress.decode_linear(encoded_array) for i in range(len(decoded_array)): self.assertAlmostEqual( decoded_array[i], test_array[i], places=4, msg='error at pos {0}'.format(i) )
def test_decode_linear(self): # ouput of >>> PyMSNumpress.encode_linear(self.mz_data, enc, # self.fixed_point) encoded_array = [ 65, 116, 117, 164, 112, 0, 0, 0, 246, 255, 255, 127, 194, 137, 226, 127, 43, 243, 138, 19, 220, 106, 32 ] # make bytearray from hex vals encoded_array = np.array(encoded_array, dtype=np.dtype('B')) # decode bytearray to numpy array decoded_array = pynumpress.decode_linear(encoded_array) self.assertIsInstance(decoded_array, np.ndarray) self.assertEqual(len(decoded_array), len(self.mz_data)) for i in range(len(decoded_array)): self.assertAlmostEqual( decoded_array[i], self.mz_data[i], places=i+1)