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


Python IO.isFileExpression方法代码示例

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


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

示例1: fileNameToIlastikOuput

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import isFileExpression [as 别名]
def fileNameToIlastikOuput(filename):
  """Converts *ClearMap* file name to an argument string for use with Ilastik headless mode
  
  Arguments:
    filename (str): image file name or expression
  
  Returns:
    str: Ilastik headless ouput specifications
    
  Note:
    The output is formated accroding to the Ilastik pixel calssification output specifications
  """

  if not isValidOutputFileName(filename):
    raise RuntimeError('Ilastik: file format not compatibel with Ilastik output');
  
  if io.isFileExpression(filename):
    o = '--output_format="' + io.fileExtension(filename) + ' sequence" '+ \
        '--output_filename_format="' + filelist.fileExpressionToFileName(filename, '{slice_index}') + '"';
    return o;
    
  else: # single file
    extensionToOuput  = {'bmp' : 'bmp', 'gif' : 'gif', 'hdr' : 'hrd', 
                         'jpg' : 'jpg', 'jpeg': 'jpeg','pbm' : 'pbm', 
                         'pgm' : 'pgm', 'png' : 'png', 'pnm' : 'pnm', 'ppm' : 'ppm', 
                         'ras' : 'ras', 'tif' : 'tif', 'tiff': 'tiff','xv'  : 'xv',
                         'h5'  : 'hdf5' , 'npy' : 'numpy'};
    ext = extensionToOuput[io.fileExtension(filename)];
    o = '--output_format="' + ext +'" ' + \
        '--output_filename_format="' + filename + '"';
    return o;
开发者ID:audrocks17,项目名称:ClearMap,代码行数:33,代码来源:Ilastik.py

示例2: fileNameToIlastikOuput

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import isFileExpression [as 别名]
def fileNameToIlastikOuput(filename):
    """Converts *ClearMap* file name to an argument string for use with Ilastik headless mode
  
  Arguments:
    filename (str): image file name or expression
  
  Returns:
    str: Ilastik headless ouput specifications
    
  Note:
    The output is formated accroding to the Ilastik pixel calssification output specifications
  """

    if not isValidOutputFileName(filename):
        raise RuntimeError("Ilastik: file format not compatibel with Ilastik output")

    if io.isFileExpression(filename):
        o = (
            '--output_format="'
            + io.fileExtension(filename)
            + ' sequence" '
            + '--output_filename_format="'
            + filelist.fileExpressionToFileName(filename, "{slice_index}")
            + '"'
        )
        return o

    else:  # single file
        extensionToOuput = {
            "bmp": "bmp",
            "gif": "gif",
            "hdr": "hrd",
            "jpg": "jpg",
            "jpeg": "jpeg",
            "pbm": "pbm",
            "pgm": "pgm",
            "png": "png",
            "pnm": "pnm",
            "ppm": "ppm",
            "ras": "ras",
            "tif": "tif",
            "tiff": "tiff",
            "xv": "xv",
            "h5": "hdf5",
            "npy": "numpy",
        }
        ext = extensionToOuput[io.fileExtension(filename)]
        o = '--output_format="' + ext + '" ' + '--output_filename_format="' + filename + '"'
        return o
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:51,代码来源:Ilastik.py

示例3: isValidOutputFileName

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import isFileExpression [as 别名]
def isValidOutputFileName(filename):
    """Checks if the file is a valid format for use with Ilastik ouput
  
  Arguments:
    filename (str): image file name or expression
  
  Returns:
    bool: True if the image file can be written by Ilastik
  """

    if io.isFileExpression(filename):
        validExtensions = [
            "bmp",
            "gif",
            "hdr",
            "jpg",
            "jpeg",
            "pbm",
            "pgm",
            "png",
            "pnm",
            "ppm",
            "ras",
            "tif",
            "tiff",
            "xv",
        ]
        return io.fileExtension(filename) in validExtensions
    else:
        validExtensions = [
            "bmp",
            "gif",
            "hdr",
            "jpg",
            "jpeg",
            "pbm",
            "pgm",
            "png",
            "pnm",
            "ppm",
            "ras",
            "tif",
            "tiff",
            "xv",
            "h5",
            "npy",
        ]
        return io.fileExtension(filename) in validExtensions
开发者ID:ChristophKirst,项目名称:ClearMapUnstable,代码行数:50,代码来源:Ilastik.py

示例4: isValidOutputFileName

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import isFileExpression [as 别名]
def isValidOutputFileName(filename):
  """Checks if the file is a valid format for use with Ilastik ouput
  
  Arguments:
    filename (str): image file name or expression
  
  Returns:
    bool: True if the image file can be written by Ilastik
  """
    
  if io.isFileExpression(filename):
    validExtensions  = ['bmp', 'gif', 'hdr', 'jpg', 'jpeg', 'pbm', 'pgm', 'png', 'pnm', 'ppm', 'ras', 'tif', 'tiff', 'xv'];
    return io.fileExtension(filename) in validExtensions;
  else:
    validExtensions  = ['bmp', 'gif', 'hdr', 'jpg', 'jpeg', 'pbm', 'pgm', 'png', 'pnm', 'ppm', 'ras', 'tif', 'tiff', 'xv', 'h5', 'npy'];
    return io.fileExtension(filename) in validExtensions;
开发者ID:audrocks17,项目名称:ClearMap,代码行数:18,代码来源:Ilastik.py

示例5: fileNameToIlastikInput

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import isFileExpression [as 别名]
def fileNameToIlastikInput(filename):
  """Converts *ClearMap* file name to a string for use with Ilastik input
  
  Arguments:
    filename (str): image file name or expression
  
  Returns:
    str: Ilastik conform file name
    
  Note:
    file expressions in *ClearMap* are regular expressions but shell expressions in Ilastik.
  """

  if not isValidInputFileName(filename):
    raise RuntimeError('Ilastik: file format not compatibel with Ilastik');
  
  if io.isFileExpression(filename):
    return '"' + filelist.fileExpressionToFileName(filename, '*') + '"';
  else:
    return '"' + filename + '"';
开发者ID:audrocks17,项目名称:ClearMap,代码行数:22,代码来源:Ilastik.py

示例6: cropData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import isFileExpression [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

示例7: stitchData

# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import isFileExpression [as 别名]
def stitchData(
    xmlPlacementFile,
    resultPath,
    algorithm=None,
    resolutions=None,
    form=None,
    channel=None,
    subRegion=None,
    bitDepth=None,
    blockSize=None,
    cleanup=True,
    compress=False,
):
    """Runs the final stiching step of TeraSticher
  
  Arguments:
    xmlPlacementFile (str or None): the xml placement descriptor
    resultPath (str): result path, file name or file expression for the stiched data
    algorithm (str or None): optional algorithm to use for placement: 
                             'NOBLEND' for no blending
                             'SINBLEND' for sinusoidal blending
    resolutions (tuple or None): the different resolutions to produce
    form (str or None): the output form, if None determined automatically
    channel (str or None): the channels to use, 'R', 'G', 'B' or 'all'
    subRegion (tuple or None): optional sub region in the form ((xmin,xmax),(ymin,ymax), (zmin, zmax))
    bitDepth (int or None): the pits per pixel to use, default is 8
    blockSize (tuple): the sizes of various blocks to save stiched image into
    cleanup (bool): if True delete the TeraSticher file structure
    compress (bool): if True compress final tif images
  
  Returns:
    str : the result path or file name of the stiched data
    
  See also:
    `TeraStitcher project step <https://github.com/abria/TeraStitcher/wiki/Step-6:-Merge>`_.
  """

    checkSticherInitialized()
    global TeraStitcherBinary

    cmd = TeraStitcherBinary + ' --merge --imout_format="tif" '

    cmd = cmd + '--projin="' + xmlPlacementFile + '" '

    if len(resultPath) > 3 and resultPath[-4:] == ".tif":
        if io.isFileExpression(resultPath):
            form = "TiledXY|2Dseries"
            resultPath, filename = os.path.split(resultPath)
        else:
            form = "TiledXY|3Dseries"
            resultPath, filename = os.path.split(resultPath)
    else:
        filename = None

    cmd = cmd + '--volout="' + resultPath + '" '

    if algorithm is not None:
        cmd = cmd + ' --algorithm="' + algorithm + '" '

    if resolutions is not None:
        cmd = cmd + '--resolutions="'
        for r in sorted(resolutions):
            cmd = cmd + str(r)
        cmd = cmd + " "

    if form is not None:
        cmd = cmd + '--volout_plugin="' + form + '" '

    if channel is not None:
        cmd = cmd + '--imin_channel="' + channel + '" '

    if subRegion is not None:
        sns = (("--R0=", "--R1="), ("--C0=", "--C1="), ("--D0=", "--D1-"))
        for d in range(3):
            for m in range(2):
                if subRegion[d][m] is not None:
                    cmd = cmd + sns[d][m] + str(subRegion[d][m]) + " "

    if blockSize is not None:
        bs = ("--slicewidth=", "--sliceheight=", "--slicedepth=")
        for d in range(3):
            if blockSize[d] is not None:
                cmd = cmd + bs[d] + str(blockSize[d]) + " "

    if bitDepth is not None:
        cmd = cmd + "--imout_depth=" + str(bitDepth) + " "

    if not compress:
        cmd = cmd + "--libtiff_uncompress "

    # print resultPath
    io.createDirectory(resultPath, split=False)

    print "running: " + cmd
    res = os.system(cmd)

    if res != 0:
        raise RuntimeError("stitchData: failed executing: " + cmd)

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


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