Exemplo n.º 1
0
def new_file_series0(first_object, first=None, last=None, step=1):
    """
    Created from a fabio image
    first and last are file numbers

    """
    im = first_object
    nimages = 0
    # for counting images
    if None in (first, last):
        step = 0
        total = 1
    else:
        total = last - first

    yield im
    while nimages < total:
        nimages += step
        try:
            newim = im.next()
            im = newim
        except Exception, error:
            pytraceback.print_exc()

            # Skip bad images
            logger.warning("Got a problem here: %s", error)
            try:
                im.filename = next_filename(im.filename)
            except Exception, error:
                # KE: This will not work and will throw an exception
                # fabio.next_filename doesn't understand %nnnn on the end
                logger.warning("Got another problem here: %s", error)
                im.filename = next_filename(im.sequencefilename)
            yield None
Exemplo n.º 2
0
def new_file_series0(first_object, first=None, last=None, step=1):
    """
    Created from a fabio image
    first and last are file numbers

    """
    im = first_object
    nimages = 0
    # for counting images
    if None in (first, last):
        step = 0
        total = 1
    else:
        total = last - first

    yield im
    while nimages < total:
        nimages += step
        try:
            newim = im.next()
            im = newim
        except Exception, error:
            pytraceback.print_exc()

            # Skip bad images
            logger.warning("Got a problem here: %s", error)
            try:
                im.filename = next_filename(im.filename)
            except Exception, error:
                # KE: This will not work and will throw an exception
                # fabio.next_filename doesn't understand %nnnn on the end
                logger.warning("Got another problem here: %s", error)
                im.filename = next_filename(im.sequencefilename)
            yield None
Exemplo n.º 3
0
def new_file_series(first_object, nimages=0, step=1, traceback=False):
    """
    A generator function that creates a file series starting from a a fabioimage.
    Iterates through all images in a file (if more than 1), then proceeds to
    the next file as determined by fabio.next_filename.
    
    first_object: the starting fabioimage, which will be the first one yielded
      in the sequence
    nimages:  the maximum number of images to consider
    step: step size, will yield the first and every step'th image until nimages
      is reached.  (e.g. nimages = 5, step = 2 will yield 3 images (0, 2, 4) 
    traceback: if True causes it to print a traceback in the event of an
      exception (missing image, etc.).  Otherwise the calling routine can handle
      the exception as it chooses 
    yields: the next fabioimage in the series.
      In the event there is an exception, it yields the sys.exec_info for the
      exception instead.  sys.exec_info is a tuple:
        ( exceptionType, exceptionValue, exceptionTraceback )
      from which all the exception information can be obtained.
      Suggested usage:
        for obj in new_file_series( ... ):
          if not isinstance( obj, fabio.fabioimage.fabioimage ):
            # deal with errors like missing images, non readable files, etc
            # e.g.
            traceback.print_exception(obj[0], obj[1], obj[2])
    """
    im = first_object
    nprocessed = 0
    abort = False
    if nimages > 0:
        yield im
        nprocessed += 1
    while nprocessed < nimages:
        try:
            newim = im.next()
            im = newim
            retVal = im
        except Exception, ex:
            import sys
            retVal = sys.exc_info()
            if(traceback):
                import traceback
                traceback.print_exc()
                # Skip bad images
                print "Got a problem here: next() failed"
            # Skip bad images
            try:
                im.filename = next_filename(im.filename)
            except:
                pass
        if nprocessed % step == 0:
            yield retVal
            # Avoid cyclic references with exc_info ?
            retVal = None
            if abort: break
        nprocessed += 1
Exemplo n.º 4
0
 def next(self):
     """
     Get the next image in a series as a fabio image
     """
     if self.currentframe < (self.nframes - 1) and self.nframes > 1:
         return self.getframe(self.currentframe + 1)
     else:
         newobj = GEimage()
         newobj.read(next_filename(self.sequencefilename))
         return newobj
Exemplo n.º 5
0
 def next(self):
     """
     Get the next image in a series as a fabio image
     """
     if self.currentframe < (self.nframes - 1) and self.nframes > 1:
         return self.getframe(self.currentframe + 1)
     else:
         newobj = GEimage()
         newobj.read(next_filename(self.sequencefilename))
         return newobj
Exemplo n.º 6
0
def new_file_series(first_object, nimages=0, step=1, traceback=False):
    """
    A generator function that creates a file series starting from a a fabioimage.
    Iterates through all images in a file (if more than 1), then proceeds to
    the next file as determined by fabio.next_filename.

    @param first_object: the starting fabioimage, which will be the first one yielded
        in the sequence
    @param nimages:  the maximum number of images to consider
        step: step size, will yield the first and every step'th image until nimages
        is reached.  (e.g. nimages = 5, step = 2 will yield 3 images (0, 2, 4)
    @param traceback: if True causes it to print a traceback in the event of an
        exception (missing image, etc.).  Otherwise the calling routine can handle
        the exception as it chooses
    @param yields: the next fabioimage in the series.
        In the event there is an exception, it yields the sys.exec_info for the
        exception instead.  sys.exec_info is a tuple:
        ( exceptionType, exceptionValue, exceptionTraceback )
        from which all the exception information can be obtained.

    Suggested usage:
    
    ::
    
        for obj in new_file_series( ... ):
          if not isinstance(obj, fabio.fabioimage.fabioimage ):
            # deal with errors like missing images, non readable files, etc
            # e.g.
            traceback.print_exception(obj[0], obj[1], obj[2])

    """
    im = first_object
    nprocessed = 0
    abort = False
    if nimages > 0:
        yield im
        nprocessed += 1
    while nprocessed < nimages:
        try:
            newim = im.next()
            im = newim
            retVal = im
        except Exception, ex:
            retVal = sys.exc_info()
            if (traceback):
                pytraceback.print_exc()
                # Skip bad images
                logger.warning("Got a problem here: next() failed %s", ex)
            # Skip bad images
            try:
                im.filename = next_filename(im.filename)
            except Exception, ex:
                logger.warning(
                    "Got another problem here: next_filename(im.filename) %s",
                    ex)
Exemplo n.º 7
0
 def next(self):
     """ returns the next file in the series as a fabioimage """
     import openimage
     return openimage.openimage(
         fabioutils.next_filename(self.filename))
Exemplo n.º 8
0
 def next(self):
     """ returns the next file in the series as a fabioimage """
     import openimage
     return openimage.openimage(fabioutils.next_filename(self.filename))