Coverage for pesummary/core/file/formats/csv.py: 66.7%
9 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 pesummary.core.file.formats.dat import read_dat, _write_dat
5__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"]
8def read_csv(path):
9 """Grab the parameters and samples in a .csv file
11 Parameters
12 ----------
13 path: str
14 path to the result file you wish to read in
15 """
16 return read_dat(path, delimiter=",")
19def _write_csv(
20 parameters, samples, outdir="./", label=None, filename=None, overwrite=False,
21 **kwargs
22):
23 """Write a set of samples to a csv file
25 Parameters
26 ----------
27 parameters: list
28 list of parameters
29 samples: 2d list
30 list of samples. Columns correspond to a given parameter
31 outdir: str, optional
32 directory to write the dat file
33 label: str, optional
34 The label of the analysis. This is used in the filename if a filename
35 if not specified
36 filename: str, optional
37 The name of the file that you wish to write
38 overwrite: Bool, optional
39 If True, an existing file of the same name will be overwritten
40 """
41 return _write_dat(
42 parameters, samples, outdir="./", label=label, filename=filename,
43 overwrite=overwrite, delimiter=",", default_filename="pesummary_{}.csv",
44 **kwargs
45 )
48def write_csv(
49 parameters, samples, outdir="./", label=None, filename=None, overwrite=False,
50 **kwargs
51):
52 """Write a set of samples to a csv file
54 Parameters
55 ----------
56 parameters: nd list
57 list of parameters
58 samples: nd list
59 list of samples. Columns correspond to a given parameter
60 outdir: str, optional
61 directory to write the csv file
62 label: str, optional
63 The label of the analysis. This is used in the filename if a filename
64 if not specified
65 filename: str, optional
66 The name of the file that you wish to write
67 overwrite: Bool, optional
68 If True, an existing file of the same name will be overwritten
69 """
70 from pesummary.io.write import _multi_analysis_write
72 _multi_analysis_write(
73 _write_csv, parameters, samples, outdir=outdir, label=label,
74 filename=filename, overwrite=overwrite, file_format="csv", **kwargs
75 )