# FIXME: If we have more than 1 copies -- This is tricky because we need
        # to pare down the duplicate sngl rows too
        maxlnevid = numpy.max([s.snr for s in results])
        total_evid = numpy.exp([s.snr - maxlnevid for s in results]).sum()
        for res in results:
            res.snr = numpy.exp(res.snr - maxlnevid) / total_evid

        # FIXME: this needs to be done in a more consistent way
        results = numpy.array([res.snr for res in results])

#
# Build (or retrieve) the initial region
#
if opts.refine or opts.prerefine:
    init_region, region_labels = amrlib.load_init_region(opts.refine
                                                         or opts.prerefine,
                                                         get_labels=True)
else:
    ####### BEGIN INITIAL GRID CODE #########
    init_region, idx = determine_region(pt, pts, ovrlp, opts.overlap_threshold,
                                        expand_prms)
    region_labels = intr_prms
    # FIXME: To be reimplemented in a different way
    #if opts.expand_param is not None:
    #expand_param(init_region, opts.expand_param)

    # TODO: Alternatively, check density of points in the region to determine
    # the points to a side
    grid, spacing = amrlib.create_regular_grid_from_cell(init_region,
                                                         side_pts=5,
                                                         return_cells=True)
        # overflows later on
        # FIXME: If we have more than 1 copies -- This is tricky because we need
        # to pare down the duplicate sngl rows too
        maxlnevid = numpy.max([s.snr for s in results])
        total_evid = numpy.exp([s.snr - maxlnevid for s in results]).sum()
        for res in results:
            res.snr = numpy.exp(res.snr - maxlnevid)/total_evid

        # FIXME: this needs to be done in a more consistent way
        results = numpy.array([res.snr for res in results])

#
# Build (or retrieve) the initial region
#
if opts.refine or opts.prerefine:
    init_region, region_labels = amrlib.load_init_region(opts.refine or opts.prerefine, get_labels=True)
else:
    ####### BEGIN INITIAL GRID CODE #########
    init_region, idx = determine_region(pt, pts, ovrlp, opts.overlap_threshold, expand_prms)
    region_labels = intr_prms
    # FIXME: To be reimplemented in a different way
    #if opts.expand_param is not None:
        #expand_param(init_region, opts.expand_param)

    # TODO: Alternatively, check density of points in the region to determine
    # the points to a side
    grid, spacing = amrlib.create_regular_grid_from_cell(init_region, side_pts=5, return_cells=True)

    # "Deactivate" cells not close to template points
    # FIXME: This gets more and more dangerous in higher dimensions
    # FIXME: Move to function
        # overflows later on
        # FIXME: If we have more than 1 copies -- This is tricky because we need
        # to pare down the duplicate sngl rows too
        maxlnevid = numpy.max([s.snr for s in results])
        total_evid = numpy.exp([s.snr - maxlnevid for s in results]).sum()
        for res in results:
            res.snr = numpy.exp(res.snr - maxlnevid)/total_evid

        # FIXME: this needs to be done in a more consistent way
        results = numpy.array([res.snr for res in results])

#
# Build (or retrieve) the initial region
#
if opts.refine or opts.prerefine:
    init_region = amrlib.load_init_region(opts.refine or opts.prerefine)
else:
    ####### BEGIN INITIAL GRID CODE #########
    init_region, idx = determine_region(pt, pts, ovrlp, opts.overlap_threshold, expand_prms)
    # FIXME: To be reimplemented in a different way
    #if opts.expand_param is not None:
        #expand_param(init_region, opts.expand_param)

    # TODO: Alternatively, check density of points in the region to determine
    # the points to a side
    grid, spacing = amrlib.create_regular_grid_from_cell(init_region, side_pts=5, return_cells=True)

    # "Deactivate" cells not close to template points
    # FIXME: This gets more and more dangerous in higher dimensions
    # FIXME: Move to function
    tree = BallTree(grid)