Beispiel #1
0
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)
      )
Beispiel #2
0
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))
Beispiel #3
0
def loadimg(p, directory='.', **kwargs):
  '''Return the Stack image using ROI and background stored in experiment metadata.
  Must be in current or specified directory.
  '''
  filename = p.filename if directory=='.' else opath.join(directory, p.filename)
  meta = p.fret.metadata
  if 'roi' not in kwargs:
    # If keyword roi= is not specified,
    # get the ROIs from the experiment metadata
    rois = [ meta[roi_key] 
      for roi_key in ('roi_donor', 'roi_acceptor')
      if roi_key in meta
      ]
    kwargs['roi'] = map(ROI.fromDict, rois)
  kwargs.setdefault('background', meta.get('background', '') )
  return image.fromFile(fileIO.add_img_ext(filename), **kwargs)
Beispiel #4
0
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))
Beispiel #5
0
 def loadimg(self, path='.', **kwargs):
   filename = self.filename
   return image.Stack(fileIO.add_img_ext(filename))
   return image.fromFile(filename, **kwargs)