Example #1
0
def add_op(volumes,
           onGrid=None,
           boundingGrid=None,
           subregion='all',
           step=1,
           gridSubregion='all',
           gridStep=1,
           inPlace=False,
           scaleFactors=None,
           modelId=None):

    volumes = filter_volumes(volumes)
    if boundingGrid is None and not inPlace:
        boundingGrid = (onGrid is None)
    if onGrid is None:
        onGrid = volumes[:1]
    onGrid = filter_volumes(onGrid, 'onGrid')
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    if inPlace:
        if boundingGrid or gridStep != 1 or gridSubregion != 'all':
            raise CommandError, "Can't use inPlace option with boundingGrid or gridStep or gridSubregion options"
        for gv in onGrid:
            if not gv.data.writable:
                raise CommandError, "Can't modify volume in place: %s" % gv.name
            if not gv in volumes:
                raise CommandError, "Can't change grid in place"
    if isinstance(scaleFactors, basestring):
        scaleFactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    modelId = parse_model_id(modelId)
    for gv in onGrid:
        add_operation(volumes, subregion, step, gv, gridSubregion, gridStep,
                      boundingGrid, inPlace, scaleFactors, modelId)
Example #2
0
def add_op(volumes, onGrid = None, boundingGrid = None,
           subregion = 'all', step = 1,
           gridSubregion = 'all', gridStep = 1,
           inPlace = False, scaleFactors = None, modelId = None):

    volumes = filter_volumes(volumes)
    if boundingGrid is None and not inPlace:
        boundingGrid = (onGrid is None)
    if onGrid is None:
        onGrid = volumes[:1]
    onGrid = filter_volumes(onGrid, 'onGrid')
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    if inPlace:
        if boundingGrid or gridStep != 1 or gridSubregion != 'all':
            raise CommandError, "Can't use inPlace option with boundingGrid or gridStep or gridSubregion options"
        for gv in onGrid:
            if not gv.data.writable:
                raise CommandError, "Can't modify volume in place: %s" % gv.name
            if not gv in volumes:
                raise CommandError, "Can't change grid in place"
    if isinstance(scaleFactors, basestring):
        scaleFactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    modelId = parse_model_id(modelId)
    for gv in onGrid:
        add_operation(volumes, subregion, step,
                      gv, gridSubregion, gridStep,
                      boundingGrid, inPlace, scaleFactors, modelId)
Example #3
0
def morph_op(volumes, frames = 25, start = 0, playStep = 0.04,
             playDirection = 1, playRange = None, addMode = False,
             constantVolume = False, scaleFactors = None,
             hideOriginalMaps = True, subregion = 'all', step = 1,
             modelId = None):

    volumes = filter_volumes(volumes)
    check_number(frames, 'frames', int, nonnegative = True)
    check_number(start, 'start')
    check_number(playStep, 'playStep', nonnegative = True)
    if playRange is None:
        if addMode:
            prange = (-1.0,1.0)
        else:
            prange = (0.0,1.0)
    else:
        prange = parse_floats(playRange, 'playRange', 2)
    check_number(playDirection, 'playDirection')
    sfactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)
    vs = [tuple(v.matrix_size(step = step, subregion = subregion))
          for v in volumes]
    if len(set(vs)) > 1:
        sizes = ' and '.join([str(s) for s in vs])
        raise CommandError, "Volume grid sizes don't match: %s" % sizes
    from MorphMap import morph_maps
    morph_maps(volumes, frames, start, playStep, playDirection, prange,
               addMode, constantVolume, sfactors,
               hideOriginalMaps, subregion, step, modelId)
Example #4
0
def map_statistics(operation, volume, step=1, subregion='all'):

    from VolumeViewer import Volume
    vlist = [m for m in volume if isinstance(m, Volume)]
    if len(vlist) == 0:
        raise CommandError('No volume specified')

    from Commands import parse_step, parse_subregion
    subregion_arg = subregion
    subregion = parse_subregion(subregion)
    step_arg = step
    step = parse_step(step)

    import VolumeStatistics as VS
    for v in vlist:
        m = v.matrix(step=step, subregion=subregion)
        mean, sd, rms = VS.mean_sd_rms(m)
        descrip = v.name
        if step_arg != 1:
            descrip += ', step %s' % step_arg
        if subregion_arg != 'all':
            descrip += ', subregion %s' % subregion_arg
        msg = '%s: mean = %.5g, SD = %.5g, RMS = %.5g' % (descrip, mean, sd,
                                                          rms)
        VS.message(msg, show_reply_log=True)
Example #5
0
def map_sum(operation, volume, aboveThreshold=None, step=1, subregion='all'):

    from VolumeViewer import Volume
    vlist = [m for m in volume if isinstance(m, Volume)]
    if len(vlist) == 0:
        raise CommandError('No volume specified')

    from Commands import parse_step, parse_subregion
    subregion_arg = subregion
    subregion = parse_subregion(subregion)
    step_arg = step
    step = parse_step(step)

    import numpy
    import VolumeStatistics as VS
    for v in vlist:
        m = v.matrix(step=step, subregion=subregion)
        if aboveThreshold is None:
            s = m.sum(dtype=numpy.float64)
        else:
            ma = (m >= aboveThreshold)
            na = ma.sum(dtype=numpy.int64)
            mt = ma.astype(m.dtype)
            mt *= m
            s = mt.sum(dtype=numpy.float64)
        descrip = v.name
        if step_arg != 1:
            descrip += ', step %s' % step_arg
        if subregion_arg != 'all':
            descrip += ', subregion %s' % subregion_arg
        if not aboveThreshold is None:
            descrip += ', level >= %.5g, npoints %d' % (aboveThreshold, na)
        msg = '%s: sum = %.5g' % (descrip, s)
        VS.message(msg, show_reply_log=True)
Example #6
0
def median_op(volumes, binSize = 3, iterations = 1,
              subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(iterations, 'iterations', positive = True)
    binSize = parse_step(binSize, 'binSize', require_3_tuple = True)
    for b in binSize:
        if b <= 0 or b % 2 == 0:
            raise CommandError, 'Bin size must be positive odd integer, got %d' % b
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from median import median_filter
    for v in volumes:
        median_filter(v, binSize, iterations, step, subregion, modelId)
Example #7
0
def scale_op(volumes,
             shift=0,
             factor=1,
             type=None,
             subregion='all',
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(shift, 'shift')
    check_number(factor, 'factor')
    if not type is None:
        import numpy as n
        types = {
            'int8': n.int8,
            'uint8': n.uint8,
            'int16': n.int16,
            'uint16': n.uint16,
            'int32': n.int32,
            'uint32': n.uint32,
            'float32': n.float32,
            'float64': n.float64,
        }
        if type in types:
            type = types[type]
        else:
            raise CommandError, ('Unknown data value type "%s", use %s' %
                                 (type, ', '.join(types.keys())))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from scale import scaled_volume
    for v in volumes:
        scaled_volume(v, factor, shift, type, step, subregion, modelId)
Example #8
0
def scale_op(volumes, shift = 0, factor = 1, type = None,
              subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(shift, 'shift')
    check_number(factor, 'factor')
    if not type is None:
        import numpy as n
        types = {'int8': n.int8,
                 'uint8': n.uint8,
                 'int16': n.int16,
                 'uint16': n.uint16,
                 'int32': n.int32,
                 'uint32': n.uint32,
                 'float32': n.float32,
                 'float64': n.float64,
                 }
        if type in types:
            type = types[type]
        else:
            raise CommandError, ('Unknown data value type "%s", use %s'
                                 % (type, ', '.join(types.keys())))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from scale import scaled_volume
    for v in volumes:
        scaled_volume(v, factor, shift, type, step, subregion, modelId)
Example #9
0
def cover_op(volumes, atomBox = None, pad = 5.0, 
             box = None, x = None, y = None, z = None,
             fBox = None, fx = None, fy = None, fz = None,
             iBox = None, ix = None, iy = None, iz = None,
             step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(pad, 'pad')

    if not atomBox is None and len(atomBox) == 0:
        raise CommandError, 'No atoms specified'
    box = parse_box(box, x, y, z, 'box', 'x', 'y', 'z')
    fBox = parse_box(fBox, fx, fy, fz, 'fBox', 'fx', 'fy', 'fz')
    iBox = parse_box(iBox, ix, iy, iz, 'iBox', 'ix', 'iy', 'iz')
    bc = len([b for b in (box, fBox, iBox, atomBox) if b])
    if bc == 0:
        raise CommandError, 'Must specify box to cover'
    if bc > 1:
        raise CommandError, 'Specify covering box in one way'

    step = parse_step(step, require_3_tuple = True)
    modelId = parse_model_id(modelId)

    from VolumeViewer import volume, volume_from_grid_data
    for v in volumes:
        g = v.grid_data(subregion = 'all', step = step, mask_zone = False)
        ijk_min, ijk_max = cover_box_bounds(v, step,
                                            atomBox, pad, box, fBox, iBox)
        cg = volume.map_from_periodic_map(g, ijk_min, ijk_max)
        cv = volume_from_grid_data(cg, model_id = modelId)
        cv.copy_settings_from(v, copy_region = False)
        cv.show()
Example #10
0
def fourier_op(volumes, subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from fourier import fourier_transform
    for v in volumes:
        fourier_transform(v, step, subregion, modelId)
Example #11
0
def z_flip_op(volumes, subregion='all', step=1, inPlace=False, modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes[:1])
    modelId = parse_model_id(modelId)

    for v in volumes:
        zflip_operation(v, subregion, step, inPlace, modelId)
Example #12
0
def fourier_op(volumes, subregion='all', step=1, modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from fourier import fourier_transform
    for v in volumes:
        fourier_transform(v, step, subregion, modelId)
Example #13
0
def laplacian_op(volumes, subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)
    
    from laplace import laplacian
    for v in volumes:
        laplacian(v, step, subregion, modelId)
Example #14
0
def resample_op(volumes, onGrid = None, boundingGrid = False,
                subregion = 'all', step = 1,
                gridSubregion = 'all', gridStep = 1,
                modelId = None):

    volumes = filter_volumes(volumes)
    if onGrid is None:
        raise CommandError, 'Resample operation must specify onGrid option'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    onGrid = filter_volumes(onGrid, 'onGrid')
    modelId = parse_model_id(modelId)
    for v in volumes:
        for gv in onGrid:
            add_operation([v], subregion, step,
                          gv, gridSubregion, gridStep,
                          boundingGrid, False, None, modelId)
Example #15
0
def laplacian_op(volumes, subregion='all', step=1, modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from laplace import laplacian
    for v in volumes:
        laplacian(v, step, subregion, modelId)
Example #16
0
def median_op(volumes,
              binSize=3,
              iterations=1,
              subregion='all',
              step=1,
              modelId=None):

    volumes = filter_volumes(volumes)
    check_number(iterations, 'iterations', positive=True)
    binSize = parse_step(binSize, 'binSize', require_3_tuple=True)
    for b in binSize:
        if b <= 0 or b % 2 == 0:
            raise CommandError, 'Bin size must be positive odd integer, got %d' % b
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from median import median_filter
    for v in volumes:
        median_filter(v, binSize, iterations, step, subregion, modelId)
Example #17
0
def gaussian_op(volumes, sDev=1.0, subregion='all', step=1, modelId=None):

    volumes = filter_volumes(volumes)
    check_number(sDev, 'sDev', positive=True)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from gaussian import gaussian_convolve
    for v in volumes:
        gaussian_convolve(v, sDev, step, subregion, modelId)
Example #18
0
def z_flip_op(volumes, subregion = 'all', step = 1,
              inPlace = False, modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes[:1])
    modelId = parse_model_id(modelId)

    for v in volumes:
        zflip_operation(v, subregion, step, inPlace, modelId)
Example #19
0
def gaussian_op(volumes, sDev = 1.0,
                subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(sDev, 'sDev', positive = True)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from gaussian import gaussian_convolve
    for v in volumes:
        gaussian_convolve(v, sDev, step, subregion, modelId)
Example #20
0
def resample_op(volumes,
                onGrid=None,
                boundingGrid=False,
                subregion='all',
                step=1,
                gridSubregion='all',
                gridStep=1,
                modelId=None):

    volumes = filter_volumes(volumes)
    if onGrid is None:
        raise CommandError, 'Resample operation must specify onGrid option'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    gridSubregion = parse_subregion(gridSubregion, 'gridSubregion')
    gridStep = parse_step(gridStep, 'gridStep')
    onGrid = filter_volumes(onGrid, 'onGrid')
    modelId = parse_model_id(modelId)
    for v in volumes:
        for gv in onGrid:
            add_operation([v], subregion, step, gv, gridSubregion, gridStep,
                          boundingGrid, False, None, modelId)
Example #21
0
def boxes_op(volumes, markers, size = 0, useMarkerSize = False,
             subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    check_number(size, 'size')
    if size <= 0 and not useMarkerSize:
        raise CommandError, 'Must specify size or enable useMarkerSize'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from boxes import boxes
    for v in volumes:
        boxes(v, markers, size, useMarkerSize, step, subregion, modelId)
Example #22
0
def bin_op(volumes, subregion='all', step=1, binSize=(2, 2, 2), modelId=None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    if isinstance(binSize, int):
        binSize = (binSize, binSize, binSize)
    elif isinstance(binSize, basestring):
        binSize = parse_ints(binSize, 'binSize', 3)
    modelId = parse_model_id(modelId)

    from bin import bin
    for v in volumes:
        bin(v, binSize, step, subregion, modelId)
Example #23
0
def bin_op(volumes, subregion = 'all', step = 1,
           binSize = (2,2,2), modelId = None):

    volumes = filter_volumes(volumes)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    if isinstance(binSize, int):
        binSize = (binSize, binSize, binSize)
    elif isinstance(binSize, basestring):
        binSize = parse_ints(binSize, 'binSize', 3)
    modelId = parse_model_id(modelId)

    from bin import bin
    for v in volumes:
        bin(v, binSize, step, subregion, modelId)
Example #24
0
def permute_axes_op(volumes, axisOrder = 'xyz',
                    subregion = 'all', step = 1, modelId = None):

    volumes = filter_volumes(volumes)
    ao = {'xyz':(0,1,2), 'xzy':(0,2,1), 'yxz':(1,0,2), 
          'yzx':(1,2,0), 'zxy':(2,0,1), 'zyx':(2,1,0)}
    if not axisOrder in ao:
        raise CommandError, 'Axis order must be xyz, xzy, zxy, zyx, yxz, or yzx'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from permute import permute_axes
    for v in volumes:
        permute_axes(v, ao[axisOrder], step, subregion, modelId)
Example #25
0
def octant_complement_op(volumes, center = None, iCenter = None,
              subregion = 'all', step = 1, inPlace = False,
              fillValue = 0, modelId = None):

    volumes = filter_volumes(volumes)
    center = parse_floats(center, 'center', 3)
    iCenter = parse_floats(iCenter, 'iCenter', 3)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes)
    check_number(fillValue, 'fillValue')
    modelId = parse_model_id(modelId)
    outside = False
    for v in volumes:
        octant_operation(v, outside, center, iCenter, subregion, step,
                         inPlace, fillValue, modelId)
Example #26
0
def cover_op(volumes,
             atomBox=None,
             pad=5.0,
             box=None,
             x=None,
             y=None,
             z=None,
             fBox=None,
             fx=None,
             fy=None,
             fz=None,
             iBox=None,
             ix=None,
             iy=None,
             iz=None,
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(pad, 'pad')

    if not atomBox is None and len(atomBox) == 0:
        raise CommandError, 'No atoms specified'
    box = parse_box(box, x, y, z, 'box', 'x', 'y', 'z')
    fBox = parse_box(fBox, fx, fy, fz, 'fBox', 'fx', 'fy', 'fz')
    iBox = parse_box(iBox, ix, iy, iz, 'iBox', 'ix', 'iy', 'iz')
    bc = len([b for b in (box, fBox, iBox, atomBox) if b])
    if bc == 0:
        raise CommandError, 'Must specify box to cover'
    if bc > 1:
        raise CommandError, 'Specify covering box in one way'

    step = parse_step(step, require_3_tuple=True)
    modelId = parse_model_id(modelId)

    from VolumeViewer import volume, volume_from_grid_data
    for v in volumes:
        g = v.grid_data(subregion='all', step=step, mask_zone=False)
        ijk_min, ijk_max = cover_box_bounds(v, step, atomBox, pad, box, fBox,
                                            iBox)
        cg = volume.map_from_periodic_map(g, ijk_min, ijk_max)
        cv = volume_from_grid_data(cg, model_id=modelId)
        cv.copy_settings_from(v, copy_region=False)
        cv.show()
Example #27
0
def boxes_op(volumes,
             markers,
             size=0,
             useMarkerSize=False,
             subregion='all',
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(size, 'size')
    if size <= 0 and not useMarkerSize:
        raise CommandError, 'Must specify size or enable useMarkerSize'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from boxes import boxes
    for v in volumes:
        boxes(v, markers, size, useMarkerSize, step, subregion, modelId)
Example #28
0
def octant_complement_op(volumes,
                         center=None,
                         iCenter=None,
                         subregion='all',
                         step=1,
                         inPlace=False,
                         fillValue=0,
                         modelId=None):

    volumes = filter_volumes(volumes)
    center = parse_floats(center, 'center', 3)
    iCenter = parse_floats(iCenter, 'iCenter', 3)
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    check_in_place(inPlace, volumes)
    check_number(fillValue, 'fillValue')
    modelId = parse_model_id(modelId)
    outside = False
    for v in volumes:
        octant_operation(v, outside, center, iCenter, subregion, step, inPlace,
                         fillValue, modelId)
Example #29
0
def morph_op(volumes,
             frames=25,
             start=0,
             playStep=0.04,
             playDirection=1,
             playRange=None,
             addMode=False,
             constantVolume=False,
             scaleFactors=None,
             hideOriginalMaps=True,
             subregion='all',
             step=1,
             modelId=None):

    volumes = filter_volumes(volumes)
    check_number(frames, 'frames', int, nonnegative=True)
    check_number(start, 'start')
    check_number(playStep, 'playStep', nonnegative=True)
    if playRange is None:
        if addMode:
            prange = (-1.0, 1.0)
        else:
            prange = (0.0, 1.0)
    else:
        prange = parse_floats(playRange, 'playRange', 2)
    check_number(playDirection, 'playDirection')
    sfactors = parse_floats(scaleFactors, 'scaleFactors', len(volumes))
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)
    vs = [
        tuple(v.matrix_size(step=step, subregion=subregion)) for v in volumes
    ]
    if len(set(vs)) > 1:
        sizes = ' and '.join([str(s) for s in vs])
        raise CommandError, "Volume grid sizes don't match: %s" % sizes
    from MorphMap import morph_maps
    morph_maps(volumes, frames, start, playStep, playDirection, prange,
               addMode, constantVolume, sfactors, hideOriginalMaps, subregion,
               step, modelId)
Example #30
0
def permute_axes_op(volumes,
                    axisOrder='xyz',
                    subregion='all',
                    step=1,
                    modelId=None):

    volumes = filter_volumes(volumes)
    ao = {
        'xyz': (0, 1, 2),
        'xzy': (0, 2, 1),
        'yxz': (1, 0, 2),
        'yzx': (1, 2, 0),
        'zxy': (2, 0, 1),
        'zyx': (2, 1, 0)
    }
    if not axisOrder in ao:
        raise CommandError, 'Axis order must be xyz, xzy, zxy, zyx, yxz, or yzx'
    subregion = parse_subregion(subregion)
    step = parse_step(step)
    modelId = parse_model_id(modelId)

    from permute import permute_axes
    for v in volumes:
        permute_axes(v, ao[axisOrder], step, subregion, modelId)