aboutsummaryrefslogtreecommitdiffstats
path: root/astro/21cm/cube_mean.py
blob: a92553217397195747137758259de4892c38f289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
#
# Copyright (c) 2017 Weitian LI <weitian@aaronly.me>
# MIT License
#

"""
Calculate the mean values of the cube.
"""

import argparse

import numpy as np


def main():
    parser = argparse.ArgumentParser(
        description="Calculate the mean value of the data cube")
    parser.add_argument("-d", "--dtype", default="float32",
                        help="NumPy dtype of data cubes (default: float32)")
    parser.add_argument("infiles", nargs="+", help="input data cubes")
    args = parser.parse_args()

    print("# filename: mean side_length")
    for f in args.infiles:
        cube = np.fromfile(open(f, "rb"), dtype=args.dtype)
        sidelen = round(cube.shape[0] ** (1.0/3))
        mean = cube.mean()
        print("%s:\t%g\t\t%d" % (f, mean, sidelen))


if __name__ == "__main__":
    main()