thin_posterior.py 1.1 KB
Newer Older
1
2
3
4
5
6
"""Thin posterior"""

import h5py
import pickle as pkl


Chris Jewell's avatar
Chris Jewell committed
7
8
def thin_posterior(input_file, output_file, config):

9
    idx = slice(config["start"], config["end"], config["by"])
10
11

    f = h5py.File(input_file, "r", rdcc_nbytes=1024 ** 3, rdcc_nslots=1e6)
12
13
14

    output_dict = {k: v[idx] for k, v in f["samples"].items()}
    output_dict["initial_state"] = f["initial_state"][:]
15
16
17
18
19
20
21
22
23
24
25
26
    f.close()

    with open(output_file, "wb") as f:
        pkl.dump(
            output_dict,
            f,
        )


if __name__ == "__main__":

    import yaml
27
    import argparse
28

29
30
31
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-c", "--config", type=str, help="Configuration file", required=True
32
    )
33
34
    parser.add_argument(
        "-o", "--output", type=str, help="Output pkl file", required=True
35
    )
36
37
    parser.add_argument("samples", type=str, help="Posterior HDF5 file")
    args = parser.parse_args()
38

39
40
41
42
43
    with open(args.config, "r") as f:
        config = yaml.load(f, Loader=yaml.FullLoader)

    print("Config: ", config["ThinPosterior"])
    thin_posterior(args.samples, args.output, config["ThinPosterior"])