Skip to content

Commit cb5d926

Browse files
authored
Merge pull request #181 from transientskp/fixed_fixed_posns
Fix bug that arose when users would supply --fixed-posns in the cli
2 parents f48b50a + 2ef2caf commit cb5d926

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

sourcefinder/utility/cli.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ def construct_argument_parser():
160160
"--structuring-element",
161161
type=ast.literal_eval,
162162
help="""
163-
Structuring element for morphological operations, provided as a
164-
Python-style nested list, e.g. '[[1,1,1], [1,1,1], [1,1,1]]' for
163+
Structuring element for morphological operations, provided as a
164+
Python-style nested list, e.g. '[[1,1,1], [1,1,1], [1,1,1]]' for
165165
8-connectivity and '[[0,1,0], [1,1,1], [0,1,0]]' for 4-connectivity.
166-
This is used for defining the connectivity in connected-component
166+
This is used for defining the connectivity in connected-component
167167
labelling.
168168
""",
169169
)
@@ -492,6 +492,11 @@ def excepthook(type, value, traceback):
492492
parser.error(
493493
"--detection-image not supported with fixed positions"
494494
)
495+
elif conf.export.residuals:
496+
parser.error("--residuals not supported with fixed positions")
497+
elif conf.export.islands:
498+
parser.error("--islands not supported with fixed positions")
499+
495500
mode = "fixed" # mode 2 above
496501
elif conf.image.fdr:
497502
if conf.image.detection_image:
@@ -575,9 +580,8 @@ def run_sourcefinder(files, conf, mode):
575580
imagedata = sourcefinder_image_from_accessor(ff, conf=conf)
576581

577582
if mode == "fixed":
578-
# FIXME: conf.image.fixed_coords does not exist
579583
sr = imagedata.fit_fixed_positions(
580-
conf.image.fixed_coords,
584+
eval(conf.image.fixed_posns), # fixed_posns is a string, use eval to obtain it's contents
581585
conf.image.ffbox * max(imagedata.beam[0:2]),
582586
)
583587

test/test_scripts/test_pyse.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
22
from pathlib import Path
3+
import pandas as pd
34

45

56
def run_pyse(files, extra_args, out_dir):
@@ -10,20 +11,7 @@ def run_pyse(files, extra_args, out_dir):
1011
test = subprocess.Popen(cli_args, stdout=subprocess.PIPE)
1112
raw_output = test.communicate()[0]
1213
output = raw_output.decode("utf8").split("\n")
13-
14-
nr_sources_per_image = []
15-
for line in output:
16-
if "Number of detected sources" in line:
17-
nr_sources = int(line.split(" = ")[-1].strip())
18-
nr_sources_per_image.append(nr_sources)
19-
20-
if len(nr_sources_per_image) != len(files):
21-
raise ValueError(
22-
f"Not all images finished correctly. Found {len(nr_sources_per_image)} sets of sources with {len(files)} input images. "
23-
)
24-
25-
return nr_sources_per_image
26-
14+
return output
2715

2816
def test_pyse_export(tmpdir):
2917
files = ["test/data/GRB120422A-120429.fits"]
@@ -37,13 +25,12 @@ def test_pyse_export(tmpdir):
3725
"--islands",
3826
]
3927
extra_args = ["--detection-thr", "6", "--analysis-thr", "5", *export_args]
40-
nr_sources_per_image = run_pyse(files, extra_args, tmpdir)
41-
42-
for n in nr_sources_per_image:
43-
assert n == 1
28+
output = run_pyse(files, extra_args, tmpdir)
4429

4530
# Check CSV
4631
assert Path(f"{tmpdir}/GRB120422A-120429.csv").exists()
32+
df = pd.read_csv(f"{tmpdir}/GRB120422A-120429.csv")
33+
assert len(df) == 1
4734

4835
# Check skymodel
4936
assert Path(f"{tmpdir}/GRB120422A-120429.skymodel").exists()
@@ -62,3 +49,16 @@ def test_pyse_export(tmpdir):
6249

6350
# Check islands
6451
assert Path(f"{tmpdir}/GRB120422A-120429.islands.fits").exists()
52+
53+
def test_pyse_fixed_posns(tmpdir):
54+
files = ["test/data/GRB120422A-120429.fits"]
55+
export_args = [
56+
"--csv",
57+
]
58+
extra_args = ["--detection-thr", "6", "--analysis-thr", "5", "--fixed-posns", "[[136.896, 14.0222]]", *export_args]
59+
nr_sources_per_image = run_pyse(files, extra_args, tmpdir)
60+
61+
# Check CSV
62+
assert Path(f"{tmpdir}/GRB120422A-120429.csv").exists()
63+
df = pd.read_csv(f"{tmpdir}/GRB120422A-120429.csv")
64+
assert len(df) == 1

0 commit comments

Comments
 (0)