Exemplo n.º 1
0
def render(input_polydata, number_of_fibers=None, opacity=1, depth_peeling=False, scalar_bar=False, axes=False, scalar_range=None, data_mode="Cell", tube=True, colormap='jet', data_name=None, verbose=True):
    """ Function for easy matlab-like use of the rendering
    functionality.


    Returns RenderPolyData object which can be used directly for more
    functionality."""

    if verbose:
        print "<render.py> Initiating rendering."
        
    if number_of_fibers is not None:
        if verbose:
            print "<render.py> Downsampling vtkPolyData:", number_of_fibers
        # downsample if requested
        input_polydata = filter.downsample(input_polydata, number_of_fibers, preserve_point_data=True, preserve_cell_data=True, verbose=verbose)

    if data_name is not None:
        if verbose:
            print "<render.py> Visualizing data:", data_name
        if data_mode == "Cell":
            input_polydata.GetCellData().SetActiveScalars(data_name)
        if data_mode == "Point":
            input_polydata.GetPointData().SetActiveScalars(data_name)

    ren = RenderPolyData()
    
    ren.render_polydata(input_polydata, opacity=opacity, depth_peeling=depth_peeling, scalar_bar=scalar_bar, axes=axes, scalar_range=scalar_range, data_mode=data_mode, tube=tube, colormap=colormap, verbose=verbose)

    if verbose:
        print "<render.py> Render pipeline created."
    return ren
Exemplo n.º 2
0
def rdmat(fn, samprds=0):
    fp = h5py.File(fn, 'r')  # open the .mat / HDF5 formatted data
    sampr = fp['craw']['adrate'][0][0]  # sampling rate
    print('fn:', fn, 'sampr:', sampr, 'samprds:', samprds)
    dt = 1.0 / sampr  # time-step in seconds
    dat = fp['craw']['cnt']  # cnt record stores the electrophys data
    npdat = np.zeros(dat.shape)
    tmax = (
        len(npdat) - 1.0
    ) * dt  # use original sampling rate for tmax - otherwise shifts phase
    dat.read_direct(
        npdat
    )  # read it into memory; note that this LFP data usually stored in microVolt
    npdat *= 0.001  # convert microVolt to milliVolt here
    fp.close()
    if samprds > 0.0:  # resample the LFPs
        dsfctr = sampr / samprds
        dt = 1.0 / samprds
        siglen = max((npdat.shape[0], npdat.shape[1]))
        nchan = min((npdat.shape[0], npdat.shape[1]))
        npds = []  # zeros((int(siglen/float(dsfctr)),nchan))
        # print dsfctr, dt, siglen, nchan, samprds, ceil(int(siglen / float(dsfctr))), npds.shape
        for i in range(nchan):
            print('resampling channel', i)
            npds.append(downsample(npdat[:, i], sampr, samprds))
        npdat = np.array(npds)
        npdat = npdat.T
        sampr = samprds
    tt = np.linspace(0, tmax, len(npdat))  # time in seconds
    return sampr, npdat, dt, tt  # npdat is LFP in units of milliVolt
Exemplo n.º 3
0
def render(input_polydata,
           number_of_fibers=None,
           opacity=1,
           depth_peeling=False,
           scalar_bar=False,
           axes=False,
           scalar_range=None,
           data_mode="Cell",
           tube=True,
           colormap='jet',
           data_name=None,
           verbose=True):
    """ Function for easy matlab-like use of the rendering
    functionality.


    Returns RenderPolyData object which can be used directly for more
    functionality."""

    if verbose:
        print "<render.py> Initiating rendering."

    if number_of_fibers is not None:
        if verbose:
            print "<render.py> Downsampling vtkPolyData:", number_of_fibers
        # downsample if requested
        input_polydata = filter.downsample(input_polydata,
                                           number_of_fibers,
                                           preserve_point_data=True,
                                           preserve_cell_data=True,
                                           verbose=verbose)

    if data_name is not None:
        if verbose:
            print "<render.py> Visualizing data:", data_name
        if data_mode == "Cell":
            input_polydata.GetCellData().SetActiveScalars(data_name)
        if data_mode == "Point":
            input_polydata.GetPointData().SetActiveScalars(data_name)

    ren = RenderPolyData()

    ren.render_polydata(input_polydata,
                        opacity=opacity,
                        depth_peeling=depth_peeling,
                        scalar_bar=scalar_bar,
                        axes=axes,
                        scalar_range=scalar_range,
                        data_mode=data_mode,
                        tube=tube,
                        colormap=colormap,
                        verbose=verbose)

    if verbose:
        print "<render.py> Render pipeline created."
    return ren
Exemplo n.º 4
0
def read_and_preprocess_polydata_directory(input_dir,
                                           fiber_length,
                                           number_of_fibers,
                                           random_seed=None,
                                           fiber_length_max=None):
    """ Find and read all .vtk and .vtp files in the given directory
    input_dir. Preprocess with fiber length threshold and downsample
    to desired number of fibers."""

    input_pd_fnames = list_vtk_files(input_dir)
    num_pd = len(input_pd_fnames)

    print "<io.py> ======================================="
    print "<io.py> Reading vtk and vtp files from directory: ", input_dir
    print "<io.py> Total number of files found: ", num_pd
    print "<io.py> ======================================="

    input_pds = list()
    subject_ids = list()
    sidx = 0

    for fname in input_pd_fnames:
        subject_id = os.path.splitext(os.path.basename(fname))[0]
        subject_ids.append(subject_id)
        print "<io.py>  ", sidx + 1, "/", num_pd, subject_id, " Reading ", fname, "..."
        pd = read_polydata(fname)
        print "<io.py>  ", sidx + 1, "/", num_pd, subject_id, " Input number of fibers:", pd.GetNumberOfLines(
        )
        pd2 = filter.preprocess(pd,
                                min_length_mm=fiber_length,
                                verbose=False,
                                max_length_mm=fiber_length_max)
        print "<io.py>  ", sidx + 1, "/", num_pd, subject_id, " Length threshold", fiber_length, "mm. Number of fibers retained:", pd2.GetNumberOfLines(
        )
        pd3 = filter.downsample(pd2,
                                number_of_fibers,
                                verbose=False,
                                random_seed=random_seed)
        print "<io.py>  ", sidx + 1, "/", num_pd, subject_id, " Downsample to", number_of_fibers, "fibers. Number of fibers retained:", pd3.GetNumberOfLines(
        )
        input_pds.append(pd3)
        sidx += 1
        print "<io.py> ======================================="

    print "<io.py> ======================================="
    print "<io.py> Done reading vtk and vtp files from directory: ", input_dir
    print "<io.py> Total number of files read: ", len(input_pds)
    print "<io.py> ======================================="

    return input_pds, subject_ids
Exemplo n.º 5
0
def render(input_polydata, number_of_fibers=None, opacity=1, depth_peeling=False, scalar_bar=False, axes=False, scalar_range=None, data_mode="Cell", tube=True, colormap='jet'):
    """ Function for easy matlab-like use of the rendering
    functionality.


    Returns RenderPolyData object which can be used directly for more
    functionality."""

    print "<render.py> Initiating rendering."
        
    if number_of_fibers is not None:
        print "<render.py> Downsampling vtkPolyData:", number_of_fibers
        # downsample if requested
        input_polydata = filter.downsample(input_polydata, number_of_fibers)

    ren = RenderPolyData()
    
    ren.render_polydata(input_polydata, opacity=opacity, depth_peeling=depth_peeling, scalar_bar=scalar_bar, axes=axes, scalar_range=scalar_range, data_mode=data_mode, tube=tube, colormap=colormap)

    print "<render.py> Render pipeline created."
    return ren
Exemplo n.º 6
0
def read_and_preprocess_polydata_directory(input_dir, fiber_length, number_of_fibers):
    """ Find and read all .vtk and .vtp files in the given directory
    input_dir. Preprocess with fiber length threshold and downsample
    to desired number of fibers."""
    
    input_pd_fnames = list_vtk_files(input_dir)
    num_pd = len(input_pd_fnames)
    
    print "<io.py> ======================================="
    print "<io.py> Reading vtk and vtp files from directory: ", input_dir
    print "<io.py> Total number of files found: ", num_pd
    print "<io.py> ======================================="

    input_pds = list()
    subject_ids = list()
    sidx = 0

    for fname in input_pd_fnames:
        subject_id = os.path.splitext(os.path.basename(fname))[0]
        subject_ids.append(subject_id)
        print "<io.py>  ", sidx + 1, "/",  num_pd, subject_id, " Reading ", fname, "..."
        pd = read_polydata(fname)
        print "<io.py>  ", sidx + 1, "/",  num_pd, subject_id, " Input number of fibers:", pd.GetNumberOfLines()
        pd2 = filter.preprocess(pd, fiber_length)
        print "<io.py>  ", sidx + 1, "/",  num_pd, subject_id, " Length threshold", fiber_length, "mm. Number of fibers retained:", pd2.GetNumberOfLines()
        pd3 = filter.downsample(pd2, number_of_fibers)
        print "<io.py>  ", sidx + 1, "/",  num_pd, subject_id, " Downsample to", number_of_fibers, "fibers. Number of fibers retained:", pd3.GetNumberOfLines()        
        input_pds.append(pd3)
        sidx += 1
        print "<io.py> ======================================="

    print "<io.py> ======================================="
    print "<io.py> Done reading vtk and vtp files from directory: ", input_dir
    print "<io.py> Total number of files read: ", len(input_pds)
    print "<io.py> ======================================="
        
    return input_pds, subject_ids