def threshold_list(imagelist,
                   threshold,
                   fractional_threshold,
                   use_moment0=True,
                   prefix=''):
    """ Find actual threshold for list of results, optionally using moment 0

    :param imagelist:
    :param threshold: Absolute threshold
    :param fractional_threshold: Fractional  threshold
    :param use_moment0: Use moment 0 for threshold
    :return:
    """
    peak = 0.0
    for result in imagelist:
        if use_moment0:
            moments = calculate_image_frequency_moments(result)
            peak = max(
                peak,
                numpy.max(numpy.abs(moments.data[0, ...] / result.shape[0])))
        else:
            peak = max(peak, numpy.max(numpy.abs(result.data)))

    actual = max(peak * fractional_threshold, threshold)

    if use_moment0:
        log.info(
            "threshold_list %s: peak in moment 0 = %.6f, threshold will be %.6f"
            % (prefix, peak, actual))
    else:
        log.info("threshold_list %s: peak = %.6f, threshold will be %.6f" %
                 (prefix, peak, actual))

    return actual
예제 #2
0
 def test_calculate_image_frequency_moments(self):
     frequency = numpy.linspace(0.9e8, 1.1e8, 9)
     cube = create_low_test_image_from_gleam(npixel=512,
                                             cellsize=0.0001,
                                             frequency=frequency,
                                             flux_limit=1.0)
     log.debug(
         export_image_to_fits(cube,
                              fitsfile='%s/test_moments_cube.fits' %
                              (self.dir)))
     original_cube = copy_image(cube)
     moment_cube = calculate_image_frequency_moments(cube, nmoment=3)
     log.debug(
         export_image_to_fits(moment_cube,
                              fitsfile='%s/test_moments_moment_cube.fits' %
                              (self.dir)))
     reconstructed_cube = calculate_image_from_frequency_moments(
         cube, moment_cube)
     log.debug(
         export_image_to_fits(
             reconstructed_cube,
             fitsfile='%s/test_moments_reconstructed_cube.fits' %
             (self.dir)))
     error = numpy.std(reconstructed_cube.data - original_cube.data)
     assert error < 0.2
def threshold_list(imagelist, threshold, fractional_threshold, use_moment0=True, prefix=''):
    """ Find actual threshold for list of results, optionally using moment 0

    :param imagelist:
    :param threshold: Absolute threshold
    :param fractional_threshold: Fractional  threshold
    :param use_moment0: Use moment 0 for threshold
    :return:
    """
    peak = 0.0
    for i, result in enumerate(imagelist):
        if use_moment0:
            moments = calculate_image_frequency_moments(result)
            this_peak = numpy.max(numpy.abs(moments.data[0, ...] / result.shape[0]))
            peak = max(peak, this_peak)
            log.info("threshold_list: using moment 0, sub_image %d, peak = %f," % (i, this_peak))
        else:
            ref_chan = result.data.shape[0] // 2
            this_peak = numpy.max(numpy.abs(result.data[ref_chan]))
            peak = max(peak, this_peak)
            log.info("threshold_list: using refchan %d , sub_image %d, peak = %f," % (ref_chan, i, this_peak))

    actual = max(peak * fractional_threshold, threshold)
    
    
    if use_moment0:
        log.info("threshold_list %s: Global peak in moment 0 = %.6f, sub-image clean threshold will be %.6f" % (prefix,
                                                                                                           peak,
                                                                                                   actual))
    else:
        log.info("threshold_list %s: Global peak = %.6f, sub-image clean threshold will be %.6f" % (prefix, peak,
                                                                                                   actual))
    
    return actual
예제 #4
0
    def deconvolve(dirty, psf, model, facet, gthreshold):
        import time
        starttime = time.time()
        if prefix == '':
            lprefix = "facet %d" % facet
        else:
            lprefix = "%s, facet %d" % (prefix, facet)

        nmoments = get_parameter(kwargs, "nmoments", 0)

        if nmoments > 0:
            moment0 = calculate_image_frequency_moments(dirty)
            this_peak = numpy.max(numpy.abs(
                moment0.data[0, ...])) / dirty.data.shape[0]
        else:
            this_peak = numpy.max(numpy.abs(dirty.data[0, ...]))

        if this_peak > 1.1 * gthreshold:
            log.info(
                "deconvolve_arlexecute %s: cleaning - peak %.6f > 1.1 * threshold %.6f"
                % (lprefix, this_peak, gthreshold))
            kwargs['threshold'] = gthreshold
            result, _ = deconvolve_cube(dirty, psf, prefix=lprefix, **kwargs)

            if result.data.shape[0] == model.data.shape[0]:
                result.data += model.data
            else:
                log.warning(
                    "deconvolve_arlexecute %s: Initial model %s and clean result %s do not have the same shape"
                    % (lprefix, str(
                        model.data.shape[0]), str(result.data.shape[0])))

            flux = numpy.sum(result.data[0, 0, ...])
            log.info(
                '### %s, %.6f, %.6f, True, %.3f # cycle, facet, peak, cleaned flux, clean, time?'
                % (lprefix, this_peak, flux, time.time() - starttime))

            return result
        else:
            log.info(
                "deconvolve_arlexecute %s: Not cleaning - peak %.6f <= 1.1 * threshold %.6f"
                % (lprefix, this_peak, gthreshold))
            log.info(
                '### %s, %.6f, %.6f, False, %.3f # cycle, facet, peak, cleaned flux, clean, time?'
                % (lprefix, this_peak, 0.0, time.time() - starttime))

            return copy_image(model)