Commit 088db024 authored by Leo Pound Singer's avatar Leo Pound Singer

Work around lack of clobber= support in old versions of Table.write

Original: 9b2367ae6492d919fadd046ef377e01fec8d6772
parent 50ce773d
......@@ -348,6 +348,15 @@ def rename(src, dst):
raise
def rm_f(filename):
"""Remove a file, or be silent if the file does not exist, like `rm -f`."""
try:
os.remove(filename)
except OSError as e:
if e.errno != errno.ENOENT:
raise
def register_to_xmldoc(xmldoc, parser, opts, **kwargs):
from glue.ligolw.utils import process
return process.register_to_xmldoc(
......
......@@ -60,6 +60,7 @@ __author__ = "Leo Singer <leo.singer@ligo.org>"
__all__ = ("read_sky_map", "write_sky_map")
import os
import math
import healpy as hp
import numpy as np
......@@ -364,6 +365,12 @@ def write_sky_map(filename, m, **kwargs):
# Scientific Linux 7 computing clusters.
fits.table_to_hdu
except AttributeError:
# FIXME: With some old versions of astropy that we still have to
# support, the astropy.table.Table.write method did not support the
# clobber argument. So we have to manually delete the file first so
# that astropy.io.fits does not complain that the file exists.
from ..bayestar.command import rm_f
rm_f(filename)
m.write(filename, format='fits')
hdulist = fits.open(filename)
_, hdu = hdulist
......
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