/usr/lib/python3/dist-packages/photutils/isophote/tests/test_isophote.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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | # 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 pytest
from astropy.io import fits
from astropy.tests.helper import remote_data
from .make_test_data import make_test_image
from ..fitter import EllipseFitter
from ..isophote import Isophote, IsophoteList
from ..sample import EllipseSample
from ...datasets import get_path
try:
import scipy # noqa
HAS_SCIPY = True
except ImportError:
HAS_SCIPY = False
@remote_data
@pytest.mark.skipif('not HAS_SCIPY')
class TestIsophote(object):
def setup_class(self):
path = get_path('isophote/M51.fits', location='photutils-datasets',
cache=True)
hdu = fits.open(path)
self.data = hdu[0].data
hdu.close()
def test_fit(self):
# low noise image, fitted perfectly by sample
data = make_test_image(noise=1.e-10, random_state=123)
sample = EllipseSample(data, 40)
fitter = EllipseFitter(sample)
iso = fitter.fit(maxit=400)
assert iso.valid
assert iso.stop_code == 0 or iso.stop_code == 2
# fitted values
assert iso.intens <= 201.
assert iso.intens >= 199.
assert iso.int_err <= 0.0010
assert iso.int_err >= 0.0009
assert iso.pix_stddev <= 0.03
assert iso.pix_stddev >= 0.02
assert abs(iso.grad) <= 4.25
assert abs(iso.grad) >= 4.20
# integrals
assert iso.tflux_e <= 1.85E6
assert iso.tflux_e >= 1.82E6
assert iso.tflux_c <= 2.025E6
assert iso.tflux_c >= 2.022E6
# deviations from perfect ellipticity
assert abs(iso.a3) <= 0.01
assert abs(iso.b3) <= 0.01
assert abs(iso.a4) <= 0.01
assert abs(iso.b4) <= 0.01
def test_m51(self):
sample = EllipseSample(self.data, 21.44)
fitter = EllipseFitter(sample)
iso = fitter.fit()
assert iso.valid
assert iso.stop_code == 0 or iso.stop_code == 2
# geometry
g = iso.sample.geometry
assert g.x0 >= (257 - 1.5) # position within 1.5 pixel
assert g.x0 <= (257 + 1.5)
assert g.y0 >= (259 - 1.5)
assert g.y0 <= (259 + 2.0)
assert g.eps >= (0.19 - 0.05) # eps within 0.05
assert g.eps <= (0.19 + 0.05)
assert g.pa >= (0.62 - 0.05) # pa within 5 deg
assert g.pa <= (0.62 + 0.05)
# fitted values
assert iso.intens == pytest.approx(682.9, abs=0.1)
assert iso.rms == pytest.approx(83.27, abs=0.01)
assert iso.int_err == pytest.approx(7.63, abs=0.01)
assert iso.pix_stddev == pytest.approx(117.8, abs=0.1)
assert iso.grad == pytest.approx(-36.08, abs=0.1)
# integrals
assert iso.tflux_e <= 1.20e6
assert iso.tflux_e >= 1.19e6
assert iso.tflux_c <= 1.38e6
assert iso.tflux_c >= 1.36e6
# deviations from perfect ellipticity
assert abs(iso.a3) <= 0.05
assert abs(iso.b3) <= 0.05
assert abs(iso.a4) <= 0.05
assert abs(iso.b4) <= 0.05
def test_m51_niter(self):
# compares with old STSDAS task. In this task, the
# default for the starting value of SMA is 10; it
# fits with 20 iterations.
sample = EllipseSample(self.data, 10)
fitter = EllipseFitter(sample)
iso = fitter.fit()
assert iso.valid
assert iso.niter == 50
class TestIsophoteList(object):
def setup_class(self):
data = make_test_image(random_state=123)
self.slen = 5
self.isolist_sma10 = self.build_list(data, sma0=10., slen=self.slen)
self.isolist_sma100 = self.build_list(data, sma0=100., slen=self.slen)
self.isolist_sma200 = self.build_list(data, sma0=200., slen=self.slen)
@staticmethod
def build_list(data, sma0, slen=5):
iso_list = []
for k in range(slen):
sample = EllipseSample(data, float(k + sma0))
sample.update()
iso_list.append(Isophote(sample, k, True, 0))
result = IsophoteList(iso_list)
return result
def test_basic_list(self):
# make sure it can be indexed as a list.
result = self.isolist_sma10[:]
assert isinstance(result[0], Isophote)
# make sure the important arrays contain floats.
# especially the sma array, which is derived
# from a property in the Isophote class.
assert isinstance(result.sma, np.ndarray)
assert isinstance(result.sma[0], float)
assert isinstance(result.intens, np.ndarray)
assert isinstance(result.intens[0], float)
assert isinstance(result.rms, np.ndarray)
assert isinstance(result.int_err, np.ndarray)
assert isinstance(result.pix_stddev, np.ndarray)
assert isinstance(result.grad, np.ndarray)
assert isinstance(result.grad_error, np.ndarray)
assert isinstance(result.grad_r_error, np.ndarray)
assert isinstance(result.sarea, np.ndarray)
assert isinstance(result.niter, np.ndarray)
assert isinstance(result.ndata, np.ndarray)
assert isinstance(result.nflag, np.ndarray)
assert isinstance(result.valid, np.ndarray)
assert isinstance(result.stop_code, np.ndarray)
assert isinstance(result.tflux_c, np.ndarray)
assert isinstance(result.tflux_e, np.ndarray)
assert isinstance(result.npix_c, np.ndarray)
assert isinstance(result.npix_e, np.ndarray)
assert isinstance(result.a3, np.ndarray)
assert isinstance(result.a4, np.ndarray)
assert isinstance(result.b3, np.ndarray)
assert isinstance(result.b4, np.ndarray)
samples = result.sample
assert isinstance(samples, list)
assert isinstance(samples[0], EllipseSample)
iso = result.get_closest(13.6)
assert isinstance(iso, Isophote)
assert iso.sma == pytest.approx(14., abs=0.000001)
def test_extend(self):
# the extend method shouldn't return anything,
# and should modify the first list in place.
inner_list = self.isolist_sma10[:]
outer_list = self.isolist_sma100[:]
assert len(inner_list) == self.slen
assert len(outer_list) == self.slen
dummy = inner_list.extend(outer_list)
assert not dummy
assert len(inner_list) == 2 * self.slen
# the __iadd__ operator should behave like the
# extend method.
inner_list = self.isolist_sma10[:]
outer_list = self.isolist_sma100[:]
inner_list += outer_list
assert len(inner_list) == 2 * self.slen
# the __add__ operator should create a new IsophoteList
# instance with the result, and should not modify
# the operands.
inner_list = self.isolist_sma10[:]
outer_list = self.isolist_sma100[:]
result = inner_list + outer_list
assert isinstance(result, IsophoteList)
assert len(inner_list) == self.slen
assert len(outer_list) == self.slen
assert len(result) == 2 * self.slen
def test_slicing(self):
iso_list = self.isolist_sma10[:]
assert len(iso_list) == self.slen
assert len(iso_list[1:-1]) == self.slen - 2
assert len(iso_list[2:-2]) == self.slen - 4
def test_combined(self):
# combine extend with slicing.
inner_list = self.isolist_sma10[:]
outer_list = self.isolist_sma100[:]
sublist = inner_list[2:-2]
dummy = sublist.extend(outer_list)
assert not dummy
assert len(sublist) == 2*self.slen - 4
# try one more slice.
even_outer_list = self.isolist_sma200
sublist.extend(even_outer_list[1:-1])
assert len(sublist) == 2*self.slen - 4 + 3
# combine __add__ with slicing.
sublist = inner_list[2:-2]
result = sublist + outer_list
assert isinstance(result, IsophoteList)
assert len(sublist) == self.slen - 4
assert len(result) == 2*self.slen - 4
result = inner_list[2:-2] + outer_list
assert isinstance(result, IsophoteList)
assert len(result) == 2*self.slen - 4
def test_sort(self):
inner_list = self.isolist_sma10[:]
outer_list = self.isolist_sma100[:]
result = outer_list[2:-2] + inner_list
assert result[-1].sma < result[0].sma
result.sort()
assert result[-1].sma > result[0].sma
|