# Path: tkp/sourcefinder/extract.py
# BIGNUM = 99999.0
# class Island(object):
# class ParamSet(DictMixin):
# class Detection(object):
#     def __init__(self, data, rms, chunk, analysis_threshold, detection_map,
#         beam, deblend_nthresh, deblend_mincont, structuring_element,
#         rms_orig=None, flux_orig=None, subthrrange=None
#     ):
#     def deblend(self, niter=0):
#     def threshold(self):
#     def noise(self):
#     def sig(self):
#     def fit(self, fixed=None):
#     def __init__(self, clean_bias=0.0, clean_bias_error=0.0,
#                  frac_flux_cal_error=0.0, alpha_maj1=2.5, alpha_min1=0.5,
#                  alpha_maj2=0.5, alpha_min2=2.5, alpha_maj3=1.5, alpha_min3=1.5):
#     def __getitem__(self, item):
#     def __setitem__(self, item, value):
#     def keys(self):
#     def calculate_errors(self, noise, beam, threshold):
#     def _condon_formulae(self, noise, beam):
#     def _error_bars_from_moments(self, noise, beam, threshold):
#     def deconvolve_from_clean_beam(self, beam):
# def source_profile_and_errors(data, threshold, noise,
#                               beam, fixed=None):
#     def __init__(self, paramset, imagedata, chunk=None, eps_ra=0, eps_dec=0):
#     def __getstate__(self):
#     def __setstate__(self, attrdict):
#     def __getattr__(self, attrname):
#     def __str__(self):
#     def __repr__(self):
#     def _physical_coordinates(self):
#         def pixel_to_spatial(x, y):
#     def distance_from(self, x, y):
#     def serialize(self, ew_sys_err, ns_sys_err):


import logging
import itertools
import numpy
    import ndimage
from tkp.utility import containers
from tkp.utility.memoize import Memoize
from tkp.sourcefinder import utils
from tkp.sourcefinder import stats
from tkp.sourcefinder import extract
    from scipy import ndimage
            grid, numpy.mgrid[slicex, slicey],
            mode='nearest', order=INTERPOLATE_ORDER)

        # If the input grid was entirely masked, then the output map must
        # also be masked: there's no useful data here. We don't search for
        # sources on a masked background/RMS, so this data will be cleanly
        # skipped by the rest of the sourcefinder
        if numpy.ma.getmask(grid).all():
            my_map.mask = True
        elif roundup:
            # In some cases, the spline interpolation may produce values
            # lower than the minimum value in the map. If required, these
            # can be trimmed off. No point doing this if the map is already
            # fully masked, though.
            my_map = numpy.ma.MaskedArray(
                    data = numpy.where(
                        my_map >= numpy.min(grid), my_map, numpy.min(grid)),
                    mask = my_map.mask
            )
        return my_map

    ###########################################################################
    #                                                                         #
    # Source extraction.                                                      #
    #                                                                         #
    # Provides for both traditional (islands-above-RMS) and FDR source        #
    # extraction systems.                                                     #
    #                                                                         #
    ###########################################################################


# Path: tkp/sourcefinder/extract.py
# BIGNUM = 99999.0
# class Island(object):
# class ParamSet(DictMixin):
# class Detection(object):
#     def __init__(self, data, rms, chunk, analysis_threshold, detection_map,
#         beam, deblend_nthresh, deblend_mincont, structuring_element,
#         rms_orig=None, flux_orig=None, subthrrange=None
#     ):
#     def deblend(self, niter=0):
#     def threshold(self):
#     def noise(self):
#     def sig(self):
#     def fit(self, fixed=None):
#     def __init__(self, clean_bias=0.0, clean_bias_error=0.0,
#                  frac_flux_cal_error=0.0, alpha_maj1=2.5, alpha_min1=0.5,
#                  alpha_maj2=0.5, alpha_min2=2.5, alpha_maj3=1.5, alpha_min3=1.5):
#     def __getitem__(self, item):
#     def __setitem__(self, item, value):
#     def keys(self):
#     def calculate_errors(self, noise, beam, threshold):
#     def _condon_formulae(self, noise, beam):
#     def _error_bars_from_moments(self, noise, beam, threshold):
#     def deconvolve_from_clean_beam(self, beam):
# def source_profile_and_errors(data, threshold, noise,
#                               beam, fixed=None):
#     def __init__(self, paramset, imagedata, chunk=None, eps_ra=0, eps_dec=0):
#     def __getstate__(self):
#     def __setstate__(self, attrdict):
#     def __getattr__(self, attrname):
#     def __str__(self):
#     def __repr__(self):
#     def _physical_coordinates(self):
#         def pixel_to_spatial(x, y):
#     def distance_from(self, x, y):
#     def serialize(self, ew_sys_err, ns_sys_err):


# Path: tkp/sourcefinder/image.py
import logging
import itertools
import numpy
    import ndimage
from tkp.utility import containers
from tkp.utility.memoize import Memoize
from tkp.sourcefinder import utils
from tkp.sourcefinder import stats
from tkp.sourcefinder import extract
    from scipy import ndimage

            grid, numpy.mgrid[slicex, slicey],
            mode='nearest', order=INTERPOLATE_ORDER)

        # If the input grid was entirely masked, then the output map must
        # also be masked: there's no useful data here. We don't search for
        # sources on a masked background/RMS, so this data will be cleanly
        # skipped by the rest of the sourcefinder
        if numpy.ma.getmask(grid).all():
            my_map.mask = True
        elif roundup:
            # In some cases, the spline interpolation may produce values
            # lower than the minimum value in the map. If required, these
            # can be trimmed off. No point doing this if the map is already
            # fully masked, though.
            my_map = numpy.ma.MaskedArray(
                    data = numpy.where(
                        my_map >= numpy.min(grid), my_map, numpy.min(grid)),
                    mask = my_map.mask
            )
        return my_map

    ###########################################################################
    #                                                                         #
    # Source extraction.                                                      #
    #                                                                         #
    # Provides for both traditional (islands-above-RMS) and FDR source        #
    # extraction systems.                                                     #
    #                                                                         #
    ###########################################################################


    def extract(self, det, anl, noisemap=None, bgmap=None, labelled_data=None,