Beispiel #1
0
def fret_from_image(img,
                    bg_pixel=(0, 0),
                    bg_counts=(0, 0),
                    beta=BETA,
                    gamma=GAMMA,
                    rois=()):
    '''Returns (time,donor,acceptor,fret) calculated from an image with added ROIs

  img         image.Stack() or equivalent. Must have .roi dictionary with 'donor' and 'acceptor'
  bg_pixel    tuple of counts per pixel to substract from (donor,acceptor)
  bg_counts   tuple of counts to substract from (donor,acceptor)
  '''
    assert_all_listy(bg_pixel, bg_counts, rois)
    if not img.roi:
        if not rois:
            raise ValueError(
                'Must specify ROIs in image or provide using rois=')
        else:
            img.addROI(*rois)
    pixel_donor, pixel_acc = bg_pixel
    bg_donor, bg_acc = bg_counts
    donor_roi, acceptor_roi = img.roi['donor'], img.roi['acceptor']
    don = counts_from_image(img, donor_roi, pixel_donor) - bg_donor
    acc = counts_from_image(img, acceptor_roi, pixel_acc) - bg_acc
    dcounts, acounts, fret = fret_counts(don, acc, beta, gamma)
    metadata = nesteddict.from_dict(img.metadata)
    metadata.update(beta=beta,
                    gamma=gamma,
                    bg_pixel=bg_pixel,
                    bg_counts=bg_counts,
                    roi_donor=donor_roi.toDict(),
                    roi_acceptor=acceptor_roi.toDict())
    fdata = FretData.fromFields(img.time, dcounts, acounts, fret)
    fdata.metadata = metadata
    return fdata
Beispiel #2
0
 def __init__(self, data, meta={}):
     data = asarray(data)
     if data is not None and not self._is_data_shape_ok(data.shape):
         logger.warning('TrapData should have fields for {}'.format(self._fields))
     self.data = data
     self._original_data = None
     self.metadata = nesteddict.from_dict(meta)
Beispiel #3
0
def fret_from_image(img, bg_pixel=(0,0), bg_counts=(0,0), beta=BETA, gamma=GAMMA, rois=()):
  '''Returns (time,donor,acceptor,fret) calculated from an image with added ROIs

  img         image.Stack() or equivalent. Must have .roi dictionary with 'donor' and 'acceptor'
  bg_pixel    tuple of counts per pixel to substract from (donor,acceptor)
  bg_counts   tuple of counts to substract from (donor,acceptor)
  '''
  assert_all_listy(bg_pixel, bg_counts, rois)
  if not img.roi:
    if not rois:
      raise ValueError('Must specify ROIs in image or provide using rois=')
    else:
      img.addROI(*rois)
  pixel_donor, pixel_acc = bg_pixel
  bg_donor, bg_acc = bg_counts
  donor_roi,acceptor_roi = img.roi['donor'], img.roi['acceptor']
  don = counts_from_image(img, donor_roi, pixel_donor) - bg_donor
  acc = counts_from_image(img, acceptor_roi, pixel_acc) - bg_acc
  dcounts,acounts,fret = fret_counts(don, acc, beta, gamma)
  metadata = nesteddict.from_dict(img.metadata)
  metadata.update(
    beta=beta, gamma=gamma, bg_pixel=bg_pixel, bg_counts=bg_counts,
    roi_donor=donor_roi.toDict(), roi_acceptor=acceptor_roi.toDict()
    )
  fdata = FretData.fromFields(img.time,dcounts,acounts,fret)
  fdata.metadata = metadata
  return fdata
Beispiel #4
0
 def __init__(self, trap, fret, metadata):
   if trap and not hasTrapData(trap):
     raise ValueError(
         "__init__ argument 'trap' <{}> does not have trap data".format(trap))
   if fret and not hasFretData(fret):
     raise ValueError(
         "__init__ argument 'fret' <{}> does not have fret data".format(fret))
   self.trap = trap
   self._fret = fret
   self.metadata = nesteddict.from_dict(metadata)
   self.metadata['trap'] = getattr(trap, 'metadata', nesteddict())
   self.metadata['fret'] = getattr(fret, 'metadata', nesteddict())
   # Move 'fret' metadata fields found in trap metadata (recorded in .str files)
   # to the fret.metadata dictionary
   for key in ifilter(lambda s: s.startswith('fret'), self.metadata['trap'].keys()):
     self['fret'].update(self.metadata['trap'].pop(key))
Beispiel #5
0
  def fromFile(cls, strfile, fretfile, metadata):
    assert strfile or fretfile
    assert isinstance(strfile, str)
    assert isinstance(fretfile, (str,type(None)))
    metadata = nesteddict.from_dict(metadata)

    trap = TrapData.fromFile(strfile)
    fret = FretData.fromFile(fretfile) if fretfile else None
    trap.metadata.setdefault('date', today())
    trap_datetime = trap.metadata['date']
    metadata.setdefault('date', to_date(trap_datetime))
    metadata.setdefault('datetime', trap_datetime)
    metadata['filename'] = fileIO.splitext(strfile)[0]
    newCls = cls(trap, fret, metadata)
    assert isinstance(newCls, cls)
    assert getattr(newCls, 'filename', None) is not None
    return newCls
Beispiel #6
0
    def fromFile(cls, strfile, fretfile, metadata):
        assert strfile or fretfile
        assert isinstance(strfile, str)
        assert isinstance(fretfile, (str, type(None)))
        metadata = nesteddict.from_dict(metadata)

        trap = TrapData.fromFile(strfile)
        fret = FretData.fromFile(fretfile) if fretfile else None
        trap.metadata.setdefault('date', today())
        trap_datetime = trap.metadata['date']
        metadata.setdefault('date', to_date(trap_datetime))
        metadata.setdefault('datetime', trap_datetime)
        metadata['filename'] = fileIO.splitext(strfile)[0]
        newCls = cls(trap, fret, metadata)
        assert isinstance(newCls, cls)
        assert getattr(newCls, 'filename', None) is not None
        return newCls
Beispiel #7
0
 def __init__(self, trap, fret, metadata):
     if trap and not hasTrapData(trap):
         raise ValueError(
             "__init__ argument 'trap' <{}> does not have trap data".format(
                 trap))
     if fret and not hasFretData(fret):
         raise ValueError(
             "__init__ argument 'fret' <{}> does not have fret data".format(
                 fret))
     self.trap = trap
     self._fret = fret
     self.metadata = nesteddict.from_dict(metadata)
     self.metadata['trap'] = getattr(trap, 'metadata', nesteddict())
     self.metadata['fret'] = getattr(fret, 'metadata', nesteddict())
     # Move 'fret' metadata fields found in trap metadata (recorded in .str files)
     # to the fret.metadata dictionary
     for key in ifilter(lambda s: s.startswith('fret'),
                        self.metadata['trap'].keys()):
         self['fret'].update(self.metadata['trap'].pop(key))