当前位置: 首页>>代码示例>>Python>>正文


Python utils.set_array函数代码示例

本文整理汇总了Python中tomviz.utils.set_array函数的典型用法代码示例。如果您正苦于以下问题:Python set_array函数的具体用法?Python set_array怎么用?Python set_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了set_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: transform_scalars

def transform_scalars(dataset):
    """Delete Slices in Dataset"""
    
    from tomviz import utils
    import numpy as np
    axis = 0;
    #----USER SPECIFIED VARIABLES-----#
    ###firstSlice###
    ###lastSlice###
    ###axis### #Axis along which to delete the subarray
    #---------------------------------#
    
    #get current dataset
    array = utils.get_array(dataset)
    
    #Get indices of the slices to be deleted
    indices = np.linspace(firstSlice,lastSlice,lastSlice-firstSlice+1).astype(int)

    # delete slices
    array = np.delete(array,indices,axis)

    #set the result as the new scalars.
    utils.set_array(dataset, array)

    #Delete corresponding tilt anlges if dataset is a tilt series
    if axis == 2:
        try:
            tilt_angles = utils.get_tilt_angles(dataset)
            tilt_angles = np.delete(tilt_angles,indices)
            utils.set_tilt_angles(dataset, tilt_angles)
        except:
            pass
开发者ID:coldatom,项目名称:tomviz,代码行数:32,代码来源:deleteSlices.py

示例2: transform_scalars

    def transform_scalars(self, dataset, N=25):
        """Add Poisson noise to tilt images"""
        self.progress.maximum = 1

        tiltSeries = utils.get_array(dataset).astype(float)
        if tiltSeries is None:
            raise RuntimeError("No scalars found!")

        Ndata = tiltSeries.shape[0] * tiltSeries.shape[1]

        self.progress.maximum = tiltSeries.shape[2]
        step = 0
        for i in range(tiltSeries.shape[2]):
            if self.canceled:
                return

            tiltImage = tiltSeries[:, :, i].copy()
            tiltImage = tiltImage / np.sum(tiltSeries[:, :, i]) * (Ndata * N)
            tiltImage = np.random.poisson(tiltImage)
            tiltImage = tiltImage * np.sum(tiltSeries[:, :, i]) / (Ndata * N)

            tiltSeries[:, :, i] = tiltImage.copy()
            step += 1
            self.progress.value = step

        utils.set_array(dataset, tiltSeries)
开发者ID:OpenChemistry,项目名称:tomviz,代码行数:26,代码来源:AddPoissonNoise.py

示例3: transform_scalars

def transform_scalars(dataset, firstSlice=None, lastSlice=None, axis=2):
    """Delete Slices in Dataset"""

    from tomviz import utils
    import numpy as np

    # Get the current dataset.
    array = utils.get_array(dataset)

    # Get indices of the slices to be deleted.
    indices = np.linspace(firstSlice, lastSlice,
                          lastSlice - firstSlice + 1).astype(int)

    # Delete the specified slices.
    array = np.delete(array, indices, axis)

    # Set the result as the new scalars.
    utils.set_array(dataset, array)

    # Delete corresponding tilt anlges if dataset is a tilt series.
    if axis == 2:
        try:
            tilt_angles = utils.get_tilt_angles(dataset)
            tilt_angles = np.delete(tilt_angles, indices)
            utils.set_tilt_angles(dataset, tilt_angles)
        except: # noqa
            # TODO what exception are we ignoring here?
            pass
开发者ID:OpenChemistry,项目名称:tomviz,代码行数:28,代码来源:deleteSlices.py

示例4: transform_scalars

def transform_scalars(dataset):
    """3D Reconstruct from a tilt series using Weighted Back-projection Method"""
    
    from tomviz import utils
    import numpy as np
    interpolation_methods = ('linear','nearest','spline','cubic')
    filter_methods = ('none','ramp','shepp-logan','cosine','hamming','hann')

    ###Nrecon###
    ###filter###
    ###interp###
    
    #Get Tilt angles
    tilt_angles = utils.get_tilt_angles(dataset)
    
    data_py = utils.get_array(dataset)
    if data_py is None:
        raise RuntimeError("No scalars found!")

    recon = wbp3(data_py,tilt_angles,Nrecon,filter_methods[filter],interpolation_methods[interp])
    print('Reconsruction Complete')

    # set the result as the new scalars.
    utils.set_array(dataset, recon)
    
    # Mark dataset as volume
    utils.mark_as_volume(dataset)
开发者ID:LijieTu,项目名称:tomviz,代码行数:27,代码来源:Recon_WBP.py

示例5: transform_scalars

def transform_scalars(dataset, threshold=None):
    """Remove bad pixels in tilt series."""

    from tomviz import utils
    import scipy.ndimage
    import numpy as np

    tiltSeries = utils.get_array(dataset).astype(np.float32)

    for i in range(tiltSeries.shape[2]):
        I = tiltSeries[:, :, i]
        I_pad = np.lib.pad(I, (1, 1), 'edge')

        # calculate standard deviation in a 3 x 3 window
        averageI2 = scipy.ndimage.filters.uniform_filter(I_pad ** 2)
        averageI = scipy.ndimage.filters.uniform_filter(I_pad)
        std = np.sqrt(abs(averageI2 - averageI**2))[1:-1, 1:-1]

        medianI = scipy.ndimage.filters.median_filter(I_pad, 2)[1:-1, 1:-1]

        #identiy bad pixels
        badPixelsMask = abs(I - medianI) > std * threshold

        I[badPixelsMask] = medianI[badPixelsMask]
        tiltSeries[:, :, i] = I

    # Set the result as the new scalars.
    utils.set_array(dataset, tiltSeries)
开发者ID:OpenChemistry,项目名称:tomviz,代码行数:28,代码来源:RemoveBadPixelsTiltSeries.py

示例6: transform_scalars

def transform_scalars(dataset, clipNum=5):
    """Set values outside a cirular range to minimum(dataset) to
    remove reconstruction artifacts"""

    from tomviz import utils
    import numpy as np

    array = utils.get_array(dataset)

    # Constant values
    numX = array.shape[1]
    numY = array.shape[2]
    minVal = array.min()

    # Find the values to be clipped
    maxR = min([numX, numY]) / 2 - clipNum
    XX, YY = np.mgrid[0:numX, 0:numY]
    RR = np.sqrt((XX - numX / 2) ** 2 + (YY - numY / 2) ** 2)
    clipThese = np.where(RR >= maxR)

    # Apply the mask along the original tilt axis direction
    # (always the first direction in the array)
    for ii in range(0, array.shape[0]):
        curImage = array[ii, :, :] # points to the relevant 2D part of the array
        curImage[clipThese] = minVal

    # Return to tomviz
    utils.set_array(dataset, array)
开发者ID:OpenChemistry,项目名称:tomviz,代码行数:28,代码来源:ClipEdges.py

示例7: set_array_from_itk_image

def set_array_from_itk_image(dataset, itk_image):
    """Set dataset array from an ITK image."""

    itk_output_image_type = type(itk_image)

    # Save the VTKGlue optimization for later
    #------------------------------------------
    # Export the ITK image to a VTK image. No copying should take place.
    #export_filter = itk.ImageToVTKImageFilter[itk_output_image_type].New()
    #export_filter.SetInput(itk_image_data)
    #export_filter.Update()

    # Get scalars from the temporary image and copy them to the data set
    #result_image = export_filter.GetOutput()
    #filter_array = result_image.GetPointData().GetArray(0)

    # Make a new instance of the array that will stick around after this
    # filters in this script are garbage collected
    #new_array = filter_array.NewInstance()
    #new_array.DeepCopy(filter_array) # Should be able to shallow copy?
    #new_array.SetName(name)
    #------------------------------------------
    import itk
    from . import utils
    result = itk.PyBuffer[
        itk_output_image_type].GetArrayFromImage(itk_image)
    result = result.copy()
    utils.set_array(dataset, result, isFortran=False)
开发者ID:cryos,项目名称:tomviz,代码行数:28,代码来源:itkutils.py

示例8: transform_scalars

def transform_scalars(dataset):
    """Pad dataset"""
    from tomviz import utils
    import numpy as np
    
    #----USER SPECIFIED VARIABLES-----#
    ###padWidthX###
    ###padWidthY###
    ###padWidthZ###
    ###padMode_index###
    #---------------------------------#
    padModes = ['constant','edge','wrap','minimum','median']
    padMode = padModes[padMode_index]
    array = utils.get_array(dataset) #get data as numpy array
    
    if array is None: #Check if data exists
        raise RuntimeError("No data array found!")
    
    pad_width = (padWidthX,padWidthY,padWidthZ)

    # pad the data.
    array = np.lib.pad(array, pad_width, padMode)

    # Set the data so that it is visible in the application.
    utils.set_array(dataset, array)

    # If dataset is marked as tilt series, update tilt angles
    if padWidthZ[0]+padWidthZ[1] >0:
        try:
            tilt_angles = utils.get_tilt_angles(dataset)
            tilt_angles = np.lib.pad(tilt_angles,padWidthZ, padMode)
            utils.set_tilt_angles(dataset, tilt_angles)
        except:
            pass
开发者ID:happy-fish,项目名称:tomviz,代码行数:34,代码来源:Pad_Data.py

示例9: transform_scalars

def transform_scalars(dataset):
    """Downsample volume by a factor of 2"""

    from tomviz import utils
    import scipy.ndimage
    import numpy as np

    array = utils.get_array(dataset)

    # Downsample the dataset x2 using order 1 spline (linear)
    # Calculate out array shape
    zoom = (0.5, 0.5, 0.5)
    result_shape = utils.zoom_shape(array, zoom)
    result = np.empty(result_shape, array.dtype, order='F')
    scipy.ndimage.interpolation.zoom(array, zoom,
                                     output=result, order=1,
                                     mode='constant', cval=0.0,
                                     prefilter=False)

    # Set the result as the new scalars.
    utils.set_array(dataset, result)

    # Update tilt angles if dataset is a tilt series.
    try:
        tilt_angles = utils.get_tilt_angles(dataset)
        result_shape = utils.zoom_shape(tilt_angles, 0.5)
        result = np.empty(result_shape, array.dtype, order='F')
        tilt_angles = scipy.ndimage.interpolation.zoom(tilt_angles, 0.5,
                                                       output=result)
        utils.set_tilt_angles(dataset, result)
    except: # noqa
        # TODO What exception are we ignoring?
        pass
开发者ID:OpenChemistry,项目名称:tomviz,代码行数:33,代码来源:BinVolumeByTwo.py

示例10: transform_scalars

def transform_scalars(dataset):
    from tomviz import utils
    import numpy as np

    #----USER SPECIFIED VARIABLES-----#
    TILT_AXIS  = []  #Specify the tilt axis, if none is specified
                     #it assume it is the smallest dimension
    ANGLES = []  #Specify the angles used in the tiltseries 
                 #For example, ANGLES = np.linspace(0,140,70)
    #---------------------------------#

    data_py = utils.get_array(dataset)
    if data_py is None:
        raise RuntimeError("No scalars found!")
        
    if TILT_AXIS == []: #If tilt axis is not given, find it
    #Find smallest array dimension, assume it is the tilt angle axis
        if data_py.ndim == 3:
            TILT_AXIS = np.argmin( data_py.shape )
        elif data_py.ndim == 2:
            raise RuntimeError("Data Array is 2 dimensions, it should be 3!")
        else: 
            raise RuntimeError("Data Array is not 2 or 3 dimensions!")
    
    if ANGLES == []: #If angles are not given, assume 2 degree tilts
        angles = np.linspace(0,146,74)
        
    dimx = np.size(data_py,0) #IN THE FUTURE THIS SHOULD NOT BE ASSUMED
    result3D = dfm3(data_py,angles,dimx)
    
    # set the result as the new scalars.
    utils.set_array(dataset, result3D)
    print('Reconsruction Complete')
开发者ID:ElliotPadgett,项目名称:tomviz,代码行数:33,代码来源:Recon_DFT.py

示例11: transform_scalars

def transform_scalars(dataset):
    """Resample dataset"""

    from tomviz import utils
    import numpy as np
    import scipy.ndimage

    #----USER SPECIFIED VARIABLES-----#
    #resampingFactor  = [1,1,1]  #Specify the shifts (x,y,z) applied to data
    ###resampingFactor###
    #---------------------------------#
    array = utils.get_array(dataset)

    # Transform the dataset.
    result = scipy.ndimage.interpolation.zoom(array, resampingFactor)
    
    # Set the result as the new scalars.
    utils.set_array(dataset, result)

    # Update tilt angles if dataset is a tilt series.
    if resampingFactor[2] != 1:
        try:
            tilt_angles = utils.get_tilt_angles(dataset)
            tilt_angles = scipy.ndimage.interpolation.zoom(tilt_angles, resampingFactor[2])
            utils.set_tilt_angles(dataset, tilt_angles)
        except:
            pass
开发者ID:happy-fish,项目名称:tomviz,代码行数:27,代码来源:Resample.py

示例12: transform_scalars

def transform_scalars(dataset, SHIFT=None, rotation_angle=90.0):
    from tomviz import utils
    from scipy import ndimage
    import numpy as np

    data_py = utils.get_array(dataset) # Get data as numpy array.

    if data_py is None: #Check if data exists
        raise RuntimeError("No data array found!")
    if SHIFT is None:
        SHIFT = np.zeros(len(data_py.shape), dtype=np.int)
    data_py_return = np.empty_like(data_py)
    ndimage.interpolation.shift(data_py, SHIFT, order=0, output=data_py_return)

    rotation_axis = 2 # This operator always assumes the rotation axis is Z
    if rotation_angle == []: # If tilt angle not given, assign it to 90 degrees.
        rotation_angle = 90

    axis1 = (rotation_axis + 1) % 3
    axis2 = (rotation_axis + 2) % 3
    axes = (axis1, axis2)
    shape = utils.rotate_shape(data_py_return, rotation_angle, axes=axes)
    data_py_return2 = np.empty(shape, data_py_return.dtype, order='F')
    ndimage.interpolation.rotate(
        data_py_return, rotation_angle, output=data_py_return2, axes=axes)

    utils.set_array(dataset, data_py_return2)
开发者ID:OpenChemistry,项目名称:tomviz,代码行数:27,代码来源:RotationAlign.py

示例13: transform_scalars

def transform_scalars(dataset):
    """3D Reconstruct from a tilt series using constraint-based Direct Fourier Method"""

    from tomviz import utils
    import numpy as np
    ###Niter###
    ###Niter_update_support###
    ###supportSigma###
    ###supportThreshold### #percent
    supportThreshold = supportThreshold/100.0
    
    nonnegativeVoxels = True
    tilt_angles = utils.get_tilt_angles(dataset) #Get Tilt angles

    tilt_images = utils.get_array(dataset)
    if tilt_images is None:
        raise RuntimeError("No scalars found!")

    #Direct Fourier recon without constraints
    (recon,recon_F) = dfm3(tilt_images,tilt_angles,np.size(tilt_images,0)*2)

    kr_cutoffs = np.linspace(0.05,0.5,10);
    I_data = radial_average(tilt_images,kr_cutoffs) #average Fourier magnitude of tilt series as a function of kr

    #Search for solutions that satisfy additional constraints
    recon = difference_map_update(recon_F,nonnegativeVoxels,I_data,kr_cutoffs,Niter,Niter_update_support,supportSigma,supportThreshold)

    print('Reconsruction Complete')

    # Set the result as the new scalars.
    utils.set_array(dataset, recon)

    # Mark dataset as volume
    utils.mark_as_volume(dataset)
开发者ID:happy-fish,项目名称:tomviz,代码行数:34,代码来源:Recon_DFT_constraint.py

示例14: transform_scalars

def transform_scalars(dataset):
    '''For each tilt image, the method uses average pixel value of selected region
      as the background level and subtracts it from the image.'''
    '''It does NOT set negative pixels to zero.'''

    from tomviz import utils
    import numpy as np

    #----USER SPECIFIED VARIABLES-----#
    ###XRANGE###
    ###YRANGE###
    ###ZRANGE###
    #---------------------------------#

    data_bs = utils.get_array(dataset) # Get data as numpy array.

    data_bs = data_bs.astype(np.float32) # Change tilt series type to float.

    if data_bs is None: #Check if data exists
        raise RuntimeError("No data array found!")    

    for i in range(ZRANGE[0],ZRANGE[1]):
        a = data_bs[:,:,i] - np.average(data_bs[XRANGE[0]:XRANGE[1],YRANGE[0]:YRANGE[1],i])
        data_bs[:,:,i] = a

    utils.set_array(dataset, data_bs)
开发者ID:happy-fish,项目名称:tomviz,代码行数:26,代码来源:Subtract_TiltSer_Background.py

示例15: transform_scalars

def transform_scalars(dataset):
    """Generate Tilt Series from Volume"""
    
    from tomviz import utils
    import numpy as np
    import scipy.ndimage
    
    
    #----USER SPECIFIED VARIABLES-----#
    ###startAngle###    #Starting angle
    ###angleIncrement###   #Angle increment
    ###Nproj### #Number of tilts
    #---------------------------------#
    
    # Generate Tilt Angles
    angles = np.linspace(startAngle,startAngle+(Nproj-1)*angleIncrement,Nproj);
    
    array = utils.get_array(dataset)
    N = array.shape[0];
    Nslice = array.shape[2]; #Number of slices along rotation axis
    tiltSeries = np.zeros((Nslice, N ,Nproj))
    for i in range(Nproj):
        #Rotate volume
        rotatedArray = scipy.ndimage.interpolation.rotate(array, angles[i],axes=(0,1),reshape=False)
        #Calculate Projection
        tiltSeries[:,:,i] = np.sum(rotatedArray,axis=0).transpose()

    # set the result as the new scalars.
    utils.set_array(dataset, tiltSeries)

    # Mark dataset as tilt series
    utils.mark_as_tiltseries(dataset)

    # Save tilt angles
    utils.set_tilt_angles(dataset, angles)
开发者ID:coldatom,项目名称:tomviz,代码行数:35,代码来源:TiltSeries.py


注:本文中的tomviz.utils.set_array函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。