コード例 #1
0
def test_array_to_table():
    r"""Test conversion of arrays to ASCII table and back."""
    flist = ['# %5s\t%ld\t%lf\t%g%+gj\n']
    for use_astropy in [False, True]:
        for f in flist:
            dtype = serialize.cformat2nptype(f)
            arr0 = np.ones(5, dtype)
            arr0['f0'][0] = b'hello'
            tab = serialize.array_to_table(arr0, f, use_astropy=use_astropy)
            arr1 = serialize.table_to_array(tab, f, use_astropy=use_astropy)
            np.testing.assert_array_equal(arr1, arr0)
コード例 #2
0
    def func_serialize(self, args):
        r"""Serialize a message.

        Args:
            args: List of arguments to be formatted or numpy array to be
                serialized.

        Returns:
            bytes, str: Serialized message.

        """
        if self.format_str is None:
            raise RuntimeError("Format string is not defined.")
        args = self.datatype.coerce_type(args,
                                         key_order=self.get_field_names())
        if self.as_array:
            out = serialize.array_to_table(args, self.format_str,
                                           use_astropy=self.use_astropy)
        else:
            out = serialize.format_message(args, self.format_str)
        return backwards.as_bytes(out)