2
2
3
3
import attr
4
4
import numpy as np
5
+ import pytest
5
6
import scipy .ndimage
6
7
from pytest import approx
7
8
15
16
)
16
17
from fastimgproto .sourcefind .fit import Gaussian2dParams
17
18
from fastimgproto .sourcefind .image import (
19
+ Island ,
20
+ IslandParams ,
21
+ Pixel ,
22
+ PixelIndex ,
18
23
SourceFindImage ,
19
24
estimate_rms ,
20
25
extremum_pixel_index ,
@@ -41,6 +46,26 @@ def test_rms_estimation():
41
46
assert np .abs ((rms_est - rms ) / rms ) < 0.05
42
47
43
48
49
+ def test_island_constructor_validation ():
50
+ img = np .zeros ((ydim , xdim ), dtype = np .float_ )
51
+ bright_pixel = Pixel (index = PixelIndex (y = int (ydim / 2 ), x = int (xdim / 2 )),
52
+ value = 1.0 )
53
+ island_params = IslandParams (sign = 1 ,
54
+ extremum = bright_pixel )
55
+
56
+ bad_mask = np .ones ((2 ,2 ), dtype = bool )
57
+ with pytest .raises (ValueError ):
58
+ island = Island (parent_data = img ,
59
+ mask = bad_mask ,
60
+ params = island_params )
61
+
62
+ mask = np .ones_like (img , dtype = bool )
63
+ mask [attr .astuple (bright_pixel .index )] = False
64
+ island = Island (parent_data = img ,
65
+ mask = mask ,
66
+ params = island_params )
67
+
68
+
44
69
def test_basic_source_detection ():
45
70
"""
46
71
We use a flat background (rather than noisy) to avoid random-noise fluctuations
@@ -50,7 +75,7 @@ def test_basic_source_detection():
50
75
start adding secondary sources and check we get multiple finds as
51
76
expected...
52
77
"""
53
- img = np .zeros ((ydim , xdim ))
78
+ img = np .zeros ((ydim , xdim ), dtype = np . float_ )
54
79
add_gaussian2d_to_image (bright_src , img )
55
80
56
81
sf = SourceFindImage (img , detection_n_sigma = 4 ,
@@ -127,7 +152,6 @@ def test_negative_source_detection():
127
152
neg_island = negative_islands [0 ]
128
153
pos_island = positive_islands [0 ]
129
154
130
-
131
155
min_pixel_index = extremum_pixel_index (img , - 1 )
132
156
assert attr .astuple (neg_island .extremum .index ) == min_pixel_index
133
157
@@ -137,7 +161,7 @@ def test_negative_source_detection():
137
161
# Sanity check that the island masks look sensible
138
162
# Check that the mask==False regions are disjoint - taking the boolean OR
139
163
# on both masks should result in a fully `True` mask-array.
140
- assert (np .logical_or (neg_island .data .mask ,pos_island .data .mask ).all ())
164
+ assert (np .logical_or (neg_island .data .mask , pos_island .data .mask ).all ())
141
165
142
166
# And that the true/false regions look sensible for the extremum pixels:
143
167
assert neg_island .data .mask [min_pixel_index ] == False
0 commit comments