/usr/lib/python3/dist-packages/photutils/isophote/tests/test_integrator.py is in python3-photutils 0.4-1.
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | # 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
import numpy.ma as ma
import pytest
from astropy.io import fits
from astropy.tests.helper import remote_data
from ..sample import EllipseSample
from ..integrator import NEAREST_NEIGHBOR, BILINEAR, MEAN, MEDIAN
from ...datasets import get_path
@remote_data
class TestData(object):
def setup_class(self):
path = get_path('isophote/synth_highsnr.fits',
location='photutils-datasets', cache=True)
hdu = fits.open(path)
self.data = hdu[0].data
hdu.close()
def make_sample(self, masked=False, sma=40., integrmode=BILINEAR):
if masked:
data = ma.masked_values(self.data, 200., atol=10.0, rtol=0.)
else:
data = self.data
sample = EllipseSample(data, sma, integrmode=integrmode)
s = sample.extract()
assert len(s) == 3
assert len(s[0]) == len(s[1])
assert len(s[0]) == len(s[2])
return s, sample
@remote_data
class TestUnmasked(TestData):
def test_bilinear(self):
s, sample = self.make_sample()
assert len(s[0]) == 225
# intensities
assert np.mean(s[2]) == pytest.approx(200.76, abs=0.01)
assert np.std(s[2]) == pytest.approx(21.55, abs=0.01)
# radii
assert np.max(s[1]) == pytest.approx(40.0, abs=0.01)
assert np.min(s[1]) == pytest.approx(32.0, abs=0.01)
assert sample.total_points == 225
assert sample.actual_points == 225
def test_bilinear_small(self):
# small radius forces sub-pixel sampling
s, sample = self.make_sample(sma=10.)
# intensities
assert np.mean(s[2]) == pytest.approx(1045.4, abs=0.1)
assert np.std(s[2]) == pytest.approx(143.0, abs=0.1)
# radii
assert np.max(s[1]) == pytest.approx(10.0, abs=0.1)
assert np.min(s[1]) == pytest.approx(8.0, abs=0.1)
assert sample.total_points == 57
assert sample.actual_points == 57
def test_nearest_neighbor(self):
s, sample = self.make_sample(integrmode=NEAREST_NEIGHBOR)
assert len(s[0]) == 225
# intensities
assert np.mean(s[2]) == pytest.approx(201.1, abs=0.1)
assert np.std(s[2]) == pytest.approx(21.8, abs=0.1)
# radii
assert np.max(s[1]) == pytest.approx(40.0, abs=0.01)
assert np.min(s[1]) == pytest.approx(32.0, abs=0.01)
assert sample.total_points == 225
assert sample.actual_points == 225
def test_mean(self):
s, sample = self.make_sample(integrmode=MEAN)
assert len(s[0]) == 64
# intensities
assert np.mean(s[2]) == pytest.approx(199.9, abs=0.1)
assert np.std(s[2]) == pytest.approx(21.3, abs=0.1)
# radii
assert np.max(s[1]) == pytest.approx(40.0, abs=0.01)
assert np.min(s[1]) == pytest.approx(32.0, abs=0.01)
assert sample.sector_area == pytest.approx(12.4, abs=0.1)
assert sample.total_points == 64
assert sample.actual_points == 64
def test_mean_small(self):
s, sample = self.make_sample(sma=5., integrmode=MEAN)
assert len(s[0]) == 29
# intensities
assert np.mean(s[2]) == pytest.approx(2339.0, abs=0.1)
assert np.std(s[2]) == pytest.approx(284.7, abs=0.1)
# radii
assert np.max(s[1]) == pytest.approx(5.0, abs=0.01)
assert np.min(s[1]) == pytest.approx(4.0, abs=0.01)
assert sample.sector_area == pytest.approx(2.0, abs=0.1)
assert sample.total_points == 29
assert sample.actual_points == 29
def test_median(self):
s, sample = self.make_sample(integrmode=MEDIAN)
assert len(s[0]) == 64
# intensities
assert np.mean(s[2]) == pytest.approx(199.9, abs=0.1)
assert np.std(s[2]) == pytest.approx(21.3, abs=0.1)
# radii
assert np.max(s[1]) == pytest.approx(40.0, abs=0.01)
assert np.min(s[1]) == pytest.approx(32.01, abs=0.01)
assert sample.sector_area == pytest.approx(12.4, abs=0.1)
assert sample.total_points == 64
assert sample.actual_points == 64
@remote_data
class TestMasked(TestData):
def test_bilinear(self):
s, sample = self.make_sample(masked=True, integrmode=BILINEAR)
assert len(s[0]) == 157
# intensities
assert np.mean(s[2]) == pytest.approx(201.52, abs=0.01)
assert np.std(s[2]) == pytest.approx(25.21, abs=0.01)
# radii
assert np.max(s[1]) == pytest.approx(40.0, abs=0.01)
assert np.min(s[1]) == pytest.approx(32.0, abs=0.01)
assert sample.total_points == 225
assert sample.actual_points == 157
def test_mean(self):
s, sample = self.make_sample(masked=True, integrmode=MEAN)
assert len(s[0]) == 51
# intensities
assert np.mean(s[2]) == pytest.approx(199.9, abs=0.1)
assert np.std(s[2]) == pytest.approx(24.12, abs=0.1)
# radii
assert np.max(s[1]) == pytest.approx(40.0, abs=0.01)
assert np.min(s[1]) == pytest.approx(32.0, abs=0.01)
assert sample.sector_area == pytest.approx(12.4, abs=0.1)
assert sample.total_points == 64
assert sample.actual_points == 51
|