Source code for datafind.metafiles
"""
Functions to manipulate PESummary metafiles.
"""
import shutil
import logging
import h5py
import contextlib
import subprocess
import os
import numpy as np
from .calibration import CalibrationUncertaintyEnvelope
logger = logging.getLogger("gwdata")
[docs]
class PSD:
[docs]
def __init__(self, data, ifo=None):
self.data = data
self.ifo = ifo
[docs]
def to_ascii(self, filename):
np.savetxt(filename, self.data)
[docs]
def to_xml(self):
tmp = "psd.tmp"
self.to_ascii(tmp)
executable = "convert_psd_ascii2xml"
if shutil.which(executable) is not None:
command = [
executable,
"--fname-psd-ascii",
f"{tmp}",
"--conventional-postfix",
"--ifo",
f"{self.ifo}",
]
pipe = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
out, err = pipe.communicate()
if err:
logger.warning(f"An XML format PSD could not be created. {err}")
os.remove(tmp)
else:
logger.warning("An XML format PSD could not be created.")