<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _read_packet(f, pos, n_smp, n_allchan, abs_delta):
 """ Read a packet of compressed data Parameters f : instance of opened file erd file pos : int index of the start of the packet in the file (in bytes from beginning of the file) n_smp : int number of samples to read n_allchan : int number of channels (we should specify if shorted or not) abs_delta: byte if the delta has this value, it means that you should read the absolute value at the end of packet. If schema is 7, the length is 1; if schema is 8 or 9, the length is 2. Returns ------- ndarray data read in the packet up to n_smp. Notes ----- TODO: shorted chan. If I remember correctly, deltamask includes all the channels, but the absolute values are only used for not-shorted channels TODO: implement schema 7, which is slightly different, but I don't remember where exactly. """

    if len(abs_delta) == 1:  # schema 7
        abs_delta = unpack('b', abs_delta)[0]
    else:  # schema 8, 9
        abs_delta = unpack('h', abs_delta)[0]

    l_deltamask = int(ceil(n_allchan / BITS_IN_BYTE))
    dat = empty((n_allchan, n_smp), dtype=int32)
    f.seek(pos)

    for i_smp in range(n_smp):
        eventbite = f.read(1)

        try:
            assert eventbite in (b'\x00', b'\x01')
        except:
            raise Exception('at pos ' + str(i_smp) +
                            ', eventbite (should be x00 or x01): ' +
                            str(eventbite))

        byte_deltamask = unpack('<' + 'B' * l_deltamask, f.read(l_deltamask))
        deltamask = unpackbits(array(byte_deltamask[::-1], dtype ='uint8'))
        deltamask = deltamask[:-n_allchan-1:-1]

        n_bytes = int(deltamask.sum()) + deltamask.shape[0]

        deltamask = deltamask.astype('bool')
        # numpy has a weird way of handling string/bytes.
        # We create a byte representation, because then tostring() works fine
        delta_dtype = empty(n_allchan, dtype='a1')
        delta_dtype[deltamask] = 'h'
        delta_dtype[~deltamask] = 'b'
        relval = array(unpack('<' + delta_dtype.tostring().decode(),
                              f.read(n_bytes)))

        read_abs = (delta_dtype == b'h') & (relval == abs_delta)

        dat[~read_abs, i_smp] = dat[~read_abs, i_smp - 1] + relval[~read_abs]
        dat[read_abs, i_smp] = fromfile(f, 'i', count=read_abs.sum())

    return dat