Exemplo n.º 1
0
    def run_on_image(self, rssdata, tracemap, current_vph):
        """Extract spectra, find peaks and compute FWHM."""

        # Extract the polynomials
        # FIXME: a little hackish
        valid_traces = get_valid_traces(tracemap)
        pols = [t.polynomial for t in tracemap.contents]
        vph_t = vph_thr['default']
        this_val = vph_t.get(current_vph)
        if this_val:
            flux_limit = this_val.get('flux_limit', 200000)
        else:
            flux_limit = 40000

        nwinwidth = 5
        times_sigma = 50.0
        lwidth = 20
        fpeaks = {}
        # FIXME: We are using here only one in 10 fibers
        for fibid in valid_traces[::10]:
            # sampling every 10 fibers...
            idx = fibid - 1
            row = rssdata[idx, :]

            the_pol = pols[idx]

            # FIXME: using here a different peak routine than in arc
            # find peaks
            threshold = numpy.median(row) + times_sigma * sigmaG(row)

            ipeaks_int1 = find_peaks_indexes(row, nwinwidth, threshold)
            # filter by flux
            self.logger.info('Filtering peaks over %5.0f', flux_limit)
            ipeaks_vals = row[ipeaks_int1]
            mask = ipeaks_vals < flux_limit
            ipeaks_int = ipeaks_int1[mask]
            self.logger.debug('LEN (ipeaks_int): %s', len(ipeaks_int))
            self.logger.debug('ipeaks_int: %s', ipeaks_int)
            ipeaks_float = refine_peaks(row, ipeaks_int, nwinwidth)[0]

            # self.pintarGrafica(refine_peaks(row, ipeaks_int, nwinwidth)[0] - refinePeaks_spectrum(row, ipeaks_int, nwinwidth))

            fpeaks[idx] = []
            for peak, peak_f in zip(ipeaks_int, ipeaks_float):
                try:
                    sl = numina.array.utils.slice_create(peak, lwidth)
                    rel_peak = peak - sl.start
                    qslit = row[sl]
                    peak_val, fwhm = fmod.compute_fwhm_1d_simple(qslit, rel_peak)
                    peak_on_trace = the_pol(peak)
                    fpeaks[idx].append((peak_f, peak_on_trace, fwhm))
                except ValueError as error:
                    self.logger.warning('Error %s computing FWHM in fiber %d', error, idx + 1)
                except IndexError as error:
                    self.logger.warning('Error %s computing FWHM in fiber %d', error, idx + 1)
            self.logger.debug('found %d peaks in fiber %d', len(fpeaks[idx]), idx)
        return fpeaks
Exemplo n.º 2
0
    def run_on_image(self, img, tracemap, flux_limit=40000, valid_traces=None, times_sigma=50):
        """Extract spectra, find peaks and compute FWHM."""

        rssdata = img[0].data

        if valid_traces:
            valid_traces_s = set(valid_traces) # use set for fast membership
            valid_apers = [aper for aper in tracemap.contents if aper.valid and aper.fibid in valid_traces_s]
        else:
            valid_apers = [aper for aper in tracemap.contents if aper.valid]

        nwinwidth = 5
        lwidth = 20
        fpeaks = {}

        for aper in valid_apers:
            fibid = aper.fibid
            idx = fibid - 1
            row = rssdata[idx, :]

            the_pol = aper.polynomial

            # FIXME: using here a different peak routine than in arc
            # find peaks
            threshold = numpy.median(row) + times_sigma * sigmaG(row)
            self.logger.debug('values for threshold: median: %f, scale: %f, sigma: %f',
                              numpy.median(row), times_sigma, sigmaG(row))
            self.logger.debug('threshold is: %f', threshold)
            ipeaks_int1 = find_peaks_indexes(row, nwinwidth, threshold)
            # filter by flux
            self.logger.info('Filtering peaks over %5.0f', flux_limit)
            ipeaks_vals = row[ipeaks_int1]
            mask = ipeaks_vals < flux_limit
            ipeaks_int = ipeaks_int1[mask]
            self.logger.debug('LEN (ipeaks_int): %s', len(ipeaks_int))
            self.logger.debug('ipeaks_int: %s', ipeaks_int)
            ipeaks_float = refine_peaks(row, ipeaks_int, nwinwidth)[0]

            # self.pintarGrafica(refine_peaks(row, ipeaks_int, nwinwidth)[0] - refinePeaks_spectrum(row, ipeaks_int, nwinwidth))

            fpeaks[fibid] = []
            for peak, peak_f in zip(ipeaks_int, ipeaks_float):
                try:
                    sl = numina.array.utils.slice_create(peak, lwidth)
                    rel_peak = peak - sl.start
                    qslit = row[sl]
                    peak_val, fwhm = fmod.compute_fwhm_1d_simple(qslit, rel_peak)
                    peak_on_trace = the_pol(peak)
                    fpeaks[fibid].append((peak_f, peak_on_trace, fwhm))
                except ValueError as error:
                    self.logger.warning('Error %s computing FWHM in fiber %d', error, fibid)
                except IndexError as error:
                    self.logger.warning('Error %s computing FWHM in fiber %d', error, fibid)
            self.logger.debug('found %d peaks in fiber %d', len(fpeaks[fibid]), fibid)
        return fpeaks
Exemplo n.º 3
0
    def obtain_boxes_from_image(self, reduced, expected, npeaks, cstart=2000):
        from numina.array.peaks.peakdet import find_peaks_indexes
        col = cstart
        data = reduced[0].data
        rr = data[:, col-1:col+1].mean(axis=1)
        # standarize
        rr -= numpy.median(rr)
        rr /= rr.max()
        rr *= -1

        cb = cosinebell(len(rr), 0.10)
        cbr = cb * rr
        plt.plot(cbr)
        plt.show()
        xv = numpy.fft.fftfreq(len(cbr))
        yv = numpy.fft.fft(cbr)
        plt.xlim([0.0, 0.5])
        plt.semilogy(xv, numpy.abs(yv.real))
        plt.show()

        cut = abs(xv) > 0.1
        yv[cut] = 0
        res = numpy.fft.ifft(yv)
        final = res.real
        plt.plot(final)
        #trend = detrend(final)
        #plt.plot(final - trend)
        plt.show()

        idx = find_peaks_indexes(final, window_width=3, threshold=0.3, fpeak=1)

        # We expect  differentnumber of pekas in LCB/MOS
        # order by intensity
        peak_flux = final[idx]
        # Number of peaks must be >=18
        npeaks = npeaks + 1
        fidx = numpy.argsort(peak_flux)[:-(npeaks+1):-1]
        nidx = idx[fidx]
        nidxs = numpy.sort(nidx)

        plt.plot(final)
        #plt.scatter(idx, [0.9 for m in idx])
        plt.scatter(nidx, [0.95 for m in nidx], c='r')
        plt.scatter(expected, [1.0 for m in expected])
        plt.show()

        plt.scatter(expected, nidxs - expected)
        plt.show()

        print("expected", expected)
        print("nidx", nidxs)

        return nidxs, col
Exemplo n.º 4
0
def refine_bar_centroid(arr_deriv, centerx, centery, wx, wy, threshold, sign):
    # Refine values
    logger = logging.getLogger('emir.recipes.bardetect')

    logger.debug('collapsing a %d x %d region', 2 * wx + 1, 2 * wy + 1)
    #
    slicey = slice_create(centery, wy, start=1, stop=2047)
    slicex = slice_create(centerx, wx, start=1, stop=2047)
    region = arr_deriv[slicey, slicex]

    if region.size == 0:
        logger.debug('region to collapse is empty')
        return 0, 0, 1

    collapsed = sign * region.mean(axis=0)

    # Fine tunning
    idxs_t = find_peaks_indexes(collapsed, window_width=3, threshold=threshold)
    # Use only the peak nearest the original peak
    if len(idxs_t) == 0:
        logger.debug('no peaks after fine-tunning')
        return 0, 0, 2

    dist_t = numpy.abs(idxs_t - wx)
    only_this = dist_t.argmin()
    idxs_p = numpy.atleast_1d(idxs_t[only_this])
    x_t, y_t = refine_peaks(collapsed, idxs_p, window_width=3)

    if len(x_t) == 0:
        logger.debug('no peaks to refine after fitting')
        return 0, 0, 2

    if x_t[0] >= collapsed.shape[0]:
        logger.debug('wrong position %d when refining', x_t[0])
        return 0, 0, 2

    _, fwhm_x = fmod.compute_fwhm_1d_simple(collapsed, x_t[0])

    xl = centerx - wx + x_t[0]
    return xl, fwhm_x, 0
Exemplo n.º 5
0
def refine_bar_centroid(arr_deriv, centerx, centery, wx, wy, threshold, sign):
    # Refine values
    logger = logging.getLogger('emir.recipes.bardetect')

    logger.debug('collapsing a %d x %d region', 2 * wx + 1 , 2 * wy + 1)
    #
    slicey = slice_create(centery, wy, start=1, stop=2047)
    slicex = slice_create(centerx, wx, start=1, stop=2047)
    region = arr_deriv[slicey, slicex]

    if region.size == 0:
        logger.debug('region to collapse is empty')
        return 0, 0, 1

    collapsed = sign * region.mean(axis=0)

    # Fine tunning
    idxs_t = find_peaks_indexes(collapsed, window_width=3, threshold=threshold)
    # Use only the peak nearest the original peak
    if len(idxs_t) == 0:
        logger.debug('no peaks after fine-tunning')
        return 0, 0, 2

    dist_t = numpy.abs(idxs_t - wx)
    only_this = dist_t.argmin()
    idxs_p = numpy.atleast_1d(idxs_t[only_this])
    x_t, y_t = refine_peaks(collapsed, idxs_p, window_width=3)

    if len(x_t) == 0:
        logger.debug('no peaks to refine after fitting')
        return 0, 0, 2

    if x_t[0] >= collapsed.shape[0]:
        logger.debug('wrong position %d when refining', x_t[0])
        return 0, 0, 2

    _, fwhm_x = fmod.compute_fwhm_1d_simple(collapsed, x_t[0])

    xl = centerx - wx + x_t[0]
    return xl, fwhm_x, 0
Exemplo n.º 6
0
def char_bar_height(arr_deriv_alt,
                    xpos1,
                    xpos2,
                    centery,
                    threshold,
                    wh=35,
                    wfit=3):

    logger = logging.getLogger('emir.recipes.bardetect')
    pcentery = coor_to_pix_1d(centery)
    slicey = slice_create(pcentery, wh, start=1, stop=2047)

    ref_pcentery = pcentery - slicey.start
    mm = arr_deriv_alt[slicey, xpos1:xpos2 + 1].mean(axis=-1)

    idxs_t = find_peaks_indexes(mm, window_width=3, threshold=threshold)
    idxs_u = find_peaks_indexes(-mm, window_width=3, threshold=threshold)
    # Peaks on the right

    status = 0
    npeaks_u = len(idxs_u)
    if npeaks_u == 0:
        # This is a problem, no peak on the right
        b2 = 0
        status = 4
        logger.debug('no bottom border found')
    else:
        # Filter over reference
        g_idxs_u = idxs_u[idxs_u >= ref_pcentery]
        if len(g_idxs_u) == 0:
            logger.debug('no peak over center')
            b2 = 0
            status = 4
        else:
            x_u, y_u = refine_peaks(-mm, g_idxs_u, window_width=wfit)
            # Select the peak with max derivative
            if len(x_u) == 0 or len(y_u) == 0:
                logger.warning("no 1st peak found after refine")
                b2 = 0
                status = 4
            else:
                idmax = y_u.argmax()
                b2 = x_u[idmax]
                b2val = y_u[idmax]
                logger.debug('main border in %f', slicey.start + b2)

    # peaks on the left
    npeaks_t = len(idxs_t)
    if npeaks_t == 0:
        # This is a problem, no peak on the left
        b1 = 0
        logger.debug('no top border found')
        status = 40 + status
    else:
        g_idxs_t = idxs_t[idxs_t <= ref_pcentery]
        if len(g_idxs_t) == 0:
            logger.debug('no peak under center')
            b1 = 0
            status = 40 + status
        else:
            x_t, y_t = refine_peaks(mm, g_idxs_t, window_width=wfit)
            # Select the peak with max derivative
            if len(x_t) == 0 or len(y_t) == 0:
                logger.warning("no 2nd peak found after refine")
                b1 = 0
                status = 40 + status
            else:
                idmax = y_t.argmax()
                b1 = x_t[idmax]
                b1val = y_t[idmax]
                logger.debug('second border in %f', slicey.start + b1)

    return slicey.start + b1, slicey.start + b2, status
Exemplo n.º 7
0
def _char_bar_peak(arr_deriv, ypix, bstart, bend, th, sign=1):

    # extract a region to average
    # wy = 3
    # wx = 10
    # Fit the peak with these points
    # wfit = 3

    logger = logging.getLogger(__name__)

    yvpix = numpy.clip(ypix, 0, 2047)

    # Refine at different positions along the slit
    newrefine = []
    wx = 5
    wy = 1
    step = 2 * wy + 1
    # visibility
    #
    intv1 = [0, 2047]
    intv2 = [yvpix - 18, yvpix + 18]
    logger.debug('overlaping interval %s', intv2)

    bar_overlap = overlap(intv1, intv2)
    logger.debug('bar overlaping %.1f', bar_overlap)
    offs = []
    if bar_overlap < 10:
        maxval = 18
    else:
        maxval = 12
    offs2 = range(-step, -maxval, -step)
    offs.extend(reversed(offs2))
    offs.extend(range(0, maxval, step))

    cut = sign * arr_deriv[yvpix, bstart:bend]

    idxs = find_peaks_indexes(cut, window_width=3, threshold=th, fpeak=1)
    logger.debug('found %d peaks over threshold %f', len(idxs), th)

    if len(idxs) == 0:
        logger.debug('no peaks, exit')
        return 0, 0, 0, 0, 0, 1

    # Characterize: use the peak that has the greatest value in the derivative?
    pix_m = cut[idxs].argmax()
    centerx = bstart + idxs[pix_m]
    logger.debug('select the peak with maximum derivative')

    centery = yvpix
    logger.debug('centery is %7.2f at position %7.2f', centery + 1,
                 centerx + 1)
    # Refine at the computed center
    xl, fwhm_x, st = refine_bar_centroid(arr_deriv, centerx, centery, wx, wy,
                                         th, sign)
    logger.debug('measured values %7.2f (FWHM %7.2f)', xl, fwhm_x)

    if st != 0:
        logger.debug('faillure refining bar centroid, go to next bar')
        # Exiting now, can't refine the centroid
        return centery, centery, xl, xl, fwhm_x, st

    # This is basically to build a list of centers that dont overlap
    for off in offs:
        if 0 <= centery + off <= 2047:
            logger.debug('looping, off %d, measuring at %7.2f', off,
                         centery + off + 1)
            res = refine_bar_centroid(arr_deriv, centerx, centery + off, wx,
                                      wy, th, sign)
            logger.debug('looping, measured values %7.2f (FWHM %7.2f)', res[0],
                         res[1])
            newrefine.append(res)
        else:
            logger.debug('looping, off %d, skipping position %7.2f', off,
                         centery + off + 1)

    # this goes in FITS pix coordinates, adding 1
    # filter values with status != 0
    valid_mt = [r[2] == 0 for r in newrefine]
    xcoords_mt = [r[0] + 1 for r in newrefine]
    ycoords_mt = [centery + off + 1 for off in offs]

    ycoords_m = list(itertools.compress(ycoords_mt, valid_mt))
    xcoords_m = list(itertools.compress(xcoords_mt, valid_mt))

    if len(xcoords_m) == 0:
        logger.debug('no valid values to refine')
        return centery, centery, xl, xl, fwhm_x, 3

    logger.debug('transform values from real to virtual')
    xcoords_t, ycoords_t = dist.pvex(xcoords_m, ycoords_m)
    logger.debug('real xcoords are: %s:', xcoords_m)
    logger.debug('real ycoords are: %s:', ycoords_m)
    logger.debug('virtual xcoords are: %s:', xcoords_t)
    logger.debug('virtual ycoords are: %s:', ycoords_t)
    avg_xl_virt = numpy.mean(xcoords_t)
    logger.debug('reference real xcoord is: %s:', xl)
    logger.debug('average virtual xcoord is: %s:', avg_xl_virt)

    centerx_virt, centery_virt = dist.pvex(centerx + 1, centery + 1)

    return centery, centery_virt, xl, avg_xl_virt, fwhm_x, 0
Exemplo n.º 8
0
def _char_bar_peak(arr_deriv,
                   ypix,
                   bstart,
                   bend,
                   th,
                   center_of_bar=None,
                   wx=10,
                   wy=15,
                   wfit=3,
                   sign=1):

    # extract a region to average
    # wy = 3
    # wx = 10
    # Fit the peak with these points
    # wfit = 3

    logger = logging.getLogger('emir.recipes.bardetect')

    cut = sign * arr_deriv[ypix, bstart:bend]

    idxs = find_peaks_indexes(cut, window_width=3, threshold=th, fpeak=1)
    logger.debug('found %d peaks over threshold %f', len(idxs), th)

    if len(idxs) == 0:
        logger.debug('no peaks, exit')
        return 0, 0, 0, 0, 0, 1

    # Characterize: use the peak that has the greatest value in the derivative?
    pix_m = cut[idxs].argmax()
    centerx = bstart + idxs[pix_m]
    logger.debug('select the peak with maximum derivative')
    # This function should return the center of 'barid'
    # when its position is 'x'
    # without information, the best guess is 'ypix'
    if center_of_bar is None:
        logger.debug('using reference value for center of bar')
        centery = ypix
    else:
        centery = center_of_bar(centerx)

    logger.debug('centery is %7.2f at position %7.2f', centery + 1,
                 centerx + 1)

    # Refine at the computed center
    xl, fwhm_x, st = refine_bar_centroid(arr_deriv, centerx, centery, wx, wy,
                                         th, sign)
    logger.debug('measured values %7.2f (FWHM %7.2f)', xl, fwhm_x)

    if st != 0:
        logger.debug('faillure refining bar centroid, go to next bar')
        # Exiting now, can't refine the centroid
        return centery, centery, xl, xl, fwhm_x, st

    # Refine at different positions along the slit
    newrefine = []
    wx = 5
    wy = 1
    step = 2 * wy + 1
    offs = []
    maxval = 18
    offs2 = range(-step, -maxval, -step)
    offs.extend(reversed(offs2))
    offs.extend(range(0, maxval, step))
    # This is basically to build a list of centers that dont overlap

    for off in offs:
        logger.debug('looping, off %d, measuring at %7.2f', off,
                     centery + off + 1)
        res = refine_bar_centroid(arr_deriv, centerx, centery + off, wx, wy,
                                  th, sign)
        logger.debug('looping, measured values %7.2f (FWHM %7.2f)', res[0],
                     res[1])
        newrefine.append(res)

    # this goes in FITS pix coordinates, adding 1
    # filter values with status != 0
    valid_mt = [r[2] == 0 for r in newrefine]
    xcoords_mt = [r[0] + 1 for r in newrefine]
    ycoords_mt = [centery + off + 1 for off in offs]

    ycoords_m = list(itertools.compress(ycoords_mt, valid_mt))
    xcoords_m = list(itertools.compress(xcoords_mt, valid_mt))

    if len(xcoords_m) == 0:
        logger.debug('no valid values to refine')
        return centery, centery, xl, xl, fwhm_x, 3

    logger.debug('transform values from real to virtual')
    xcoords_t, ycoords_t = dist.pvex(xcoords_m, ycoords_m)
    logger.debug('real xcoords are: %s:', xcoords_m)
    logger.debug('real ycoords are: %s:', ycoords_m)
    logger.debug('virtual xcoords are: %s:', xcoords_t)
    logger.debug('virtual ycoords are: %s:', ycoords_t)
    avg_xl_virt = numpy.mean(xcoords_t)
    logger.debug('reference real xcoord is: %s:', xl)
    logger.debug('average virtual xcoord is: %s:', avg_xl_virt)

    centerx_virt, centery_virt = dist.pvex(centerx + 1, centery + 1)

    return centery, centery_virt, xl, avg_xl_virt, fwhm_x, 0
Exemplo n.º 9
0
def char_bar_height(arr_deriv_alt, xpos1, xpos2, centery, threshold, wh=35, wfit=3):

    logger = logging.getLogger('emir.recipes.bardetect')
    pcentery = coor_to_pix_1d(centery)
    slicey = slice_create(pcentery, wh, start=1, stop=2047)

    ref_pcentery = pcentery - slicey.start
    mm = arr_deriv_alt[slicey, xpos1:xpos2 + 1].mean(axis=-1)

    idxs_t = find_peaks_indexes(mm, window_width=3,threshold=threshold)
    idxs_u = find_peaks_indexes(-mm, window_width=3,threshold=threshold)
    # Peaks on the right

    status = 0
    npeaks_u = len(idxs_u)
    if npeaks_u == 0:
        # This is a problem, no peak on the right
        b2 = 0
        status = 4
        logger.debug('no bottom border found')
    else:
        # Filter over reference
        g_idxs_u = idxs_u[idxs_u >= ref_pcentery]
        if len(g_idxs_u) == 0:
            logger.debug('no peak over center')
            b2 = 0
            status = 4
        else:
            x_u, y_u = refine_peaks(-mm, g_idxs_u, window_width=wfit)
            # Select the peak with max derivative
            if len(x_u) == 0 or len(y_u) == 0:
                logger.warning("no 1st peak found after refine")
                b2 = 0
                status = 4
            else:
                idmax = y_u.argmax()
                b2 = x_u[idmax]
                b2val = y_u[idmax]
                logger.debug('main border in %f', slicey.start + b2)

    # peaks on the left
    npeaks_t = len(idxs_t)
    if npeaks_t == 0:
        # This is a problem, no peak on the left
        b1 = 0
        logger.debug('no top border found')
        status = 40 + status
    else:
        g_idxs_t = idxs_t[idxs_t <= ref_pcentery]
        if len(g_idxs_t) == 0:
            logger.debug('no peak under center')
            b1 = 0
            status = 40 + status
        else:
            x_t, y_t = refine_peaks(mm, g_idxs_t, window_width=wfit)
            # Select the peak with max derivative
            if len(x_t) == 0 or len(y_t) == 0:
                logger.warning("no 2nd peak found after refine")
                b1 = 0
                status = 40 + status
            else:
                idmax = y_t.argmax()
                b1 = x_t[idmax]
                b1val = y_t[idmax]
                logger.debug('second border in %f', slicey.start + b1)

    return slicey.start + b1, slicey.start + b2, status
Exemplo n.º 10
0
def _char_bar_peak(arr_deriv, ypix, bstart, bend, th, sign=1):

    # extract a region to average
    # wy = 3
    # wx = 10
    # Fit the peak with these points
    # wfit = 3

    logger = logging.getLogger(__name__)

    yvpix = numpy.clip(ypix, 0, 2047)

    # Refine at different positions along the slit
    newrefine = []
    wx = 5
    wy = 1
    step = 2 * wy + 1
    # visibility
    #
    intv1 = [0, 2047]
    intv2 = [yvpix - 18, yvpix + 18]
    logger.debug('overlaping interval %s', intv2)

    bar_overlap = overlap(intv1, intv2)
    logger.debug('bar overlaping %.1f', bar_overlap)
    offs = []
    if bar_overlap < 10:
        maxval = 18
    else:
        maxval = 12
    offs2 = range(-step, -maxval, -step)
    offs.extend(reversed(offs2))
    offs.extend(range(0, maxval, step))

    cut = sign * arr_deriv[yvpix, bstart:bend]

    idxs = find_peaks_indexes(cut, window_width=3, threshold=th, fpeak=1)
    logger.debug('found %d peaks over threshold %f', len(idxs), th)

    if len(idxs) == 0:
        logger.debug('no peaks, exit')
        return 0, 0, 0, 0, 0, 1

    # Characterize: use the peak that has the greatest value in the derivative?
    pix_m = cut[idxs].argmax()
    centerx = bstart + idxs[pix_m]
    logger.debug('select the peak with maximum derivative')

    centery = yvpix
    logger.debug('centery is %7.2f at position %7.2f', centery+1,  centerx+1)
    # Refine at the computed center
    xl, fwhm_x, st = refine_bar_centroid(arr_deriv, centerx, centery, wx, wy, th, sign)
    logger.debug('measured values %7.2f (FWHM %7.2f)', xl, fwhm_x)

    if st != 0:
        logger.debug('faillure refining bar centroid, go to next bar')
        # Exiting now, can't refine the centroid
        return centery, centery, xl, xl, fwhm_x, st

    # This is basically to build a list of centers that dont overlap
    for off in offs:
        if 0 <= centery + off <= 2047:
            logger.debug('looping, off %d, measuring at %7.2f', off, centery + off + 1)
            res = refine_bar_centroid(arr_deriv, centerx, centery + off, wx, wy, th, sign)
            logger.debug('looping, measured values %7.2f (FWHM %7.2f)', res[0], res[1])
            newrefine.append(res)
        else:
            logger.debug('looping, off %d, skipping position %7.2f', off, centery + off + 1)

    # this goes in FITS pix coordinates, adding 1
    # filter values with status != 0
    valid_mt = [r[2] == 0 for r in newrefine]
    xcoords_mt = [r[0] + 1 for r in newrefine]
    ycoords_mt = [centery + off + 1 for off in offs]

    ycoords_m = list(itertools.compress(ycoords_mt, valid_mt))
    xcoords_m = list(itertools.compress(xcoords_mt, valid_mt))

    if len(xcoords_m) == 0:
        logger.debug('no valid values to refine')
        return centery, centery, xl, xl, fwhm_x, 3

    logger.debug('transform values from real to virtual')
    xcoords_t, ycoords_t = dist.pvex(xcoords_m, ycoords_m)
    logger.debug('real xcoords are: %s:', xcoords_m)
    logger.debug('real ycoords are: %s:', ycoords_m)
    logger.debug('virtual xcoords are: %s:', xcoords_t)
    logger.debug('virtual ycoords are: %s:', ycoords_t)
    avg_xl_virt = numpy.mean(xcoords_t)
    logger.debug('reference real xcoord is: %s:', xl)
    logger.debug('average virtual xcoord is: %s:', avg_xl_virt)

    centerx_virt, centery_virt = dist.pvex(centerx + 1, centery + 1)

    return centery, centery_virt, xl, avg_xl_virt, fwhm_x, 0