This file is indexed.

/usr/lib/python2.7/dist-packages/photutils/datasets/tests/test_make.py is in python-photutils 0.2.1-2.

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
# 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, assert_quantity_allclose
from astropy.table import Table
import astropy.units as u
from .. import (make_noise_image, make_poisson_noise, make_gaussian_sources,
                make_random_gaussians, make_4gaussians_image,
                make_100gaussians_image)


TABLE = Table()
TABLE['flux'] = [1, 2, 3]
TABLE['x_mean'] = [30, 50, 70.5]
TABLE['y_mean'] = [50, 50, 50.5]
TABLE['x_stddev'] = [1, 2, 3.5]
TABLE['y_stddev'] = [2, 1, 3.5]
TABLE['theta'] = np.array([0., 30, 50]) * np.pi / 180.


def test_make_noise_image():
    shape = (100, 100)
    image = make_noise_image(shape, 'gaussian', mean=0., stddev=2.)
    assert image.shape == shape
    assert_allclose(image.mean(), 0., atol=1.)


def test_make_noise_image_poisson():
    shape = (100, 100)
    image = make_noise_image(shape, 'poisson', mean=1.)
    assert image.shape == shape
    assert_allclose(image.mean(), 1., atol=1.)


def test_make_noise_image_nomean():
    """
    Test if ValueError raises if mean is not input.
    """
    with pytest.raises(ValueError):
        shape = (100, 100)
        make_noise_image(shape, 'gaussian', stddev=2.)


def test_make_noise_image_nostddev():
    """
    Test if ValueError raises if stddev is not input for Gaussian noise.
    """
    with pytest.raises(ValueError):
        shape = (100, 100)
        make_noise_image(shape, 'gaussian', mean=2.)


def test_make_noise_image_unit():
    shape = (100, 100)
    unit = u.electron / u.s
    image = make_noise_image(shape, 'gaussian', mean=0., stddev=2., unit=unit)
    assert image.shape == shape
    assert image.unit == unit
    assert_quantity_allclose(image.mean(), 0.*unit, atol=1.*unit)


def test_make_poisson_noise():
    shape = (100, 100)
    data = np.ones(shape)
    result = make_poisson_noise(data)
    assert result.shape == shape
    assert_allclose(result.mean(), 1., atol=1.)


def test_make_poisson_noise_negative():
    """Test if negative image values raises ValueError."""
    with pytest.raises(ValueError):
        shape = (100, 100)
        data = np.zeros(shape) - 1.
        make_poisson_noise(data)


def test_make_poisson_noise_unit():
    shape = (100, 100)
    unit = u.electron / u.s
    data = np.ones(shape) * unit
    result = make_poisson_noise(data)
    assert result.shape == shape
    assert result.unit == unit
    assert_quantity_allclose(result.mean(), 1.*unit, atol=1.*unit)


def test_make_gaussian_sources():
    shape = (100, 100)
    image = make_gaussian_sources(shape, TABLE)
    assert image.shape == shape
    assert_allclose(image.sum(), TABLE['flux'].sum())


def test_make_gaussian_sources_amplitude():
    table = TABLE.copy()
    table.remove_column('flux')
    table['amplitude'] = [1, 2, 3]
    shape = (100, 100)
    image = make_gaussian_sources(shape, table)
    assert image.shape == shape


def test_make_gaussian_sources_oversample():
    shape = (100, 100)
    image = make_gaussian_sources(shape, TABLE, oversample=10)
    assert image.shape == shape
    assert_allclose(image.sum(), TABLE['flux'].sum())


def test_make_gaussian_sources_parameters():
    with pytest.raises(ValueError):
        table = TABLE.copy()
        table.remove_column('flux')
        shape = (100, 100)
        make_gaussian_sources(shape, table)


def test_make_gaussian_sources_unit():
    shape = (100, 100)
    unit = u.electron / u.s
    image = make_gaussian_sources(shape, TABLE, unit=unit)
    assert image.shape == shape
    assert image.unit == unit
    assert_quantity_allclose(image.sum(), TABLE['flux'].sum()*unit)


def test_make_random_gaussians():
    n_sources = 5
    bounds = [0, 1]
    table = make_random_gaussians(n_sources, bounds, bounds, bounds, bounds,
                                  bounds)
    assert len(table) == n_sources


def test_make_random_gaussians_amplitude():
    n_sources = 5
    bounds = [0, 1]
    table = make_random_gaussians(n_sources, bounds, bounds, bounds, bounds,
                                  bounds, amplitude_range=bounds)
    assert len(table) == n_sources


def test_make_4gaussians_image():
    shape = (100, 200)
    data_sum = 176219.18059091491
    image = make_4gaussians_image()
    assert image.shape == shape
    assert_allclose(image.sum(), data_sum, rtol=1.e-6)


def test_make_100gaussians_image():
    shape = (300, 500)
    data_sum = 826182.24501251709
    image = make_100gaussians_image()
    assert image.shape == shape
    assert_allclose(image.sum(), data_sum, rtol=1.e-6)