Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions sourcefinder/utility/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def construct_argument_parser():
"--structuring-element",
type=ast.literal_eval,
help="""
Structuring element for morphological operations, provided as a
Python-style nested list, e.g. '[[1,1,1], [1,1,1], [1,1,1]]' for
Structuring element for morphological operations, provided as a
Python-style nested list, e.g. '[[1,1,1], [1,1,1], [1,1,1]]' for
8-connectivity and '[[0,1,0], [1,1,1], [0,1,0]]' for 4-connectivity.
This is used for defining the connectivity in connected-component
This is used for defining the connectivity in connected-component
labelling.
""",
)
Expand Down Expand Up @@ -575,9 +575,8 @@ def run_sourcefinder(files, conf, mode):
imagedata = sourcefinder_image_from_accessor(ff, conf=conf)

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

Expand Down
36 changes: 18 additions & 18 deletions test/test_scripts/test_pyse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
from pathlib import Path
import pandas as pd


def run_pyse(files, extra_args, out_dir):
Expand All @@ -10,20 +11,7 @@ def run_pyse(files, extra_args, out_dir):
test = subprocess.Popen(cli_args, stdout=subprocess.PIPE)
raw_output = test.communicate()[0]
output = raw_output.decode("utf8").split("\n")

nr_sources_per_image = []
for line in output:
if "Number of detected sources" in line:
nr_sources = int(line.split(" = ")[-1].strip())
nr_sources_per_image.append(nr_sources)

if len(nr_sources_per_image) != len(files):
raise ValueError(
f"Not all images finished correctly. Found {len(nr_sources_per_image)} sets of sources with {len(files)} input images. "
)

return nr_sources_per_image

return output

def test_pyse_export(tmpdir):
files = ["test/data/GRB120422A-120429.fits"]
Expand All @@ -37,13 +25,12 @@ def test_pyse_export(tmpdir):
"--islands",
]
extra_args = ["--detection-thr", "6", "--analysis-thr", "5", *export_args]
nr_sources_per_image = run_pyse(files, extra_args, tmpdir)

for n in nr_sources_per_image:
assert n == 1
output = run_pyse(files, extra_args, tmpdir)

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

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

# Check islands
assert Path(f"{tmpdir}/GRB120422A-120429.islands.fits").exists()

def test_pyse_fixed_posns(tmpdir):
files = ["test/data/GRB120422A-120429.fits"]
export_args = [
"--csv",
]
extra_args = ["--detection-thr", "6", "--analysis-thr", "5", "--fixed-posns", "[[136.896, 14.0222]]", *export_args]
nr_sources_per_image = run_pyse(files, extra_args, tmpdir)

# Check CSV
assert Path(f"{tmpdir}/GRB120422A-120429.csv").exists()
df = pd.read_csv(f"{tmpdir}/GRB120422A-120429.csv")
assert len(df) == 1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which cases could we have len(df) > 1?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why does it pass now? Before this commit it didn't.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would get a different number of sources if you lower the detection and analysis thresholds or use a different image for testing.

It passes now because I split test_pyse into two tests. One test tries all export options as before and the other specifies a specific target location. Combining the target location with residuals export or island export is a problem. This is why I was suggesting an error message here: #181 (comment)