def __new__(cls, file_name): if not file_exists(file_name): raise splt = file_name.split(".") if len(file_name) > 4 and file_name[:4] == "bdb:": pass elif EMUtil.get_image_ext_type(splt[-1]) == EMUtil.ImageType.IMAGE_UNKNOWN: raise if splt[-1] in ["img","hed"]: return EMImagicTmpFileHandle(file_name) elif file_name[:4] == "bdb:": return EMDBTmpFileHandle(file_name) else: return EMGeneralTmpFileHandle(file_name)
def __new__(cls, file_name): if not file_exists(file_name): raise splt = file_name.split(".") if len(file_name) > 4 and file_name[:4] == "bdb:": pass elif EMUtil.get_image_ext_type(splt[-1]) == EMUtil.ImageType.IMAGE_UNKNOWN: raise if splt[-1] in ["img","hed"]: return EMImagicTmpFileHandle(file_name) elif file_name[:4] == "bdb:": return EMDBTmpFileHandle(file_name) else: return EMGeneralTmpFileHandle(file_name)
def __init__(self,file_name): ''' @param file_name the name of the file that which is being overwritten @exception raised if the file_name does not exist on the file system @exception raised if the file_name has a unrecognized (or no) type ''' if not os.path.exists(file_name): raise splt = file_name.split(".") if len(splt) < 2: raise if EMUtil.get_image_ext_type(splt[-1]) == EMUtil.ImageType.IMAGE_UNKNOWN: raise self.__file_ext = "."+splt[-1] EMTmpFileHandleBase.__init__(self) self.__file_name = get_file_tag(file_name) self.__full_file_name = file_name self.__tmp_file_name = None self.__establish_tmp_file_name()
def __init__(self,file_name): ''' @param file_name the name of the file that which is being overwritten @exception raised if the file_name does not exist on the file system @exception raised if the file_name has a unrecognized (or no) type ''' if not os.path.exists(file_name): raise splt = file_name.split(".") if len(splt) < 2: raise if EMUtil.get_image_ext_type(splt[-1]) == EMUtil.ImageType.IMAGE_UNKNOWN: raise self.__file_ext = "."+splt[-1] EMTmpFileHandleBase.__init__(self) self.__file_name = base_name(file_name) self.__full_file_name = file_name self.__tmp_file_name = None self.__establish_tmp_file_name()
def __new__(cls,filename,application,force_plot=False,force_2d=False,old=None): file_type = Util.get_filename_ext(filename) em_file_type = EMUtil.get_image_ext_type(file_type) if not file_exists(filename): return None if force_plot and force_2d: # ok this sucks but it suffices for the time being print "Error, the force_plot and force_2d options are mutually exclusive" return None if force_plot: from emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget if em_file_type != IMAGE_UNKNOWN or filename[:4] == "bdb:": n = EMUtil.get_image_count(filename) nx,ny,nz = gimme_image_dimensions3D(filename) if n > 1 and nz == 1: if force_2d: a = EMData() data=a.read_images(filename) else: data = None # This is like a flag - the ImageMXWidget only needs the file name elif nz == 1: data = [EMData(filename,0)] else: data = EMData() data.read_image(filename,0,not force_2d) # This should be 3-D. We read the header-only here data = [data] if data != None and len(data) == 1: data = data[0] if force_2d or isinstance(data,EMData) and data.get_zsize()==1: if isinstance(data,list) or data.get_ysize() != 1: from emimage2d import EMImage2DWidget if isinstance(old,EMImage2DWidget): widget = old else: widget= EMImage2DWidget(application=application) else: from emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget elif isinstance(data,EMData): if isinstance(old,EMScene3D): widget = old else: widget = EMScene3D() # print n,data for ii in xrange(n): data=EMData(filename,ii) datai = EMDataItem3D(data, transform=Transform()) widget.insertNewNode(os.path.basename(filename), datai, parentnode=widget) isosurface = EMIsosurface(datai, transform=Transform()) widget.insertNewNode("Iso", isosurface, parentnode=datai) return widget elif data == None or isinstance(data,list): from emimagemx import EMImageMXWidget if isinstance(old,EMImageMXWidget): widget = old else: widget = EMImageMXWidget(application=application) data = filename else: print filename raise # weirdness, this should never happen widget.set_data(data,filename) return widget else: from emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget
def __new__(cls,filename,application,force_plot=False,force_2d=False,old=None): file_type = Util.get_filename_ext(filename) em_file_type = EMUtil.get_image_ext_type(file_type) if not file_exists(filename): return None if force_plot and force_2d: # ok this sucks but it suffices for the time being print("Error, the force_plot and force_2d options are mutually exclusive") return None if force_plot: from .emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget if em_file_type != IMAGE_UNKNOWN or filename[:4] == "bdb:": n = EMUtil.get_image_count(filename) nx,ny,nz = gimme_image_dimensions3D(filename) if n > 1 and nz == 1: if force_2d: a = EMData() data=a.read_images(filename) else: data = None # This is like a flag - the ImageMXWidget only needs the file name elif nz == 1: data = [EMData(filename,0)] else: data = EMData() data.read_image(filename,0,not force_2d) # This should be 3-D. We read the header-only here data = [data] if data != None and len(data) == 1: data = data[0] if force_2d or isinstance(data,EMData) and data.get_zsize()==1: if isinstance(data,list) or data.get_ysize() != 1: from .emimage2d import EMImage2DWidget if isinstance(old,EMImage2DWidget): widget = old else: widget= EMImage2DWidget(application=application) else: from .emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget elif isinstance(data,EMData): if isinstance(old,EMScene3D): widget = old else: widget = EMScene3D() # print n,data for ii in range(n): data=EMData(filename,ii) datai = EMDataItem3D(data, transform=Transform()) widget.insertNewNode(os.path.basename(filename), datai, parentnode=widget) isosurface = EMIsosurface(datai, transform=Transform()) widget.insertNewNode("Iso", isosurface, parentnode=datai) return widget elif data == None or isinstance(data,list): from .emimagemx import EMImageMXWidget if isinstance(old,EMImageMXWidget): widget = old else: widget = EMImageMXWidget(application=application) data = filename else: print(filename) raise # weirdness, this should never happen widget.set_data(data,filename) return widget else: from .emplot2d import EMPlot2DWidget if isinstance(old,EMPlot2DWidget): widget = old else: widget = EMPlot2DWidget(application=application) widget.set_data_from_file(filename) return widget