Skip to content

Commit 408dff9

Browse files
authored
Merge pull request #178 from transientskp/Fix_172
Fix 172
2 parents 3d59af1 + a352fda commit 408dff9

17 files changed

Lines changed: 233 additions & 142 deletions

sourcefinder/extract.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919
from sourcefinder.utility import coordinates
2020
from sourcefinder.utility.uncertain import Uncertain
21-
from . import measuring
21+
from . import measure
2222
from . import utils
2323
from .config import Conf, ImgConf
2424
from .gaussian import gaussian
@@ -812,18 +812,11 @@ def _error_bars_from_moments(self, noise, correlation_lengths, threshold):
812812
if errortheta > np.pi / 2.0:
813813
errortheta = np.pi / 2.0
814814

815-
# The peak from "moments" is just the value of the maximum pixel
816-
# times a correction, fudge_max_pix, for the fact that the
817-
# centre of the Gaussian is not at the centre of the pixel.
818-
# This correction is performed in measuring.py. The maximum pixel
819-
# method introduces a peak dependent error corresponding to the last
820-
# term in the expression below for errorpeaksq.
821-
# To this, we add, in quadrature, the errors corresponding
822-
# to the first and last term of the rhs of equation 37 of the
823-
# NVSS paper. The middle term in that equation 37 is heuristically
824-
# replaced by noise**2 since the threshold should not affect
825-
# the error from the (corrected) maximum pixel method,
826-
# while it is part of the expression for rho_sq above.
815+
# Basically, this is equation 37 of the NVSS paper, with the middle
816+
# term of the rhs of that equation heuristically replaced by
817+
# noise**2 since the threshold is not expected to affect the error
818+
# on peak brightnesses from tweaked moments, while it is part of the
819+
# expression for rho_sq above.
827820
errorpeaksq = (
828821
(frac_flux_cal_error * peak) ** 2 + clean_bias_error**2 + noise**2
829822
)
@@ -1105,7 +1098,7 @@ def source_profile_and_errors(
11051098
# Moments can only be computed if no parameters are fixed.
11061099
try:
11071100
param.update(
1108-
measuring.moments(
1101+
measure.moments(
11091102
data,
11101103
fudge_max_pix_factor,
11111104
beam,
@@ -1122,7 +1115,7 @@ def source_profile_and_errors(
11221115
except ValueError:
11231116
logger.warning("Moments computations failed, use defaults.")
11241117
try:
1125-
gaussian_soln = measuring.fitgaussian(
1118+
gaussian_soln = measure.fitgaussian(
11261119
data, param, fixed=fixed, bounds=param.bounds
11271120
)
11281121
param.update(gaussian_soln)
@@ -1173,7 +1166,7 @@ def source_profile_and_errors(
11731166
gauss_island_filled = gauss_island_masked
11741167
gauss_resid_filled = gauss_resid_masked
11751168

1176-
param.chisq, param.reduced_chisq = measuring.goodness_of_fit(
1169+
param.chisq, param.reduced_chisq = measure.goodness_of_fit(
11771170
gauss_resid_masked, rms, correlation_lengths
11781171
)
11791172

@@ -2307,7 +2300,7 @@ def source_measurements_vectorised(
23072300
# array. In this way Numba can infer the shape of the output array.
23082301
with np.errstate(invalid="ignore"):
23092302
# Context manager added to fix issue #165.
2310-
measuring.moments_enhanced(
2303+
measure.moments_enhanced(
23112304
sources,
23122305
noises,
23132306
chunk_positions,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,10 @@ def moments_enhanced(
757757
errortheta = np.pi / 2.0
758758

759759
# This should reflect the equivalent of equation 37 of the NVSS paper for
760-
# moments calculations. The middle term in that equation 37 is heuristically
761-
# replaced by noise**2 since the threshold should not affect the error from
762-
# the (corrected) maximum pixel method, while it is part of the expression
763-
# for rho_sq above.
760+
# moments calculations. The middle term of the rhs of that equation is
761+
# heuristically replaced by noise**2 since the threshold is not expected to
762+
# affect the error on peak brightnesses from tweaked moments, while it
763+
# is part of the expression for rho_sq above.
764764
errorpeaksq = (
765765
(frac_flux_cal_error * peak) ** 2 + clean_bias_error**2 + noise**2
766766
)

test/test_FDR.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@
4040

4141
from sourcefinder import accessors
4242
from sourcefinder.config import Conf, ImgConf
43-
from .conftest import DATAPATH
43+
from test.conftest import DATAPATH
4444
from sourcefinder.testutil.decorators import requires_data, duration
4545

4646
from sourcefinder import image
4747

4848
NUMBER_INSERTED = float(3969)
4949

50-
uncorr_path = os.path.join(DATAPATH, 'uncorrelated_noise.fits')
51-
corr_path = os.path.join(DATAPATH, 'correlated_noise.fits')
52-
deconv_path = os.path.join(DATAPATH, 'deconvolved.fits')
50+
uncorr_path = os.path.join(DATAPATH, "uncorrelated_noise.fits")
51+
corr_path = os.path.join(DATAPATH, "correlated_noise.fits")
52+
deconv_path = os.path.join(DATAPATH, "deconvolved.fits")
5353

5454

5555
@requires_data(uncorr_path)
@@ -108,22 +108,29 @@ def test_normal(self):
108108

109109
def test_alpha0_1(self):
110110
self.number_alpha_10pc = len(
111-
self.image_with_sources.fd_extract(alpha=0.1))
112-
self.assertTrue((self.number_alpha_10pc - NUMBER_INSERTED) /
113-
NUMBER_INSERTED < 0.1)
111+
self.image_with_sources.fd_extract(alpha=0.1)
112+
)
113+
self.assertTrue(
114+
(self.number_alpha_10pc - NUMBER_INSERTED) / NUMBER_INSERTED < 0.1
115+
)
114116

115117
def test_alpha0_01(self):
116118
self.number_alpha_1pc = len(
117-
self.image_with_sources.fd_extract(alpha=0.01))
118-
self.assertTrue((self.number_alpha_1pc - NUMBER_INSERTED) /
119-
NUMBER_INSERTED < 0.01)
119+
self.image_with_sources.fd_extract(alpha=0.01)
120+
)
121+
self.assertTrue(
122+
(self.number_alpha_1pc - NUMBER_INSERTED) / NUMBER_INSERTED < 0.01
123+
)
120124

121125
def test_alpha0_001(self):
122126
self.number_alpha_point1pc = len(
123-
self.image_with_sources.fd_extract(alpha=0.001))
124-
self.assertTrue((self.number_alpha_point1pc - NUMBER_INSERTED) /
125-
NUMBER_INSERTED < 0.001)
127+
self.image_with_sources.fd_extract(alpha=0.001)
128+
)
129+
self.assertTrue(
130+
(self.number_alpha_point1pc - NUMBER_INSERTED) / NUMBER_INSERTED
131+
< 0.001
132+
)
126133

127134

128-
if __name__ == '__main__':
135+
if __name__ == "__main__":
129136
unittest.main()

test/test_L15_12h_const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import unittest
66

7-
from .conftest import DATAPATH
7+
from test.conftest import DATAPATH
88
from sourcefinder.testutil.decorators import requires_data
99

1010
import sourcefinder.accessors.fitsimage

test/test_aartfaaccasatable.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from sourcefinder.accessors.aartfaaccasaimage import AartfaacCasaImage
77
from sourcefinder.testutil.decorators import requires_data
88
from sourcefinder.utility.coordinates import angsep
9-
from .conftest import DATAPATH
9+
from test.conftest import DATAPATH
1010

1111

12-
casatable = os.path.join(DATAPATH, 'accessors/aartfaac.table')
12+
casatable = os.path.join(DATAPATH, "accessors/aartfaac.table")
1313

1414

1515
class TestAartfaacCasaImage(unittest.TestCase):
@@ -51,11 +51,14 @@ def test_pix_scale(self):
5151
p2_pix = (p1_pix[0], p1_pix[1] + pixel_sep)
5252
p2_sky = self.accessor.wcs.p2s(p2_pix)
5353

54-
coord_dist_deg = angsep(p1_sky[0], p1_sky[1], p2_sky[0], p2_sky[1]) / 3600.0
54+
coord_dist_deg = (
55+
angsep(p1_sky[0], p1_sky[1], p2_sky[0], p2_sky[1]) / 3600.0
56+
)
5557
pix_dist_deg = pixel_sep * self.accessor.pixelsize[1]
5658

5759
# 6 decimal places => 1e-6*degree / 10pix => 1e-7*degree / 1pix
5860
# => Approx 0.15 arcseconds drift across 512 pixels
5961
# (Probably OK).
60-
self.assertAlmostEqual(abs(coord_dist_deg), abs(pix_dist_deg), places=3)
61-
62+
self.assertAlmostEqual(
63+
abs(coord_dist_deg), abs(pix_dist_deg), places=3
64+
)

test/test_accessors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
from sourcefinder import accessors
66

7-
from .conftest import DATAPATH
7+
from test.conftest import DATAPATH
88

99
lofar_casatable = os.path.join(
1010
DATAPATH,
11-
("casatable/L55596_000TO009_skymodellsc_wmax6000_noise_mult10_cell40_" +
12-
"npix512_wplanes215.img.restored.corr"),
11+
(
12+
"casatable/L55596_000TO009_skymodellsc_wmax6000_noise_mult10_cell40_"
13+
+ "npix512_wplanes215.img.restored.corr"
14+
),
1315
)
1416

1517

test/test_amicasatable.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from sourcefinder.accessors.amicasaimage import AmiCasaImage
77
from sourcefinder.testutil.decorators import requires_data
88
from sourcefinder.utility.coordinates import angsep
9-
from .conftest import DATAPATH
9+
from test.conftest import DATAPATH
1010

1111

12-
casatable = os.path.join(DATAPATH, 'accessors/ami-la.image')
12+
casatable = os.path.join(DATAPATH, "accessors/ami-la.image")
1313

1414

1515
class TestAmiLaCasaImage(unittest.TestCase):
@@ -22,9 +22,11 @@ def test_casaimage(self):
2222
results = self.accessor.extract_metadata()
2323
sfimage = accessors.sourcefinder_image_from_accessor(self.accessor)
2424

25-
known_bmaj, known_bmin, known_bpa = (4.002118682861328,
26-
2.4657058715820312,
27-
0.3598241556754317)
25+
known_bmaj, known_bmin, known_bpa = (
26+
4.002118682861328,
27+
2.4657058715820312,
28+
0.3598241556754317,
29+
)
2830

2931
bmaj, bmin, bpa = self.accessor.beam
3032
self.assertAlmostEqual(known_bmaj, bmaj, 2)
@@ -50,15 +52,18 @@ def test_pix_scale(self):
5052
p1_sky = (self.accessor.centre_ra, self.accessor.centre_decl)
5153
p1_pix = self.accessor.wcs.s2p(p1_sky)
5254

53-
pixel_sep = 10 #Along a single axis
55+
pixel_sep = 10 # Along a single axis
5456
p2_pix = (p1_pix[0], p1_pix[1] + pixel_sep)
5557
p2_sky = self.accessor.wcs.p2s(p2_pix)
5658

57-
coord_dist_deg = angsep(p1_sky[0], p1_sky[1], p2_sky[0], p2_sky[1]) / 3600.0
59+
coord_dist_deg = (
60+
angsep(p1_sky[0], p1_sky[1], p2_sky[0], p2_sky[1]) / 3600.0
61+
)
5862
pix_dist_deg = pixel_sep * self.accessor.pixelsize[1]
5963

60-
#6 decimal places => 1e-6*degree / 10pix => 1e-7*degree / 1pix
64+
# 6 decimal places => 1e-6*degree / 10pix => 1e-7*degree / 1pix
6165
# => Approx 0.15 arcseconds drift across 512 pixels
6266
# (Probably OK).
63-
self.assertAlmostEqual(abs(coord_dist_deg), abs(pix_dist_deg), places=6)
64-
67+
self.assertAlmostEqual(
68+
abs(coord_dist_deg), abs(pix_dist_deg), places=6
69+
)

test/test_casatable.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import unittest
44

5-
import pytest
65
import sourcefinder.accessors as accessors
76
from sourcefinder.testutil.decorators import requires_data
8-
from .conftest import DATAPATH
7+
from test.conftest import DATAPATH
98

10-
casatable = os.path.join(DATAPATH, 'accessors/casa.table')
9+
casatable = os.path.join(DATAPATH, "accessors/casa.table")
1110

1211

1312
@requires_data(casatable)

test/test_config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
from sourcefinder.config import validate_nested
1111
from sourcefinder.config import validate_types
1212

13-
from .conftest import DATAPATH
13+
from test.conftest import DATAPATH
1414

1515
_image = {"rms_filter": 0.1, "structuring_element": [[2] * 3] * 3}
1616
_export = {"file_type": "hdf5", "source_params": ["foo", "bar"]}
1717

18+
1819
@pytest.mark.parametrize(
1920
"conf_t, conf",
2021
[
@@ -72,7 +73,12 @@ def test_assert_t_err(key, val, types):
7273
("listany", ["a", 1, True], list, ()),
7374
("liststr", list("abc"), list, (str,)),
7475
("dictionary", {"a": 1, "b": 2}, dict, (str, int)),
75-
("dictionarymixed", {"a": 3.14, "b": 2}, dict, (str, float)), # compatible
76+
(
77+
"dictionarymixed",
78+
{"a": 3.14, "b": 2},
79+
dict,
80+
(str, float),
81+
), # compatible
7682
],
7783
)
7884
def test_nested(key, value, origin_t, args):
@@ -108,7 +114,11 @@ def test_nested_warn(key, value, origin_t, args):
108114
("listany", ["a", 1, True], list),
109115
("liststr", list("abc"), list[str,]),
110116
("dictionary", {"a": 1, "b": 2}, dict[str, int]),
111-
("dictionarymixed", {"a": 3.14, "b": 2}, dict[str, float]), # compatible
117+
(
118+
"dictionarymixed",
119+
{"a": 3.14, "b": 2},
120+
dict[str, float],
121+
), # compatible
112122
("union", 42, (NoneType | int)), # uniontype
113123
],
114124
)

test/test_detection.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22

33
import unittest
44

5-
import pytest
65
import sourcefinder.accessors as accessors
7-
from sourcefinder.accessors.detection import isfits, islofarhdf5, detect, iscasa
6+
from sourcefinder.accessors.detection import (
7+
isfits,
8+
islofarhdf5,
9+
detect,
10+
iscasa,
11+
)
812
from sourcefinder.accessors.lofarcasaimage import LofarCasaImage
9-
from sourcefinder.accessors.casaimage import CasaImage
1013
from sourcefinder.accessors.fitsimage import FitsImage
1114
from sourcefinder.accessors.amicasaimage import AmiCasaImage
1215
from sourcefinder.testutil.decorators import requires_data
13-
from .conftest import DATAPATH
16+
from test.conftest import DATAPATH
1417

1518

16-
lofarcasatable = os.path.join(DATAPATH, "casatable/L55596_000TO009_skymodellsc_wmax6000_noise_mult10_cell40_npix512_wplanes215.img.restored.corr")
17-
casatable = os.path.join(DATAPATH, 'accessors/casa.table')
18-
fitsfile = os.path.join(DATAPATH, 'accessors/lofar.fits')
19-
hdf5file = os.path.join(DATAPATH, 'accessors/lofar.h5')
20-
antennafile = os.path.join(DATAPATH, 'lofar/CS001-AntennaArrays.conf')
21-
amicasatable = os.path.join(DATAPATH, 'accessors/ami-la.image')
19+
lofarcasatable = os.path.join(
20+
DATAPATH,
21+
"casatable/L55596_000TO009_skymodellsc_wmax6000_noise_mult10_cell40_npix512_wplanes215.img.restored.corr",
22+
)
23+
casatable = os.path.join(DATAPATH, "accessors/casa.table")
24+
fitsfile = os.path.join(DATAPATH, "accessors/lofar.fits")
25+
hdf5file = os.path.join(DATAPATH, "accessors/lofar.h5")
26+
antennafile = os.path.join(DATAPATH, "lofar/CS001-AntennaArrays.conf")
27+
amicasatable = os.path.join(DATAPATH, "accessors/ami-la.image")
2228

2329

2430
class TestAutodetect(unittest.TestCase):
@@ -55,7 +61,7 @@ def test_open(self):
5561
accessor = accessors.open(lofarcasatable)
5662
self.assertEqual(accessor.__class__, LofarCasaImage)
5763
self.assertRaises(OSError, accessors.open, antennafile)
58-
self.assertRaises(OSError, accessors.open, 'doesntexists')
64+
self.assertRaises(OSError, accessors.open, "doesntexists")
5965

6066
@requires_data(amicasatable)
6167
def test_isamicasa(self):

0 commit comments

Comments
 (0)