Commit d5e649d6 authored by Leo Pound Singer's avatar Leo Pound Singer

Fix error message in ligo-skymap-from-samples

A misspelled identifier (`parser` instead of `_parser`) caused an
exception to be raised instead of a user-friendly error message to
be printed if the posterior samples file lacked a distance column.

Thanks to @salvatore-vitale for reporting this.
parent e7288994
Pipeline #55726 passed with stages
in 9 minutes and 34 seconds
......@@ -108,10 +108,10 @@ def main(args=None):
if args.loadpost is None:
if dist is None:
if args.enable_distance_map:
parser.error("The posterior samples file '{0}' does not have "
"a distance column named 'dist' or 'distance'. "
"Cannot generate distance map.".format(
args.samples.name))
_parser.error("The posterior samples file '{0}' does not have "
"a distance column named 'dist' or 'distance'. "
"Cannot generate distance map.".format(
args.samples.name))
pts = np.column_stack((data['ra'], data['dec']))
else:
pts = np.column_stack((data['ra'], data['dec'], dist))
......
......@@ -22,7 +22,8 @@ def run_entry_point(name, *args):
try:
main(args)
except SystemExit as e:
assert e.code == 0
if e.code != 0:
raise subprocess.CalledProcessError(e.code, [name, *args])
def exec_glue(name, *args):
......@@ -48,7 +49,9 @@ def run_glue(name, *args):
process = multiprocessing.Process(target=exec_glue, args=[name, *args])
process.start()
process.join()
assert process.exitcode == 0
if process.exitcode != 0:
raise subprocess.CalledProcessError(
process.exitcode, [name, *args])
def run_lalsuite(name, *args):
......
from subprocess import CalledProcessError
from astropy.coordinates import (CartesianRepresentation, SkyCoord,
SphericalRepresentation)
from astropy.table import Table
......@@ -7,7 +9,7 @@ import numpy as np
from scipy import stats
import pytest
from ...io.hdf5 import write_samples
from ...io.hdf5 import read_samples, write_samples
from . import run_entry_point
......@@ -40,6 +42,15 @@ def samples(seed, tmpdir):
return filename
@pytest.fixture
def samples_without_distance(samples, tmpdir):
table = read_samples(samples, path='/posterior_samples')
del table['dist']
filename = str(tmpdir / 'samples_without_distance.hdf5')
write_samples(table, filename, path='/posterior_samples')
return filename
def test_from_samples(samples, tmpdir):
"""Test ligo-skyamp-from-samples."""
run_entry_point('ligo-skymap-from-samples', '--seed', '150914',
......@@ -48,3 +59,14 @@ def test_from_samples(samples, tmpdir):
table = Table.read(str(tmpdir / 'skymap.fits'), format='fits')
assert table.meta['OBJECT'] == 'S1234'
assert table.meta['INSTRUME'] == 'H1,L1,V1'
def test_from_samples_without_distance(samples_without_distance,
capsys, tmpdir):
"""Test ligo-skyamp-from-samples on an MCMC samples file that does not have
a distance column."""
with pytest.raises(CalledProcessError):
run_entry_point('ligo-skymap-from-samples', samples_without_distance,
'-o', str(tmpdir))
out, err = capsys.readouterr()
assert "does not have a distance column named 'dist' or 'distance'" in err
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment