Ejemplo n.º 1
0
 def start_comp(self, seed_curve, name_template, cur_frame, disk_dict):
     # make the connection to the ether
     lb_view = Client(profile='vpn',
                      sshserver='10.8.0.1').load_balanced_view()
     # grab a copy of the paramters
     proc_prams = copy.copy(self.process_backend.params)
     # put in the start_frame
     if cur_frame is not None:
         proc_prams['start_frame'] = cur_frame
     name_template = leidenfrost.convert_base_path(name_template, disk_dict)
     # push to ether and hope!
     as_res = lb_view.apply_async(leidenfrost.proc.proc_cine_to_h5,
                                  self.process_backend.cine_.hash,
                                  name_template, proc_prams, seed_curve)
     print('fired: {}'.format(as_res.msg_id))
Ejemplo n.º 2
0
 def start_comp(self, seed_curve, name_template, cur_frame, disk_dict):
     # make the connection to the ether
     lb_view = Client(profile='vpn',
                      sshserver='10.8.0.1').load_balanced_view()
     # grab a copy of the paramters
     proc_prams = copy.copy(self.process_backend.params)
     # put in the start_frame
     if cur_frame is not None:
         proc_prams['start_frame'] = cur_frame
     name_template = leidenfrost.convert_base_path(name_template, disk_dict)
     # push to ether and hope!
     as_res = lb_view.apply_async(leidenfrost.proc.proc_cine_to_h5,
                         self.process_backend.cine_.hash,
                         name_template, proc_prams, seed_curve)
     print('fired: {}'.format(as_res.msg_id))
Ejemplo n.º 3
0
def proc_cine_to_h5(ch, hdf_fname_template, params, seed_curve):
    """
    Processes a cine path -> h5

    Parameters
    ----------
    ch : str
        Hash of the cine_fname

    hdf_fname_template: FilePath
        Template for where to put the output file + log files

    params : dict
        Parameters to use to process the cine file

    seed_curve : int
        The first frame to process

    """
    i_disk_dict = {
        0: u'/media/tcaswell/leidenfrost_a',
        1: u'/media/tcaswell/leidenfrost_c'
    }
    # make data base communication object
    db = ldb.LFmongodb(i_disk_dict=i_disk_dict)
    # set up logging stuff
    logger = logging.getLogger('proc_cine_frame_' + str(os.getpid()))
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
    # make a copy so we don't export side effects
    params = copy.copy(params)

    # convert disk
    hdf_fname_template = leidenfrost.convert_base_path(hdf_fname_template,
                                                       i_disk_dict)
    cine_md = db.get_movie_md(ch)
    cine_fname = leidenfrost.FilePath.from_db_dict(cine_md['fpath'],
                                                   i_disk_dict)

    # sort out output files names
    h5_fname = hdf_fname_template._replace(
        fname=cine_fname.fname.replace('cine', 'h5'))
    # get _id from DB
    _id, h5_fname = db.start_proc(ch, params, seed_curve, h5_fname)
    lh = logging.FileHandler(
        hdf_fname_template._replace(
            fname=h5_fname.fname.replace('h5', 'log')).format)

    start_frame = params.pop('start_frame', 0)
    end_frame = params.pop('end_frame', -1)
    if end_frame > 0 and end_frame < start_frame:
        raise Exception("invalid start and end frames")

    max_circ_change_frac = params.pop('max_circ_change', None)

    if os.path.isfile(h5_fname.format):
        print('panic!')
        logger.error("file already exists")
        db.remove_proc(_id)
        return

    stack = lb.ProcessBackend.from_args(cine_fname, **params)
    stack.gen_stub_h5(h5_fname.format, seed_curve, start_frame)
    hfb = lb.HdfBackend(h5_fname,
                        cine_base_path=cine_fname.base_path,
                        mode='rw')
    file_out = hfb.file
    logger.info('created file')

    if end_frame == -1:
        end_frame = len(stack)

    old_handler = signal.signal(signal.SIGALRM, _timeout_handler)

    try:
        lh.setFormatter(formatter)
        logger.addHandler(lh)

        for j in range(start_frame, end_frame):
            # set a 30s window, if the frame does not finish on 30s, kill it
            if hfb.contains_frame(j):
                logger.warn('deleting existing frame {0}'.format(j))
                hfb._del_frame(j)

            signal.alarm(45)
            start = time.time()
            mbe, new_seed_curve = stack.process_frame(j, seed_curve)
            if max_circ_change_frac is not None:
                # check if we are limiting how much the circumference
                # can change between frames
                old_circ = seed_curve.circ
                new_circ = new_seed_curve.circ
                # if it changes little enough, adopt the new seed
                # curve
                if (np.abs(old_circ - new_circ) / old_circ <
                        max_circ_change_frac):
                    seed_curve = new_seed_curve
            else:
                seed_curve = new_seed_curve
            signal.alarm(0)
            elapsed = time.time() - start
            logger.info('completed frame %d in %fs', j, elapsed)
            # set alarm to 0

            mbe.write_to_hdf(file_out)

            if j % 500 == 0:
                file_out.flush()
            del mbe
            #gc.collect()
    except TimeoutException:
        # handle the time out error
        logger.warn('timed out')
        # tell the DB we timed out
        db.timeout_proc(_id)
    except Exception as e:
        # handle all exceptions we should get
        logger.warn(str(e))
        db.error_proc(_id)
    except:
        # handle everything else
        logger.warn('raised exception not derived from Exception')
        db.error_proc(_id)
    else:
        # if we ran through the full movie, mark it done (yay)
        db.finish_proc(_id)
    finally:
        # make sure that no matter what the output file gets cleaned up
        file_out.close()
        # reset the alarm
        signal.alarm(0)
        # rest the signal handler
        signal.signal(signal.SIGALRM, old_handler)
        logger.removeHandler(lh)

    return None
Ejemplo n.º 4
0
def proc_cine_to_h5(ch, hdf_fname_template, params, seed_curve):
    """
    Processes a cine path -> h5

    Parameters
    ----------
    ch : str
        Hash of the cine_fname

    hdf_fname_template: FilePath
        Template for where to put the output file + log files

    params : dict
        Parameters to use to process the cine file

    seed_curve : int
        The first frame to process

    """
    i_disk_dict = {0: u'/media/tcaswell/leidenfrost_a', 1: u'/media/tcaswell/leidenfrost_c'}
    # make data base communication object
    db = ldb.LFmongodb(i_disk_dict=i_disk_dict)
    # set up logging stuff
    logger = logging.getLogger('proc_cine_frame_' + str(os.getpid()))
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
    # make a copy so we don't export side effects
    params = copy.copy(params)

    # convert disk
    hdf_fname_template = leidenfrost.convert_base_path(hdf_fname_template,
                                                       i_disk_dict)
    cine_md = db.get_movie_md(ch)
    cine_fname = leidenfrost.FilePath.from_db_dict(cine_md['fpath'], i_disk_dict)

    # sort out output files names
    h5_fname = hdf_fname_template._replace(
        fname=cine_fname.fname.replace('cine', 'h5'))
    # get _id from DB
    _id, h5_fname = db.start_proc(ch, params, seed_curve, h5_fname)
    lh = logging.FileHandler(hdf_fname_template._replace(
        fname=h5_fname.fname.replace('h5', 'log')).format)

    start_frame = params.pop('start_frame', 0)
    end_frame = params.pop('end_frame', -1)
    if end_frame > 0 and end_frame < start_frame:
        raise Exception("invalid start and end frames")

    max_circ_change_frac = params.pop('max_circ_change', None)

    if os.path.isfile(h5_fname.format):
        print ('panic!')
        logger.error("file already exists")
        db.remove_proc(_id)
        return

    stack = lb.ProcessBackend.from_args(cine_fname, **params)
    stack.gen_stub_h5(h5_fname.format, seed_curve, start_frame)
    hfb = lb.HdfBackend(h5_fname,
                        cine_base_path=cine_fname.base_path,
                        mode='rw')
    file_out = hfb.file
    logger.info('created file')

    if end_frame == -1:
        end_frame = len(stack)

    old_handler = signal.signal(signal.SIGALRM, _timeout_handler)

    try:
        lh.setFormatter(formatter)
        logger.addHandler(lh)

        for j in range(start_frame, end_frame):
            # set a 30s window, if the frame does not finish on 30s, kill it
            if hfb.contains_frame(j):
                logger.warn('deleting existing frame {0}'.format(j))
                hfb._del_frame(j)

            signal.alarm(45)
            start = time.time()
            mbe, new_seed_curve = stack.process_frame(j, seed_curve)
            if max_circ_change_frac is not None:
                # check if we are limiting how much the circumference
                # can change between frames
                old_circ = seed_curve.circ
                new_circ = new_seed_curve.circ
                # if it changes little enough, adopt the new seed
                # curve
                if (np.abs(old_circ - new_circ) / old_circ
                    < max_circ_change_frac):
                    seed_curve = new_seed_curve
            else:
                seed_curve = new_seed_curve
            signal.alarm(0)
            elapsed = time.time() - start
            logger.info('completed frame %d in %fs', j, elapsed)
            # set alarm to 0

            mbe.write_to_hdf(file_out)

            if j % 500 == 0:
                file_out.flush()
            del mbe
            #gc.collect()
    except TimeoutException:
        # handle the time out error
        logger.warn('timed out')
        # tell the DB we timed out
        db.timeout_proc(_id)
    except Exception as e:
        # handle all exceptions we should get
        logger.warn(str(e))
        db.error_proc(_id)
    except:
        # handle everything else
        logger.warn('raised exception not derived from Exception')
        db.error_proc(_id)
    else:
        # if we ran through the full movie, mark it done (yay)
        db.finish_proc(_id)
    finally:
        # make sure that no matter what the output file gets cleaned up
        file_out.close()
        # reset the alarm
        signal.alarm(0)
        # rest the signal handler
        signal.signal(signal.SIGALRM, old_handler)
        logger.removeHandler(lh)

    return None