Coverage for pesummary/gw/file/formats/xml.py: 88.2%
17 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-12-09 22:34 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-12-09 22:34 +0000
1# Licensed under an MIT style license -- see LICENSE.md
3from gwpy.table import Table
4import numpy as np
6__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"]
9def read_xml(
10 path, format="ligolw", tablename="sim_inspiral", num=None, cls=None,
11 additional_xml_map={}, ignore_params=["beta"], **kwargs
12):
13 """Grab the data from an xml file
15 Parameters
16 ----------
17 path: str
18 Path to the injection file you wish to read
19 format: str, optional
20 The format of your xml. Default is 'ligolw'
21 tablename: str, optional
22 Name of the table you wish to load. Default is 'sim_inspiral'
23 num: int, optional
24 The row you wish to load. Default is None
25 additional_xml_map: dict, optional
26 Additional mapping of non standard names. Key is the
27 standard parameter name and item is the name stored in
28 the xml file
29 """
30 from pesummary.gw.file.standard_names import standard_names
32 table = Table.read(path, format=format, tablename=tablename)
33 injection = {
34 standard_names[key]: [table[key][num]] if num is not None else
35 list(table[key]) for key in table.colnames if key in
36 standard_names.keys()
37 }
38 for key, item in additional_xml_map.items():
39 injection[key] = (
40 [table[item][num]] if num is not None else list(table[item])
41 )
42 for param in ignore_params:
43 if param in injection.keys():
44 _ = injection.pop(param)
45 if cls is not None:
46 return cls(injection)
47 parameters = list(injection.keys())
48 samples = np.array([injection[param] for param in parameters])
49 return parameters, samples.T.tolist()