Ejemplo n.º 1
0
def render_probe_3d(rsites: pd.DataFrame,
                    save_path: Path = None,
                    targets: tuple = None):
    targets = list(targets) or []

    # create brainrender scene
    scene = br.Scene(screenshots_folder=save_path)

    # add probe track
    track = np.vstack(rsites.registered_brain_coordinates.values)
    colors = [
        color if region in targets else
        (blue_grey if region not in ('unknown', 'OUT') else 'k')
        for color, region in zip(rsites.color.values,
                                 rsites.brain_region.values)
    ]
    pts = scene.add(br.actors.Points(track, colors=colors, radius=15))
    scene.add_silhouette(pts, lw=2)

    # add brain regions
    for region in rsites.brain_region.unique():
        if region in targets:
            alpha = 0.4
            targets.pop(targets.index(region))
        else:
            alpha = 0.01
        scene.add_brain_region(region, alpha=alpha)

    # add remainning targets
    if targets:
        scene.add_brain_region(*targets, alpha=0.4)

    # slice
    plane = scene.atlas.get_plane(norm=(0, 0, 1),
                                  pos=scene.root._mesh.centerOfMass())
    scene.slice(plane)

    # render
    cam = {
        "pos": (7196, 247, -38602),
        "viewup": (0, -1, 0),
        "clippingRange": (29133, 44003),
        "focalPoint": (7718, 4290, -3507),
        "distance": 35331,
    }

    if save_path is None:
        scene.render(camera=cam)
    else:
        scene.render(camera=cam, interactive=False)
        scene.screenshot("activity_probe_rendering")
    scene.close()
    del scene
Ejemplo n.º 2
0
from brainrender.atlas_specific import get_streamlines_for_region
from brainrender.actors.streamlines import make_streamlines

SELECTED = "locomotion"


save_folder = Path(
    "/Users/federicoclaudi/Dropbox (UCL)/Rotation_vte/Presentations/Presentations/Fiete lab"
)


br.settings.SHOW_AXES = False
br.settings.vsettings.screenshotTransparentBackground - True


scene = br.Scene(screenshots_folder=save_folder, inset=False)

scene.add_brain_region("RSP", alpha=1)
scene.add_brain_region("MOs", alpha=0.2)

streams = get_streamlines_for_region("RSP")[:2]
scene.add(
    *make_streamlines(
        *streams,
        color=scene.atlas._get_from_structure("RSP", "rgb_triplet"),
        alpha=0.5,
    )
)

camera = {
    "pos": (-6374, -5444, 26602),
Ejemplo n.º 3
0
br.settings.SHOW_AXES = False
br.settings.ROOT_ALPHA = 0.1

probes_folder = Path(
    r"D:\Dropbox (UCL)\Rotation_vte\Locomotion\reconstructed_probe_location")
probes_files = files(probes_folder, pattern="*_0.npy")

save_folder = Path(
    r"D:\Dropbox (UCL)\Rotation_vte\Presentations\Presentations\Fiete lab")

colors = make_palette(blue_grey_dark, blue_grey_light, len(probes_files))

# ----------------------------- create renderings ---------------------------- #
for repeat in range(3):
    # scene and brain regions
    scene = br.Scene(inset=False, screenshots_folder=save_folder)

    scene.add_brain_region("CUN", "GRN", "PPN", alpha=0.9)

    # add probes
    for n, probe in enumerate(probes_files):
        coords = np.load(probe)
        probe_actor = scene.add(
            br.actors.Points(coords[::4, :], colors=colors[n], radius=60))
        # scene.add_silhouette(probe_actor, lw=.5)

    # slice
    if repeat == 2:
        plane = scene.atlas.get_plane(norm=(0, 0, -1),
                                      pos=scene.root._mesh.centerOfMass())
        camera = "sagittal"
Ejemplo n.º 4
0
def render_probe_regions_slices(rsites: pd.DataFrame,
                                save_path: Path = None,
                                targets: tuple = None):
    targets = list(targets) if targets is not None else []

    for target_region in rsites.brain_region.unique():
        for side in ("frontal", "sagittal2", "top"):
            scene_targets = targets.copy()
            scene = br.Scene(title=target_region, screenshots_folder=save_path)

            # add probe track
            track = np.vstack(rsites.registered_brain_coordinates.values)
            track_actor = scene.add(
                br.actors.Points(track, colors="k", radius=80))

            # add brain regions
            actors = [track_actor]
            for region in rsites.brain_region.unique():
                if region == target_region:
                    alpha = 0.9
                elif region in scene_targets:
                    scene_targets.pop(scene_targets.index(region))
                    alpha = 0.5
                else:
                    alpha = 0.05

                act = scene.add_brain_region(region, alpha=alpha)
                if act is not None:
                    actors.append(act)

            # add remaining target regions
            if scene_targets:
                actors.extend(scene.add_brain_region(*scene_targets,
                                                     alpha=0.4))

            # slice
            coords = np.mean(
                np.vstack(rsites.loc[rsites.brain_region == target_region].
                          registered_brain_coordinates.values),
                axis=0,
            )
            if side == "frontal":
                shift = np.array([250, 0, 0])
            elif side == "top":
                shift = np.array([0, 250, 0])
            else:
                coords[2] = -coords[2]
                shift = np.array([0, 0, 500])
            p1 = coords - shift
            p2 = coords + shift

            for p, norm in zip((p1, p2), (1, -1)):
                if side == "frontal":
                    nrm = (norm, 0, 0)
                elif side == "top":
                    nrm = (0, norm, 0)
                else:
                    nrm = (0, 0, norm)
                plane = scene.atlas.get_plane(pos=p, norm=nrm)
                scene.slice(plane, actors=actors, close_actors=True)
                scene.slice(plane, actors=scene.root, close_actors=False)

            # show/save
            if save_path is None:
                scene.render(camera=side)
            else:
                scene.render(camera=side, interactive=False)
                scene.screenshot(
                    f"activity_probe_slice_{target_region}_{side}")
            scene.close()
            del scene
probes_folder = Path(
    r"D:\Dropbox (UCL)\Rotation_vte\Locomotion\reconstructed_probe_location")

colors = {
    '1100279_0': grey,
    '1100281_0': grey_dark,
    '1100516_0': indigo,
    '1110750_0': green,
    '1110751_0': black,
}

["k", "b", "r", "m", green]

# scene and brain regions
scene = br.Scene()

scene.add_brain_region("CUN", "GRN", alpha=.88)
scene.add_brain_region("IC",
                       "PRNr",
                       "PRNc",
                       "SCm",
                       alpha=0.25,
                       silhouette=False)
scene.add_brain_region("PPN", alpha=0.8, silhouette=False)
# add probes
for n, probe in enumerate(files(probes_folder, pattern="*_0.npy")):
    coords = np.load(probe)
    probe_actor = scene.add(
        br.actors.Points(coords, colors=colors[probe.stem], radius=40))
    logger.info(
Ejemplo n.º 6
0
#Associating BrainR Regions with their values
for month in range(0, len(tp)):
    brainR.insert(3 + month, "Val_MPI{}".format(tp[month]), "")
    for idx, regions in enumerate(brainR["ROInames"]):
        brainR['Val_MPI{}'.format(
            tp[month])][idx] = data.loc[regions, "MPI{}".format(tp[month])]

###Still need ==> to implement this for each month
# Ipsilateral Data
ipsi_pred = brainR[brainR['Side'] == 'ipsi']

# Contralateral Data
contra_pred = brainR[brainR['Side'] == 'contra']

#BrainRenders
ipsi_pred_mpi1 = ipsi_pred[["BrainR", "Val_MPI1"]]
contra_pred_mpi1 = contra_pred[["BrainR", "Val_MPI1"]]

scene = brainrender.Scene(atlas_name="allen_mouse_10um")

#Adding the ipsilateral regions

for reg in contra_pred_mpi1.index:
    region = contra_pred_mpi1.loc[reg, 'BrainR']
    color = cmap(contra_pred_mpi1.loc[reg, 'Val_MPI1'])[:3]
    scene.add_brain_region(reg, color=color, alpha=0.5)
# #scene.axes_indices(None)
scene.render()

#Adding the controlateral regions