Ejemplo n.º 1
0
def listToBin(forBin,
              type='sphere',
              posDelta=0.2,
              vPosDelta=0.5,
              startPos=0,
              startStr=''):

    distinct = sorted(list(set(forBin)))
    distinctPos = {
        k: (i * posDelta + startPos)
        for i, k in enumerate(distinct)
    }
    NDist = len(distinct)

    objects = []

    for i, d in enumerate(distinct):
        myText = sO.Text(f'{startStr}[{d}]')
        myText.actor.SetScale(0.1, 0.1, 0.1)
        myText.actor.SetPosition(startPos + i * posDelta, -1, 0)
        myText.actor.GetProperty().SetColor(0, 0, 0)
        myText.actor.RotateZ(-90)

        objects.append(myText)

        vLine = sO.Line((startPos + i * posDelta, -.4, 0),
                        (startPos + i * posDelta, -.6, 0))
        objects.append(vLine)

    vLine = sO.Line((startPos, -.5, 0),
                    (startPos + (NDist - 1) * posDelta, -.5, 0))
    objects.append(vLine)

    for i, k in enumerate(forBin):
        s = sO.Sphere()
        s.actor.SetScale(posDelta * 0.5)
        s.actor.SetPosition(distinctPos[k], i * vPosDelta, 0)
        s.actor.GetProperty().SetColor(0, 1, 0)
        objects.append(s)

        for j in range(NDist):
            v = sO.Voxel()
            v.actor.SetPosition(startPos + (j - 0.5) * posDelta,
                                (i - 0.5) * vPosDelta, -0.5 * posDelta)
            v.actor.SetScale(posDelta, vPosDelta, posDelta)
            objects.append(v)

    return objects
Ejemplo n.º 2
0
def getPatients(nPatients, xPos, yPosDelta):

    allObj = []
    for p in range(nPatients):
        patientText = sO.Text(f'p_{p:03d}')
        patientText.actor.SetScale(0.1, 0.1, 0.1)
        patientText.actor.SetPosition(xPos, p * yPosDelta, 0)
        patientText.actor.GetProperty().SetColor(0, 0, 0)

        allObj.append(patientText)

        ax = sO.Line((xPos - 0.3 - 0.1, p * yPosDelta, 0),
                     (xPos - 0.3 + 0.1, p * yPosDelta, 0))
        allObj.append(ax)

    ax = sO.Line((xPos - 0.3, 0, 0),
                 (xPos - 0.3, (nPatients - 1) * yPosDelta, 0))
    allObj.append(ax)

    return allObj
Ejemplo n.º 3
0
def get1DobjectsSmooth(vals,
                       xPos,
                       xText='x',
                       yPosDelta=0.5,
                       size=0.3,
                       vMax=None,
                       vMin=None,
                       highlight=None):

    if vMin is None:
        minVal = min(vals)
    else:
        minVal = vMin

    if vMax is None:
        maxVal = max(vals)
    else:
        maxVal = vMax

    size1 = 0.2 + 0.8 * (np.array(vals) - minVal) / (maxVal - minVal)
    colors = plt.cm.Blues(size1)[:, :-1]

    allObj = []
    for i, color in enumerate(colors):

        if (highlight is not None) and (highlight != i):
            color = cl.rgb_to_hsv(color)
            # color[0] = 0
            color[1] = 0
            color = cl.hsv_to_rgb(color)

        obj = sO.Cube()
        obj.source.SetCenter(xPos, i * yPosDelta, 0)
        obj.setSize(size * size1[i])
        obj.setColor(color)

        if (highlight is not None) and (highlight != i):
            obj.actor.GetProperty().SetOpacity(0.2)

        allObj.append(obj)

    xLabel = sO.Text(f'{xText}')
    xLabel.actor.SetScale(0.1, 0.1, 0.1)
    xLabel.actor.SetPosition(xPos - 0.2, -1, 0)
    xLabel.actor.GetProperty().SetColor(0, 0, 0)

    allObj.append(xLabel)

    ax1 = sO.Line((xPos, -0.4, 0), (xPos, -0.6, 0))
    allObj.append(ax1)

    return allObj
Ejemplo n.º 4
0
def get2DObjects(colors2D,
                 sizes2D,
                 xPos,
                 xText='x',
                 yPosDelta=0.5,
                 zPosDelta=0.5,
                 size=0.3,
                 maxNz=10,
                 highlight=None):

    allObj = []
    for i, (colors, sizes) in enumerate(zip(colors2D, sizes2D)):
        for j, (c, s) in enumerate(zip(colors, sizes)):
            if j > maxNz:
                break

            if (highlight is not None) and (highlight != i):
                c = cl.rgb_to_hsv(c)
                # color[0] = 0
                c[1] = 0
                c = cl.hsv_to_rgb(c)

            obj = sO.Cube()
            obj.source.SetCenter(xPos, i * yPosDelta, -j * zPosDelta)
            obj.setSize(size * s)
            obj.setColor(c)

            if (highlight is not None) and (highlight != i):
                obj.actor.GetProperty().SetOpacity(0.1)

            allObj.append(obj)

    xLabel = sO.Text(f'{xText}')
    xLabel.actor.SetScale(0.1, 0.1, 0.1)
    xLabel.actor.SetPosition(xPos - 0.2, -1, 0)
    xLabel.actor.GetProperty().SetColor(0, 0, 0)
    allObj.append(xLabel)

    ax1 = sO.Line((xPos, -0.4, 0), (xPos, -0.6, 0))
    allObj.append(ax1)

    return allObj
Ejemplo n.º 5
0
def get1Dobjects(colors,
                 xPos,
                 xText='x',
                 yPosDelta=0.5,
                 size=0.3,
                 highlight=None):

    allObj = []
    for i, color in enumerate(colors):

        if (highlight is not None) and (highlight != i):
            color = cl.rgb_to_hsv(color)
            # color[0] = 0
            color[1] = 0
            color = cl.hsv_to_rgb(color)

        obj = sO.Cube()
        obj.source.SetCenter(xPos, i * yPosDelta, 0)
        obj.setSize(size)
        obj.setColor(color)

        if (highlight is not None) and (highlight != i):
            obj.actor.GetProperty().SetOpacity(0.2)

        allObj.append(obj)

    xLabel = sO.Text(f'{xText}')
    xLabel.actor.SetScale(0.1, 0.1, 0.1)
    xLabel.actor.SetPosition(xPos - 0.2, -1, 0)
    xLabel.actor.GetProperty().SetColor(0, 0, 0)

    allObj.append(xLabel)

    ax1 = sO.Line((xPos, -0.4, 0), (xPos, -0.6, 0))
    allObj.append(ax1)

    return allObj
Ejemplo n.º 6
0
def getDiagnObjs(diagn,
                 xPos,
                 xText='x',
                 yPosDelta=0.5,
                 zPosDelta=0.5,
                 size=0.3,
                 highlight=None):

    uniques = set([])
    for ds in diagn:
        for d in ds:
            uniques.update(d)

    uniques = sorted(list(uniques))
    nUniq = len(uniques)
    colors = {m: plt.cm.tab20b(i / nUniq)[:-1] for i, m in enumerate(uniques)}
    poss = {m: i for i, m in enumerate(uniques)}

    allObj = []
    for i, patient in enumerate(diagn):
        for j, day in enumerate(patient):
            for k, disease in enumerate(uniques):
                if disease in day:

                    c = colors[disease]
                    if (highlight is not None) and (highlight != i):
                        c = cl.rgb_to_hsv(c)
                        c[1] = 0
                        c = cl.hsv_to_rgb(c)

                    obj = sO.Cube()
                    obj.source.SetCenter(xPos - k * size / (nUniq),
                                         i * yPosDelta, -j * zPosDelta)
                    obj.setSize(size / (nUniq + 1))
                    obj.setColor(c)

                    if (highlight is not None) and (highlight != i):
                        obj.actor.GetProperty().SetOpacity(0.1)
                    allObj.append(obj)

    for i, u in enumerate(uniques):

        xTick = sO.Line((xPos - i * size / (nUniq), -0.4, 0),
                        (xPos - i * size / (nUniq), -0.6, 0))
        allObj.append(xTick)

        xLabel = sO.Text(f'[{xText}]-{u}')
        xLabel.actor.SetScale(0.1, 0.1, 0.1)
        xLabel.actor.SetPosition(xPos - i * size / (nUniq), -1, 0)
        xLabel.actor.GetProperty().SetColor(0, 0, 0)
        xLabel.actor.RotateZ(-90)
        allObj.append(xLabel)

    xLabel = sO.Text(f'{xText}')
    xLabel.actor.SetScale(0.1, 0.1, 0.1)
    xLabel.actor.SetPosition(xPos - 0.6, -0.8, 0)
    xLabel.actor.GetProperty().SetColor(0, 0, 0)
    allObj.append(xLabel)

    ax = sO.Line((xPos, -0.5, 0),
                 (xPos - (nUniq - 1) * size / (nUniq), -0.5, 0))
    allObj.append(ax)

    return allObj
Ejemplo n.º 7
0
def plot2D(config):

    bgColor = [217 / 255, 211 / 255, 232 / 255]
    # bgColor = [219/255, 225/255, 235/255]

    Npatients = 10

    data = getData()[:Npatients + 1]
    header = data[0]
    data = data[1:]
    site, patient, sex, race = zip(*data)

    N = len(site)

    ren.SetBackground(bgColor)
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    sexColors = colorMapper(sex)
    raceColors = colorMapper(race)
    siteColors = colorMapper(site)

    if config['ohe']:
        for m in listToBin(sex, posDelta=0.4, startPos=4, startStr='sex'):
            ren.AddActor(m.actor)

        for m in listToBin(race, posDelta=0.4, startPos=5, startStr='race'):
            ren.AddActor(m.actor)

    # Render the x-axes
    ax1 = sO.Line((1, -0.5, 0), (3, -0.5, 0))
    ren.AddActor(ax1.actor)
    for i in range(3):
        ax1 = sO.Line((i + 1, -0.4, 0), (i + 1, -0.6, 0))
        ren.AddActor(ax1.actor)

    # Render the y-axes
    ax1 = sO.Line((0, 0, 0), (0, (Npatients - 1) * 0.5, 0))
    ren.AddActor(ax1.actor)
    for i in range(Npatients):
        ax1 = sO.Line((-0.1, i * 0.5, 0), (0.1, i * 0.5, 0))
        ren.AddActor(ax1.actor)

    for patient in range(Npatients):

        # Set the names for the patients
        myText = sO.Text(f'p_{patient:04d}')
        myText.actor.SetScale(0.1, 0.1, 0.1)
        myText.actor.SetPosition(-1, patient * 0.5, 0)
        myText.actor.GetProperty().SetColor(0, 0, 0)
        ren.AddActor(myText.actor)

        # set the cohort values
        cohort = sO.Sphere()
        cohort.actor.SetScale(0.3)
        cohort.actor.SetPosition(1, patient * 0.5, 0)
        cohort.setColor((0, 1, 0))
        ren.AddActor(cohort.actor)

        # set the sex values
        sex = sO.Cube()
        sex.source.SetCenter(2, patient * 0.5, 0)
        sex.setSize(0.3)
        sex.setColor(sexColors[patient])
        ren.AddActor(sex.actor)

        # set the race values
        race = sO.Cube()
        race.source.SetCenter(3, patient * 0.5, 0)
        race.setSize(0.3)
        race.setColor(raceColors[patient])
        ren.AddActor(race.actor)

    # Set the names for the axes
    for pos, dataType in enumerate(['cohort', 'sex ', 'race']):
        myText = sO.Text(f'{dataType}')
        myText.actor.SetScale(0.1, 0.1, 0.1)
        myText.actor.SetPosition(pos + 0.8, -1, 0)
        myText.actor.GetProperty().SetColor(0, 0, 0)
        ren.AddActor(myText.actor)

    renWin.SetSize(900, 900)
    renWin.SetWindowName('Cylinder')

    iren.AddObserver("KeyPressEvent", Keypress)
    iren.Initialize()

    ren.ResetCamera()
    restoreCammeraSpecs('../results/cameraPos/latest2D.json')
    renWin.Render()

    # Start the event loop.
    iren.Start()

    return