本文整理汇总了Python中ClearMap.IO.fileExtension方法的典型用法代码示例。如果您正苦于以下问题:Python IO.fileExtension方法的具体用法?Python IO.fileExtension怎么用?Python IO.fileExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClearMap.IO
的用法示例。
在下文中一共展示了IO.fileExtension方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fileNameToIlastikOuput
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [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;
示例2: fileNameToIlastikOuput
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [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
示例3: isValidOutputFileName
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [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
示例4: isValidOutputFileName
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [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;
示例5: isValidInputFileName
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [as 别名]
def isValidInputFileName(filename):
"""Checks if the file is a valid format for use with Ilastik input
Arguments:
filename (str): image file name or expression
Returns:
bool: True if the image file can be read by Ilastik
"""
validExtensions = [
"bmp",
"exr",
"gif",
"jpg",
"jpeg",
"tif",
"tiff",
"ras",
"png",
"pbm",
"pgm",
"ppm",
"pnm",
"hdr",
"xv",
"npy",
]
return io.fileExtension(filename) in validExtensions
示例6: copyData
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [as 别名]
def copyData(source, sink):
"""Copy a raw/mhd file pair from source to sink
Arguments:
source (str): file name of source
sink (str): file name of sink
Returns:
str: file name of the copy
"""
sourceExt = io.fileExtension(source);
sinkExt = io.fileExtension(sink);
sources = [source];
sinks = [];
if sourceExt == 'raw':
sources.append(source[:-3] + 'mhd');
if sinkExt == 'raw':
sinks.append(sink);
sinks.append(sink[:-3] + 'mhd');
elif sinkExt == 'mhd':
sinks.append(sink[:-3] + 'raw');
sinks.append(sink);
else:
raise RuntimeError('copyData: sink extension %s not raw or mhd' % sinkExt);
elif sourceExt == 'mhd':
sources.append(source[:-3] + 'raw');
if sinkExt == 'raw':
sinks.append(sink[:-3] + 'mhd');
sinks.append(sink);
elif sinkExt == 'mhd':
sinks.append(sink);
sinks.append(sink[:-3] + 'raw');
else:
raise RuntimeError('copyData: sink extension %s not raw or mhd' % sinkExt);
for i in range(2):
io.copyData(sources[i], sinks[i]);
return sink;
示例7: writeData
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [as 别名]
def writeData(filename, data, **args):
""" Write data into to raw/mhd file pair
Arguments:
filename (str): file name as regular expression
data (array): data to write to raw file
Returns:
str: file name of mhd file
"""
fext = io.fileExtension(filename);
if fext == "raw":
fname = filename[:-3] + 'mhd';
else:
fname = filename;
assert(fname[-4:]=='.mhd')
meta_dict = {}
meta_dict['ObjectType'] = 'Image'
meta_dict['BinaryData'] = 'True'
meta_dict['BinaryDataByteOrderMSB'] = 'False'
numpy_to_datatype = {numpy.dtype('int8') : "MET_CHAR",
numpy.dtype('uint8') : "MET_UCHAR",
numpy.dtype('int16') : "MET_SHORT",
numpy.dtype('uint16') : "MET_USHORT",
numpy.dtype('int32') : "MET_INT",
numpy.dtype('uint32') : "MET_UINT",
numpy.dtype('int64') : "MET_LONG",
numpy.dtype('uint64') : "MET_ULONG",
numpy.dtype('float32') : "MET_FLOAT",
numpy.dtype('float64') : "MET_DOUBLE",
}
dtype = data.dtype;
meta_dict['ElementType'] = numpy_to_datatype[dtype];
dsize = list(data.shape);
#dsize[0:2] = [dsize[1],dsize[0]]; #fix arrays represented as (y,x,z)
meta_dict['NDims'] = str(len(dsize))
meta_dict['DimSize'] = ' '.join([str(i) for i in dsize])
meta_dict['ElementDataFile'] = os.path.split(fname)[1].replace('.mhd','.raw')
writeHeader(fname, meta_dict)
pwd = os.path.split(fname)[0]
if pwd:
data_file = pwd +'/' + meta_dict['ElementDataFile']
else:
data_file = meta_dict['ElementDataFile']
writeRawData(data_file, data)
return fname;
示例8: isValidInputFileName
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [as 别名]
def isValidInputFileName(filename):
"""Checks if the file is a valid format for use with Ilastik input
Arguments:
filename (str): image file name or expression
Returns:
bool: True if the image file can be read by Ilastik
"""
validExtensions = ['bmp', 'exr', 'gif', 'jpg', 'jpeg', 'tif', 'tiff', 'ras',
'png', 'pbm', 'pgm', 'ppm', 'pnm', 'hdr', 'xv', 'npy'];
return io.fileExtension(filename) in validExtensions;
示例9: makeColorPalette
# 需要导入模块: from ClearMap import IO [as 别名]
# 或者: from ClearMap.IO import fileExtension [as 别名]
def makeColorPalette(filename=None):
"""Creates a pal file for imaris based on label colors"""
global Label
maxlabel = max(Label.ids)
colarray = numpy.zeros((maxlabel, 3))
for i in Label.ids:
colarray[i - 1, :] = Label.color(i)
if filename is None:
return colarray
else:
fext = io.fileExtension(filename)
if fext == "pal":
writePAL(filename, colarray)
elif fext == "lut":
writeLUT(filename, colarray)
else:
raise RuntimeError("color pallete format: %s not supported" % fext)
return colarray