示例#1
0
def save_matching(matching, lsensors, rescale=True):
    """

    :param smatching:
    :return:
    """

    collist = choose_color(len(matching))

    lpages = []

    c = canvas.canvas()
    c.text(0, (len(matching) + 1) * 5, "%s" % (datainfo.name), [text.size(5)])

    for i, s in enumerate(lsensors):
        c.text((i * 5) + 1, len(matching) * 5, s, [text.size(5)])
        c.text((i * 5) + 1, -2, s, [text.size(5)])

    for i, match in enumerate(matching):
        p = path.rect(-5.5, i * 5, 5, 5)
        c.stroke(p, [deco.filled([collist[i]])])
        peaks = [False] * len(lsensors)
        nclust = [''] * len(lsensors)
        for m in match:
            if m[0:4] in lsensors:
                peaks[lsensors.index(m[0:4])] = True
                nclust[lsensors.index(m[0:4])] = str(int(m[4:]) + 1)

        for j in range(len(lsensors)):
            if peaks[j]:
                isens = datainfo.sensors.index(lsensors[j])
                fname = datainfo.dpath + '/' + datainfo.name + "/Results/icons/" + datainfo.name + lsensors[j] \
                        + '.nc' + str(datainfo.clusters[isens]) + '.cl' + nclust[j] + '.jpg'
                bm = bitmap.jpegimage(fname)
                bm.info = {}
                bm.info['dpi'] = (100, 100)
                bm2 = bitmap.bitmap(j * 5, i * 5, bm, compressmode=None)
                c.insert(bm2)

    lpages.append(document.page(c))

    d = document.document(lpages)
    res = ''
    if rescale:
        res = 'rescale'

    d.writePDFfile(datainfo.dpath + '/' + datainfo.name +
                   "/Results/peaksmatching-%s-%s" % (datainfo.name, res))
示例#2
0
def save_matching(matching, lsensors, rescale=True):
    """

    :param smatching:
    :return:
    """

    collist = choose_color(len(matching))

    lpages = []

    c = canvas.canvas()
    c.text(0, (len(matching)+1)*5, "%s" % (datainfo.name), [text.size(5)])

    for i, s in enumerate(lsensors):
        c.text((i*5)+1, len(matching)*5, s, [text.size(5)])
        c.text((i*5)+1, -2, s, [text.size(5)])

    for i, match in enumerate(matching):
        p = path.rect(-5.5, i*5,  5, 5)
        c.stroke(p, [deco.filled([collist[i]])])
        peaks = [False] * len(lsensors)
        nclust = [''] * len(lsensors)
        for m in match:
            if m[0:4] in lsensors:
                peaks[lsensors.index(m[0:4])] = True
                nclust[lsensors.index(m[0:4])] = str(int(m[4:])+1)

        for j in range(len(lsensors)):
            if peaks[j]:
                isens = datainfo.sensors.index(lsensors[j])
                fname = datainfo.dpath + '/' + datainfo.name + "/Results/icons/" + datainfo.name + lsensors[j] \
                        + '.nc' + str(datainfo.clusters[isens]) + '.cl' + nclust[j] + '.jpg'
                bm = bitmap.jpegimage(fname)
                bm.info = {}
                bm.info['dpi'] = (100, 100)
                bm2 = bitmap.bitmap(j*5, i*5, bm, compressmode=None)
                c.insert(bm2)

    lpages.append(document.page(c))

    d = document.document(lpages)
    res = ''
    if rescale:
        res = 'rescale'

    d.writePDFfile(datainfo.dpath + '/' + datainfo.name + "/Results/peaksmatching-%s-%s" % (datainfo.name, res))
示例#3
0
def plot_sequences(nfile, lseq, nsym, sensor, lmatch=0, mapping=None):
    """
    plots the sequence of frequent pairs

    :param nfile:
    :param lseq:
    :return:
    """
    if lmatch != 0:
        collist = choose_color(lmatch)
    else:
        collist = choose_color(nsym)

    lpages = []

    c = canvas.canvas()

    if lmatch != 0:
        mtx = np.zeros(lmatch) + 0.5
        for i in range(nsym):
            mtx[mapping[i]] = 1
        for i, col in enumerate(collist):
            p = path.rect(3 + i, 7, 1, mtx[i])
            c.stroke(p, [deco.filled([col])])
    else:
        for i, col in enumerate(collist):
            p = path.rect(3 + i, 7, 1, 1)
            c.stroke(p, [deco.filled([col])])

    dpos = -5
    step = 50
    tres = 5000.0
    stt = -1

    c.text(0, 10, "%s-%s-%s-%s" % (datainfo.name, dfile, sensor, ename),
           [text.size(5)])

    for seq in lseq:
        if len(seq) == 4:
            tm1, pk1, tm2, pk2 = seq
            coord = tm1 / tres
            lng = (tm2 / tres) - coord
            if lmatch != 0:
                pk1 = int(mapping[pk1])
                pk2 = int(mapping[pk2])

            dcoord = int(coord / step)
            ypos = dcoord * dpos
            if stt != dcoord:
                stt = dcoord
                c.text(0, 3 + ypos, str(tm1), [text.size(1)])
            p = path.rect(3 + coord - (dcoord * step), 3 + ypos, lng / 2.0, 1)
            c.stroke(p, [deco.filled([collist[pk1]])])
            p = path.rect(3 + coord - (dcoord * step) + (lng / 2.0), 3 + ypos,
                          lng / 2.0, 1)
            c.stroke(p, [deco.filled([collist[pk2]])])
            c.stroke(p)
            # p = path.line(3+coord - (dcoord*step), 3+ypos + 1,  3+coord - (dcoord*step), 3+ypos + 2)
            # c.stroke(p, [deco.filled([collist[pk1]])])
            c.fill(
                path.rect(3 + coord - (dcoord * step), 3 + ypos + 1, 0.05, 1),
                [collist[pk1]])
        else:
            tm1, pk1 = seq
            if lmatch != 0:
                pk1 = int(mapping[pk1])
            coord = tm1 / tres
            dcoord = int(coord / step)
            ypos = dcoord * dpos
            if stt != dcoord:
                stt = dcoord
                c.text(0, 3 + ypos, str(tm1), [text.size(1)])
            # p = path.line(3+coord - (dcoord*step), 3+ypos + 1, 3+coord - (dcoord*step), 3+ypos + 2)
            # c.stroke(p, [deco.filled([collist[pk1]])])
            c.fill(
                path.rect(3 + coord - (dcoord * step), 3 + ypos + 1, 0.05, 1),
                [collist[pk1]])

    lpages.append(document.page(c))

    d = document.document(lpages)

    d.writePDFfile(datainfo.dpath + '/' + datainfo.name +
                   "/Results/peaksseq-%s-%s-%s-%s-%d" %
                   (datainfo.name, dfile, sensor, ename, nsym))
def plot_sequences(nfile, lseq, nsym, sensor, lmatch=0, mapping=None):
    """
    plots the sequence of frequent pairs

    :param nfile:
    :param lseq:
    :return:
    """
    if lmatch != 0:
        collist = choose_color(lmatch)
    else:
        collist = choose_color(nsym)

    lpages = []

    c = canvas.canvas()

    if lmatch != 0:
        mtx = np.zeros(lmatch) + 0.5
        for i in range(nsym):
            mtx[mapping[i]] = 1
        for i, col in enumerate(collist):
            p = path.rect(3 + i , 7, 1,  mtx[i])
            c.stroke(p, [deco.filled([col])])
    else:
        for i, col in enumerate(collist):
            p = path.rect(3 + i , 7, 1,  1)
            c.stroke(p, [deco.filled([col])])

    dpos = -5
    step = 50
    tres = 5000.0
    stt = -1

    c.text(0, 10, "%s-%s-%s-%s" % (datainfo.name, dfile, sensor, ename), [text.size(5)])

    for seq in lseq:
        if len(seq) == 4:
            tm1, pk1, tm2, pk2 = seq
            coord = tm1 / tres
            lng = (tm2/tres) - coord
            if lmatch != 0:
                pk1 = int(mapping[pk1])
                pk2 = int(mapping[pk2])


            dcoord = int(coord/step)
            ypos = dcoord * dpos
            if stt != dcoord:
                stt = dcoord
                c.text(0, 3+ypos, str(tm1), [text.size(1)])
            p = path.rect(3+coord - (dcoord*step), 3+ypos, lng/2.0,  1)
            c.stroke(p, [deco.filled([collist[pk1]])])
            p = path.rect(3+coord - (dcoord*step) +(lng/2.0), 3+ypos, lng/2.0,  1)
            c.stroke(p, [deco.filled([collist[pk2]])])
            c.stroke(p)
            # p = path.line(3+coord - (dcoord*step), 3+ypos + 1,  3+coord - (dcoord*step), 3+ypos + 2)
            # c.stroke(p, [deco.filled([collist[pk1]])])
            c.fill(path.rect(3+coord - (dcoord*step), 3+ypos + 1, 0.05, 1),[collist[pk1]])
        else:
            tm1, pk1 = seq
            if lmatch != 0:
                pk1 = int(mapping[pk1])
            coord = tm1 / tres
            dcoord = int(coord /step)
            ypos = dcoord * dpos
            if stt != dcoord:
                stt = dcoord
                c.text(0,3+ ypos, str(tm1), [text.size(1)])
            # p = path.line(3+coord - (dcoord*step), 3+ypos + 1, 3+coord - (dcoord*step), 3+ypos + 2)
            # c.stroke(p, [deco.filled([collist[pk1]])])
            c.fill(path.rect(3+coord - (dcoord*step), 3+ypos + 1, 0.05, 1),[collist[pk1]])


    lpages.append(document.page(c))

    d = document.document(lpages)

    d.writePDFfile(datainfo.dpath + '/' + datainfo.name + "/Results/peaksseq-%s-%s-%s-%s-%d" % (datainfo.name, dfile, sensor, ename, nsym))
示例#5
0
def draw_synchs_boxes(pk, exp, ename, sensors, window, nsym, nmatch=0, dmappings=None):
    """
    Draws syncronizations and their time window boxes

    :param peakdata:
    :param exp:
    :param ename:
    :param sensors:
    :param window:
    :param nsym:
    :param nmatch:
    :param dmappings:
    :return:
    """
    if nmatch != 0:
        collist = choose_color(nmatch)
    else:
        collist = choose_color(nsym)

    lpages = []

    c = canvas.canvas()

    # Paleta de colores
    for i, col in enumerate(collist):
        p = path.rect((i * 0.25) + 5, 7, 0.25, 0.25)
        c.stroke(p, [deco.filled([col])])

    dpos = -len(sensors) - 1

    lppage = 10
    step = 100
    tres = 500.0
    stt = -1

    lpages = []
    npages = 0
    nline = 1

    c.text(-4, 14, " ", [text.size(5)])
    c.text(0, 10, "%s-%s-%s-W%d" % (datainfo.name, dfile, ename, window), [text.size(5)])

    for i in range(len(pk)):
        l = [False] * len(sensors)
        lcol = [cmyk.White] * len(sensors)
        ptime = np.zeros(len(sensors))
        for p in pk[i]:
            sns = sensors[p[0]]
            l[p[0]] = True
            ptime[p[0]] = p[1]
            if dmappings is not None:
                lcol[p[0]] = collist[int(dmappings[sns][p[2]])]
            else:
                lcol[p[0]] = collist[p[2]]

        tm1 = np.min([t for _, t, _ in pk[i]])
        tm2 = np.max([t for _, t, _ in pk[i]])
        coord = tm1 / tres
        lng = (tm2 - tm1) / tres

        dcoord = int(coord / step)
        if stt != dcoord:

            # New page
            if nline % lppage == 0:
                c.text(step+10, 3 + (lppage-1) * dpos, str(npages+1), [text.size(5)])
                c.text(step+12, -1 + (lppage-1) * dpos, " ", [text.size(5)])

                nline = 1
                npages += 1
                lpages.append(document.page(c))
                c = canvas.canvas()
                c.text(-4, 14, " ", [text.size(5)])
                c.text(0, 10, "%s-%s-%s-W%d" % (datainfo.name, dfile, ename, window), [text.size(5)])
                # Paleta de colores
                for i, col in enumerate(collist):
                    p = path.rect((i * 0.25) + 5, 7, 0.25, 0.25)
                    c.stroke(p, [deco.filled([col])])

            nline += 1

            stt = dcoord
            ypos = (dcoord * dpos) - (npages * (lppage-1) * dpos)

            # Legend on the left for the names of the sensors
            c.text(-2, 3 + ypos, str(tm1), [text.size(3)])
            for j, sn in enumerate(sensors):
                c.text(1, 3 + ypos + 1 - j, sn, [text.size(3)])
        else:
            ypos = (dcoord * dpos) - (npages * (lppage-1) * dpos)


        # Rectangulo que rodea las sincronizaciones
        p = path.rect(3 + (coord - (dcoord * step)), 3 + ypos + 2 - len(sensors), lng + .05, len(sensors))
        c.stroke(p)

        for j in range(len(sensors)):
            if l[j]:
                tcoord = ptime[j] / tres
                c.fill(path.rect(3 + (tcoord - (dcoord * step)), 3 + ypos + 1 - j, 0.05, 1), [lcol[j]])
                # p = path.line(3 + (tcoord - (dcoord*step)), 3+ypos + 1+j,  3 + (tcoord - (dcoord*step)), 3+ypos + 2+j)
                # c.stroke(p, [deco.filled([lcol[j]])])

    if nline != 0:
        c.text(step+10, 3 + (lppage-1) * dpos, str(npages+1), [text.size(5)])
        c.text(step+12, -1 + (lppage-1) * dpos, " ", [text.size(5)])
        lpages.append(document.page(c))

    d = document.document(lpages)

    d.writePDFfile(
        datainfo.dpath + '/' + datainfo.name + "/Results/peakssyncboxes-%s-%s-%s" % (datainfo.name, dfile, ename))
示例#6
0
def draw_synchs(peakdata, exp, ename, sensors, window, nsym, nmatch=0, dmappings=None):
    """
    Generates a PDF of the synchronizations
    :param peakdata: Dictionary with the synchronizations computed by compute_syncs
    :param exps: Experiments in the dictionary
    :param window: Window used to determine the synchronizations
    :return:
    """

    def syncIcon(x, y, sensors, coord, lv, lcol, scale, can):
        """
        Generates the drawing for a syncronization

        :param x:
        :param y:
        :param sensors:
        :param coord:
        :param lv:
        :param lcol:
        :param scale:
        :param can:
        :param dmappings:
        :return:
        """
        scale *= 0.6
        y = (y / 2.5) + 2
        x += 5

        for al, v, col in zip(sensors, lv, lcol):
            c = coord[al]
            p = path.rect(y + (c[0] * scale), x + (c[1] * scale), scale, scale)
            if v:
                can.stroke(p, [deco.filled([col])])
            else:
                can.stroke(p)

    # Generates the list of colors
    if nmatch == 0:
        collist = choose_color(nsym)
    else:
        collist = choose_color(nmatch)

    ncol = 0
    npage = 1
    lpages = []
    pk = peakdata
    c = canvas.canvas()
    p = path.line(1, 0, 1, 28)
    c.stroke(p)
    c.text(1.5, 27, '%s - page: %d' % (exp, npage), [text.size(-1)])
    vprev = 0
    y = 0
    yt = 1.25

    # Paleta de colores
    for i, col in enumerate(collist):
        p = path.rect(0, i * 0.25, 0.25, 0.25)
        c.stroke(p, [deco.filled([col])])

    for i in range(len(pk)):
        l = [False] * len(sensors)
        lcol = [cmyk.White] * len(sensors)
        for p in pk[i]:
            l[p[0]] = True
            sns = sensors[p[0]]
            if dmappings is not None:
                lcol[p[0]] = collist[int(dmappings[sns][p[2]])]
            else:
                lcol[p[0]] = collist[p[2]]

        v = np.min([t for _, t, _ in pk[i]]) % 10000  # Time in a page (5000)
        if v < vprev:
            p = path.line(yt + 2.5, 0, yt + 2.5, 28)
            c.stroke(p)
            y += 6.3
            yt += 2.5
            ncol += 1
            if ncol % 7 == 0:
                # p=path.line(yt+2.5, 0, yt+2.5, 28)
                # c.stroke(p)
                npage += 1
                ncol = 0
                lpages.append(document.page(c))
                c = canvas.canvas()
                p = path.line(1, 0, 1, 28)
                c.stroke(p)
                c.text(1.5, 27, '%s - page: %d' % (exp, npage), [text.size(-1)])
                vprev = 0
                y = 0
                yt = 1.25

        vprev = v
        d = v - 1500  # end of the page (800)

        # proportion of x axis (200)
        c.text(yt, (d / 400.0) + 5.25, '%8s' % str(int(round(pk[i][0][1] * 0.6))), [text.size(-4)])
        syncIcon(d / 400.0, y, sensors, coormap, l, lcol, 0.25, c)

    # p=path.line(yt+2.5, 0, yt+2.5, 28)
    # c.stroke(p)

    d = document.document(lpages)

    d.writePDFfile(
        datainfo.dpath + '/' + datainfo.name + "/Results/peaksynchs-%s-%s-%s-W%d" % (datainfo.name, exp, ename, window))