Helper function to interact with merged cands file and refine analysis

    candsfile is merged pkl file
    candloc (scan, segment, candint, dmind, dtind, beamnum) is as above.
    if no candloc, then it prints out cands above threshold.

def refine_cand(candsfile, candloc=[], candnum=-1, threshold=0, scaledm=2.1, scalepix=2, scaleuv=1.0, chans=[], returndata=False):
    """ Helper function to interact with merged cands file and refine analysis

    candsfile is merged pkl file
    candloc (scan, segment, candint, dmind, dtind, beamnum) is as above.
    if no candloc, then it prints out cands above threshold.
    """

    if candnum >= 0:
        candlocs, candprops, d0 = pc.read_candidates(candsfile, snrmin=threshold, returnstate=True)
        candloc = candlocs[candnum]
        candprop = candprops[candnum]

        logger.info('Refining cand {0} with features {1}'.format(candloc, candprop))
        values = rt.pipeline_refine(d0, candloc, scaledm=scaledm, scalepix=scalepix, scaleuv=scaleuv, chans=chans, returndata=returndata)
        return values

    elif candloc:
        logger.info('Refining cand {0}'.format(candloc))
        d0 = pickle.load(open(candsfile, 'r'))
        values = rt.pipeline_refine(d0, candloc, scaledm=scaledm, scalepix=scalepix, scaleuv=scaleuv, chans=chans, returndata=returndata)
        return d, cands
    else:
        return None