/usr/lib/python3/dist-packages/photutils/background/tests/test_core.py is in python3-photutils 0.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | # Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import numpy as np
from numpy.testing import assert_allclose
from astropy.tests.helper import pytest
from ...datasets.make import make_noise_image
from ..core import (SigmaClip, MeanBackground, MedianBackground,
ModeEstimatorBackground, MMMBackground,
SExtractorBackground, BiweightLocationBackground,
StdBackgroundRMS, MADStdBackgroundRMS,
BiweightMidvarianceBackgroundRMS)
BKG = 0.0
STD = 0.5
DATA = make_noise_image((100, 100), type='gaussian', mean=BKG, stddev=STD,
random_state=12345)
BKG_CLASS0 = [MeanBackground, MedianBackground, ModeEstimatorBackground,
MMMBackground, SExtractorBackground]
# BiweightLocationBackground cannot handle a constant background
# (astropy.stats.biweight_location needs to be fixed)
BKG_CLASS = BKG_CLASS0 + [BiweightLocationBackground]
RMS_CLASS = [StdBackgroundRMS, MADStdBackgroundRMS,
BiweightMidvarianceBackgroundRMS]
SIGMA_CLIP = SigmaClip(sigma=3.)
@pytest.mark.parametrize('bkg_class', BKG_CLASS0)
def test_constant_background(bkg_class):
data = np.ones((100, 100))
bkg = bkg_class(sigma_clip=SIGMA_CLIP)
bkgval = bkg.calc_background(data)
assert not np.ma.isMaskedArray(bkgval)
assert_allclose(bkgval, 1.0)
assert_allclose(bkg(data), bkg.calc_background(data))
@pytest.mark.parametrize('bkg_class', BKG_CLASS)
def test_background(bkg_class):
bkg = bkg_class(sigma_clip=SIGMA_CLIP)
bkgval = bkg.calc_background(DATA)
assert not np.ma.isMaskedArray(bkgval)
assert_allclose(bkgval, BKG, atol=1.e-2)
assert_allclose(bkg(DATA), bkg.calc_background(DATA))
@pytest.mark.parametrize('bkg_class', BKG_CLASS)
def test_background_axis(bkg_class):
bkg = bkg_class(sigma_clip=SIGMA_CLIP)
bkg_arr = bkg.calc_background(DATA, axis=0)
bkgi = []
for i in range(100):
bkgi.append(bkg.calc_background(DATA[:, i]))
bkgi = np.array(bkgi)
assert_allclose(bkg_arr, bkgi)
bkg_arr = bkg.calc_background(DATA, axis=1)
bkgi = []
for i in range(100):
bkgi.append(bkg.calc_background(DATA[i, :]))
bkgi = np.array(bkgi)
assert_allclose(bkg_arr, bkgi)
def test_sextrator_background_zero_std():
data = np.ones((100, 100))
bkg = SExtractorBackground(sigma_clip=None)
assert_allclose(bkg.calc_background(data), 1.0)
def test_sextrator_background_skew():
data = np.arange(100)
data[70:] = 1.e7
bkg = SExtractorBackground(sigma_clip=None)
assert_allclose(bkg.calc_background(data), np.median(data))
@pytest.mark.parametrize('rms_class', RMS_CLASS)
def test_background_rms(rms_class):
bkgrms = rms_class(sigma_clip=SIGMA_CLIP)
assert_allclose(bkgrms.calc_background_rms(DATA), STD, atol=1.e-2)
assert_allclose(bkgrms(DATA), bkgrms.calc_background_rms(DATA))
|