diff options
author | Aaron LI <aly@aaronly.me> | 2017-06-11 14:59:13 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2017-06-11 14:59:13 +0800 |
commit | dc3a26c947a101b72bf37a16ce71ee3704a5d61f (patch) | |
tree | c6378ad634385635edb29e6a7922c2bae3e67f3d /astro/21cm/cube_mean.py | |
parent | 2414e200871936953b3dff78a39bb1aee72b1caa (diff) | |
download | atoolbox-dc3a26c947a101b72bf37a16ce71ee3704a5d61f.tar.bz2 |
Add astro/21cm/{freq2z,z2freq,cube_mean}.py
Migrated from my other repo 21cmFAST/tools.
Diffstat (limited to 'astro/21cm/cube_mean.py')
-rwxr-xr-x | astro/21cm/cube_mean.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/astro/21cm/cube_mean.py b/astro/21cm/cube_mean.py new file mode 100755 index 0000000..9ff33d4 --- /dev/null +++ b/astro/21cm/cube_mean.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Weitian LI <weitian@aaronly.me> +# MIT License +# + +""" +Calculate the mean values of the cube. +""" + +import os +import sys +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() |