def processFiles(flist, roi='roi.txt', background=None, verbose=True, ext=fileIO.FRET_FILE, **calcOptions): "Calculate donor, acceptor, and FRET values for files in flist argument." if isinstance(roi, str): roi = image.ROI.fromFile(roi) if len(roi) < 2: raise ValueError('Need 2 ROIs; given %s' % repr(roi)) don_roi, acc_roi = roi BG = image.fromBackground(background) for fname in flist: try: if verbose: info('Opening %s...' % fname) img = image.fromFile(fname, roi=roi, background=BG) calculated_fret = fret_from_image(img, **calcOptions) if verbose: info('Saving .fret data to file...') calculated_fret.metadata.update(img.metadata) save_fret(calculated_fret, fileIO.change_extension(fname, ext)) except IOError as e: warning("Error processing file {0}: {1}".format(fname, e.strerror)) except image.StackError as e: warning("\n** Error processing file {}:\n\t{!s}**\n".format( fname, e))
def processFiles(flist, roi='roi.txt', background=None, verbose=True, ext=fileIO.FRET_FILE, **calcOptions): "Process files given in flist as images" if isinstance(background, str): BG = image.fromFile(background,background=True) elif isinstance(background, int): BG = background else: BG = constants.default_background_subtract if isinstance(roi,str): roi = image.ROI.fromFile(roi) for fname in flist: try: if verbose: info('Opening %s...' % fname) img = image.fromFile(fname) - BG img.addROI(*roi) output = calculate(img, **calcOptions) if verbose: info('Saving .fret data to file...') toFile(fileIO.change_extension(fname,ext), output, img.metadata) except IOError as e: warning("Error processing file {0}: {1}".format( fname, e.strerror) )
def __init__(self, filename, filetype="img", camFile='', deepcopy=False): if filetype != 'img': raise ValueError, "Only filetype 'img' is supported!" self._showROI = False ################################################# ## Load data from file called filename if string ################################################# if isinstance(filename, str): self.filename = filename self._img = fileIO.loadimg(filename) self._roi = {} self._donorROIName = Stack.defaultDonorROI self._acceptorROIName = Stack.defaultAcceptorROI camFile = camFile or fileIO.change_extension(filename, '.cam') settings = fileIO.loadcam(camFile) self.metadata = {} for setting,value in settings.iteritems(): self.metadata[setting] = value if not hasattr(self, setting): setattr(self, setting, value) # check cam and img file correspondence if self._img.shape != (settings['frames'],settings['height'],settings['width']): raise StackError, ".img file and .cam file dimensions do not agree" self.origin = (self.roileft,self.roibottom) self.addROI(*self.__class__.defaultROI.values()) ################################################# ## Make a copy of filename if actually another Stack ################################################# elif isinstance(filename, Stack): if deepcopy: self._img=filename._img.copy() else: self._img=filename._img self._roi=filename._roi self._donorROIName = filename._donorROIName self._acceptorROIName = filename._acceptorROIName self.origin = filename.origin self.metadata = filename.metadata for setting in self.metadata: if not hasattr(self,setting.lower()): setattr(self, setting, getattr(filename,setting)) else: raise StackError, "Invalid constructor call using %s" % str(filename)
def processFiles(flist, roi='roi.txt', background=None, verbose=True, ext=fileIO.FRET_FILE, **calcOptions): "Calculate donor, acceptor, and FRET values for files in flist argument." if isinstance(roi,str): roi = image.ROI.fromFile(roi) if len(roi) < 2: raise ValueError('Need 2 ROIs; given %s' % repr(roi)) don_roi,acc_roi = roi BG = image.fromBackground(background) for fname in flist: try: if verbose: info('Opening %s...' % fname) img = image.fromFile(fname, roi=roi, background=BG) calculated_fret = fret_from_image(img, **calcOptions) if verbose: info('Saving .fret data to file...') calculated_fret.metadata.update(img.metadata) save_fret(calculated_fret, fileIO.change_extension(fname,ext)) except IOError as e: warning("Error processing file {0}: {1}".format( fname, e.strerror)) except image.StackError as e: warning("\n** Error processing file {}:\n\t{!s}**\n".format(fname, e))