@classmethod
def fromdata(cls, data, header=None, bps=2):
    """Encode data as a payload.

        Parameters
        ----------
        data : `~numpy.ndarray`
            Data to be encoded. The last dimension is taken as the number of
            channels.
        header : header instance, optional
            If given, used to infer the bps.
        bps : int, optional
            Bits per elementary sample, i.e., per channel and per real or
            imaginary component, used if header is not given.  Default: 2.
        """
    sample_shape = data.shape[1:]
    complex_data = data.dtype.kind == 'c'
    if header:
        bps = header.bps
    try:
        encoder = cls._encoders[bps]
    except KeyError:
        raise ValueError('{0} cannot encode data with {1} bits'.format(cls.
            __name__, bps))
    if complex_data:
        data = data.view((data.real.dtype, (2,)))
    words = encoder(data).ravel().view(cls._dtype_word)
    return cls(words, sample_shape=sample_shape, bps=bps, complex_data=
        complex_data)
