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


Python IO.toDataRange方法代码示例

本文整理汇总了Python中ClearMap.IO.toDataRange方法的典型用法代码示例。如果您正苦于以下问题:Python IO.toDataRange方法的具体用法?Python IO.toDataRange怎么用?Python IO.toDataRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClearMap.IO的用法示例。


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

示例1: readData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import toDataRange [as 别名]
def readData(filename, x = all, y = all, z = all, resolution = 0, channel = 0, timepoint = 0, **args):
    """Read data from imaris file

    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
        resolution (int): resolution level
        channel (int): color channel
        timepoint (int): time point
    
    Returns:
        array: image data
    """ 
    
    f = h5py.File(filename, "r");
    dataset = readDataSet(f, resolution = resolution, channel = channel, timepoint = timepoint);
    dsize = dataset.shape;
    
    rz = io.toDataRange(dsize[0], r = z);
    ry = io.toDataRange(dsize[1], r = y);
    rx = io.toDataRange(dsize[2], r = x);    
    
    data = dataset[rz[0]:rz[1],ry[0]:ry[1],rx[0]:rx[1]];
    data = data.transpose((2,1,0)); # imaris stores files in reverse x,y,z ordering
    #data = dataset[x[0]:x[1],y[0]:y[1],z[0]:z[1]];
    
    f.close();
    
    return data;
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:31,代码来源:Imaris.py

示例2: readDataFiles

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import toDataRange [as 别名]
def readDataFiles(filename, x=all, y=all, z=all, **args):
    """Read data from individual images assuming they are the z slices

    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """

    fpath, fl = readFileList(filename)
    nz = len(fl)

    # read first image to get data size and type
    rz = io.toDataRange(nz, r=z)
    sz = io.toDataSize(nz, r=z)
    fn = os.path.join(fpath, fl[rz[0]])
    img = io.readData(fn, x=x, y=y)
    nxy = img.shape
    data = numpy.zeros(nxy + (sz,), dtype=img.dtype)
    data[:, :, 0] = img

    for i in range(rz[0] + 1, rz[1]):
        fn = os.path.join(fpath, fl[i])
        data[:, :, i - rz[0]] = io.readData(fn, x=x, y=y)

    return data
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:30,代码来源:FileList.py

示例3: readData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import toDataRange [as 别名]
def readData(filename, x = all, y = all, z = all, **args):
    """Read data from a single tif image or stack
    
    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """
    
    dsize = dataSize(filename);
    #print "dsize %s" % str(dsize);    
    
    if len(dsize) == 2:
        data = tiff.imread(filename, key = 0);
        #print "data.shape %s" % str(data.shape);        
        
        return io.dataToRange(data.transpose([1,0]), x = x, y = y);
        #return io.dataToRange(data, x = x, y = y);
        
    else:
        if z is all:
            data = tiff.imread(filename);
            if data.ndim == 2:
                # data = data
                data = data.transpose([1,0]);
            elif data.ndim == 3:
                #data = data.transpose([1,2,0]);
                data = data.transpose([2,1,0]);
            elif data.ndim == 4: # multi channel image
                #data = data.transpose([1,2,0,3]);
                data = data.transpose([2,1,0,3]);
            else:
                raise RuntimeError('readData: dimension %d not supproted!' % data.ndim)
            
            return io.dataToRange(data, x = x, y = y, z = all);
        
        else: #optimize for z ranges
            ds = io.dataSizeFromDataRange(dsize, x = x, y = y, z = z);
            t = tiff.TiffFile(filename);
            p = t.pages[0];
            data = numpy.zeros(ds, dtype = p.dtype);
            rz = io.toDataRange(dsize[2], r = z);
            
            #print "test"
            #print rz;
            #print dsize            
            
            for i in range(rz[0], rz[1]):
                xydata = t.pages[i].asarray();
                #data[:,:,i-rz[0]] = io.dataToRange(xydata, x = x, y = y);
                data[:,:,i-rz[0]] = io.dataToRange(xydata.transpose([1,0]), x = x, y = y);
            
            return data
开发者ID:jennan,项目名称:ClearMap,代码行数:57,代码来源:TIF.py

示例4: calculateSubStacks

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import toDataRange [as 别名]
def calculateSubStacks(source, z = all, x = all, y = all, **args):
    """Calculates the chunksize and other info for parallel processing and returns a list of sub-stack objects
    
    The sub-stack information is described in :ref:`SubStack`  
    
    Arguments:
        source (str): image source
        x,y,z (tuple or all): range specifications
        processes (int): number of parallel processes
        chunkSizeMax (int): maximal size of a sub-stack
        chunkSizeMin (int): minial size of a sub-stack
        chunkOverlap (int): minimal sub-stack overlap
        chunkOptimization (bool): optimize chunck sizes to best fit number of processes
        chunkOptimizationSize (bool or all): if True only decrease the chunk size when optimizing
        verbose (bool): print information on sub-stack generation
        
    Returns:
        list: list of sub-stack objects
    """    
    
    #determine z ranges
    fs = io.dataSize(source);
    zs = fs[2];
    zr = io.toDataRange(zs, r = z);
    nz = zr[1] - zr[0];
    
    #calculate optimal chunk sizes
    nchunks, zranges, zcenters = calculateChunkSize(nz, **args);
    
    #adjust for the zrange
    zcenters = [c + zr[0] for c in zcenters];
    zranges = [(zc[0] + zr[0], zc[1] + zr[0]) for zc in zranges];
    
    #create substacks
    subStacks = [];
    indexlo = zr[0];
    
    for i in range(nchunks):
        
        indexhi = int(round(zcenters[i+1]));
        if indexhi > zr[1] or i == nchunks - 1:
            indexhi = zr[1];
        
        zs = zranges[i][1] - zranges[i][0];
        
        subStacks.append({"stackId" : i, "nStacks" : nchunks, 
                          "source" : source, "x" : x, "y" : y, "z" : zranges[i], 
                          "zCenters" : (zcenters[i], zcenters[i+1]),
                          "zCenterIndices" : (indexlo, indexhi),
                          "zSubStackCenterIndices" : (indexlo - zranges[i][0], zs - (zranges[i][1] - indexhi))});
        
        indexlo = indexhi; # + 1;
    
    return subStacks;
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:56,代码来源:StackProcessing.py

示例5: cropData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import toDataRange [as 别名]
def cropData(source, sink=None, x=all, y=all, z=all, adjustOverlap=False, verbose=True, processes=all):
    """Crop source from start to stop point
  
  Arguments:
    source (str or array): filename or data array of source
    sink (str or None): filename or sink
    x,y,z (tuple or all): the range to crop the data to
    adjustOverlap (bool): correct overlap meta data if exists
  
  Return:
    str or array: array or filename with cropped data
  """

    if sink is None:
        return readDataFiles(source, x=x, y=y, z=z)
    else:  # sink assumed to be file expression

        if not io.isFileExpression(sink):
            raise RuntimeError("cropping data to different format not supported!")

        fileheader, fileext, digitfrmt = splitFileExpression(sink)

        # read first image to get data size and type
        fp, fl = readFileList(source)
        nz = len(fl)
        rz = io.toDataRange(nz, r=z)

        if adjustOverlap:  # change overlap in first file
            try:
                fn = os.path.join(fp, fl[0])
                info = io.readMetaData(fn, info=["description", "overlap", "resolution"])
                description = str(info["description"])
                overlap = numpy.array(info["overlap"], dtype=float)
                resolution = numpy.array(info["resolution"], dtype=float)

            except:
                raise RuntimeWarning("could not modify overlap!")

            fullsize = io.dataSize(fn)
            data = io.readData(fn, x=x, y=y)

            # overlap in pixels
            poverlap = overlap[:2] / resolution[:2]
            print poverlap

            # cropped pixel
            xr = io.toDataRange(fullsize[0], r=x)
            yr = io.toDataRange(fullsize[1], r=y)

            print xr
            print yr
            print fullsize

            poverlap[0] = poverlap[0] - xr[0] - (fullsize[0] - xr[1])
            poverlap[1] = poverlap[1] - yr[0] - (fullsize[1] - yr[1])
            print poverlap

            # new overlap in microns
            overlap = poverlap * resolution[:2]

            # check for consistency
            if numpy.abs(fullsize[0] - xr[1] - xr[0]) > 1 or numpy.abs(fullsize[1] - yr[1] - yr[0]) > 1:
                raise RuntimeWarning("cropping is inconsistent with overlap )modification!")

            # change image description
            import ClearMap.IO.TIF as CMTIF

            description = CMTIF.changeOMEMetaDataString(description, {"overlap": overlap})
            print len(description)

            # write first file
            fnout = fileheader + (digitfrmt % 0) + fileext
            io.writeData(fnout, data, info=description)

            zr = range(rz[0] + 1, rz[1])
        else:
            zr = range(rz[0], rz[1])

        print zr
        nZ = len(zr)

        if processes is None:
            processes = 1
        if processes is all:
            processes = multiprocessing.cpu_count()

        if processes > 1:  # parallel processing
            pool = multiprocessing.Pool(processes=processes)
            argdata = []

            for i, z in enumerate(zr):
                if verbose:
                    argdata.append(
                        (os.path.join(fp, fl[z]), fileheader + (digitfrmt % (i + 1)) + fileext, x, y, (i + 1), (nZ + 1))
                    )
                else:
                    argdata.append(
                        (os.path.join(fp, fl[z]), fileheader + (digitfrmt % (i + 1)) + fileext, x, y, None, None)
                    )

#.........这里部分代码省略.........
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:103,代码来源:FileList.py


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