# Path: sourcefinder/testutil/data.py
# DATAPATH = os.environ.get('TKP_TESTPATH', DEFAULT)
# 
# Path: sourcefinder/testutil/decorators.py
# def requires_data(*args):
#     for filename in args:
#         if not os.path.exists(filename):
#             return unittest.skip("Test data (%s) not available" % filename)
#     return lambda func: func
# 
# def duration(test_duration):
#     max_duration = float(os.environ.get("TKP_MAXTESTDURATION", False))
#     if max_duration:
#         if max_duration < test_duration:
#             return unittest.skip(
#              "Tests of duration > %s disabled with TKP_MAXTESTDURATION" %
#                 max_duration)
#     return lambda func: func
# 
# Path: sourcefinder/image.py
# INTERPOLATE_ORDER = 1  # Spline order for grid interpolation
# MEDIAN_FILTER = 0  # If non-zero, apply a median filter of size
# MF_THRESHOLD = 0  # If MEDIAN_FILTER is non-zero, only use the filtered
# DEBLEND_MINCONT = 0.005  # Min. fraction of island flux in deblended subisland
# STRUCTURING_ELEMENT = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]  # Island connectiivty
#         RMS_FILTER = 0.001
# class ImageData(object):
#     def __init__(self, data, beam, wcs, margin=0, radius=0, back_size_x=32,
#                  back_size_y=32, residuals=True
#                  ):
#     def _grids(self):
#     def _backmap(self):
#     def _set_backmap(self, bgmap):
#     def _get_rm(self):
#     def _set_rm(self, noisemap):
#     def _get_data(self):
#     def _get_data_bgsubbed(self):
#     def xdim(self):
#     def ydim(self):
#     def pixmax(self):
#     def pixmin(self):
#     def clearcache(self):
#     def __grids(self):
#     def _interpolate(self, grid, roundup=False):
#     def extract(self, det, anl, noisemap=None, bgmap=None, labelled_data=None,
#                 labels=None, deblend_nthresh=0, force_beam=False):
#     def reverse_se(self, det):
#     def fd_extract(self, alpha, anl=None, noisemap=None,
#                    bgmap=None, deblend_nthresh=0, force_beam=False
#                    ):
#     def flux_at_pixel(self, x, y, numpix=1):
#     def box_slice_about_pixel(x, y, box_radius):
#     def fit_to_point(self, x, y, boxsize, threshold, fixed):
#     def fit_fixed_positions(self, positions, boxsize, threshold=None,
#                             fixed='position+shape',
#                             ids=None):
#     def label_islands(self, detectionthresholdmap, analysisthresholdmap):
#     def _pyse(
#             self, detectionthresholdmap, analysisthresholdmap,
#             deblend_nthresh, force_beam, labelled_data=None, labels=[]
#     ):
#         def is_usable(det):
#             def check_point(x, y):


import os
import unittest
import numpy as np
import sourcefinder.accessors
from sourcefinder.testutil.data import DATAPATH
from sourcefinder.testutil.decorators import requires_data, duration
from sourcefinder import image
        # in particular, can be biased low if the background levels
        # are biased high.  The background and noise levels supplied
        # here are the true values.

        extraction_results = img.extract(
            det=10.0, anl=6.0,
            noisemap=np.ma.array(BG_STD * np.ones((2048, 2048))),
            bgmap=np.ma.array(BG_MEAN * np.ones((2048, 2048))))
        self.number_sources = len(extraction_results)

        peak_fluxes = []
        deconv_smajaxes = []
        deconv_sminaxes = []
        deconv_bpas = []

        for sources in extraction_results:
            peak_fluxes.append([sources.peak.value, sources.peak.error])
            deconv_smajaxes.append([sources.smaj_dc.value,
                                    sources.smaj_dc.error])
            deconv_sminaxes.append([sources.smin_dc.value,
                                    sources.smin_dc.error])
            deconv_bpas.append([sources.theta_dc.value,
                                sources.theta_dc.error])

        self.peak_fluxes = np.array(peak_fluxes)
        self.deconv_smajaxes = np.array(deconv_smajaxes)
        self.deconv_sminaxes = np.array(deconv_sminaxes)
        self.deconv_bpas = np.array(deconv_bpas)

    @duration(100)

# Path: sourcefinder/testutil/data.py
# DATAPATH = os.environ.get('TKP_TESTPATH', DEFAULT)
# 
# Path: sourcefinder/testutil/decorators.py
# def requires_data(*args):
#     for filename in args:
#         if not os.path.exists(filename):
#             return unittest.skip("Test data (%s) not available" % filename)
#     return lambda func: func
# 
# def duration(test_duration):
#     max_duration = float(os.environ.get("TKP_MAXTESTDURATION", False))
#     if max_duration:
#         if max_duration < test_duration:
#             return unittest.skip(
#              "Tests of duration > %s disabled with TKP_MAXTESTDURATION" %
#                 max_duration)
#     return lambda func: func
# 
# Path: sourcefinder/image.py
# INTERPOLATE_ORDER = 1  # Spline order for grid interpolation
# MEDIAN_FILTER = 0  # If non-zero, apply a median filter of size
# MF_THRESHOLD = 0  # If MEDIAN_FILTER is non-zero, only use the filtered
# DEBLEND_MINCONT = 0.005  # Min. fraction of island flux in deblended subisland
# STRUCTURING_ELEMENT = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]  # Island connectiivty
#         RMS_FILTER = 0.001
# class ImageData(object):
#     def __init__(self, data, beam, wcs, margin=0, radius=0, back_size_x=32,
#                  back_size_y=32, residuals=True
#                  ):
#     def _grids(self):
#     def _backmap(self):
#     def _set_backmap(self, bgmap):
#     def _get_rm(self):
#     def _set_rm(self, noisemap):
#     def _get_data(self):
#     def _get_data_bgsubbed(self):
#     def xdim(self):
#     def ydim(self):
#     def pixmax(self):
#     def pixmin(self):
#     def clearcache(self):
#     def __grids(self):
#     def _interpolate(self, grid, roundup=False):
#     def extract(self, det, anl, noisemap=None, bgmap=None, labelled_data=None,
#                 labels=None, deblend_nthresh=0, force_beam=False):
#     def reverse_se(self, det):
#     def fd_extract(self, alpha, anl=None, noisemap=None,
#                    bgmap=None, deblend_nthresh=0, force_beam=False
#                    ):
#     def flux_at_pixel(self, x, y, numpix=1):
#     def box_slice_about_pixel(x, y, box_radius):
#     def fit_to_point(self, x, y, boxsize, threshold, fixed):
#     def fit_fixed_positions(self, positions, boxsize, threshold=None,
#                             fixed='position+shape',
#                             ids=None):
#     def label_islands(self, detectionthresholdmap, analysisthresholdmap):
#     def _pyse(
#             self, detectionthresholdmap, analysisthresholdmap,
#             deblend_nthresh, force_beam, labelled_data=None, labels=[]
#     ):
#         def is_usable(det):
#             def check_point(x, y):


# Path: test/test_source_measurements.py
import os
import unittest
import numpy as np
import sourcefinder.accessors
from sourcefinder.testutil.data import DATAPATH
from sourcefinder.testutil.decorators import requires_data, duration
from sourcefinder import image

        # in particular, can be biased low if the background levels
        # are biased high.  The background and noise levels supplied
        # here are the true values.

        extraction_results = img.extract(
            det=10.0, anl=6.0,
            noisemap=np.ma.array(BG_STD * np.ones((2048, 2048))),
            bgmap=np.ma.array(BG_MEAN * np.ones((2048, 2048))))
        self.number_sources = len(extraction_results)

        peak_fluxes = []
        deconv_smajaxes = []
        deconv_sminaxes = []
        deconv_bpas = []

        for sources in extraction_results:
            peak_fluxes.append([sources.peak.value, sources.peak.error])
            deconv_smajaxes.append([sources.smaj_dc.value,
                                    sources.smaj_dc.error])
            deconv_sminaxes.append([sources.smin_dc.value,
                                    sources.smin_dc.error])
            deconv_bpas.append([sources.theta_dc.value,
                                sources.theta_dc.error])

        self.peak_fluxes = np.array(peak_fluxes)
        self.deconv_smajaxes = np.array(deconv_smajaxes)
        self.deconv_sminaxes = np.array(deconv_sminaxes)
        self.deconv_bpas = np.array(deconv_bpas)

    @duration(100)

    @requires_data(os.path.join(DATAPATH, 'deconvolved.fits'))