diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-20 12:11:25 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-20 12:11:25 +0800 |
commit | cba36462e9e70f45341e432074c726dda5e31092 (patch) | |
tree | 0bc9885d0ff86b563e0fb5321c56d51d5687ba70 /bin/shuffle_profile.py | |
parent | 2a069ed00d6f1c83153be9174c296e5540f37d30 (diff) | |
download | chandra-acis-analysis-cba36462e9e70f45341e432074c726dda5e31092.tar.bz2 |
Move shell/python scripts from 'mass_profile/' to 'bin/'
Diffstat (limited to 'bin/shuffle_profile.py')
-rwxr-xr-x | bin/shuffle_profile.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/bin/shuffle_profile.py b/bin/shuffle_profile.py new file mode 100755 index 0000000..124f505 --- /dev/null +++ b/bin/shuffle_profile.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# +# Shuffle the profile data point values according to their errors. +# +# Weitian LI +# 2017-02-07 + +import sys +import numpy as np + + +if len(sys.argv) != 3: + print("Usage: %s <input_profile> <shuffled_profile>") + sys.exit(1) + + +# 4-column data: radius, err, temperature/brightness, err +data = np.loadtxt(sys.argv[1]) + +x1 = data[:, 2] +xe = data[:, 3] +x2 = np.zeros(shape=x1.shape) + +for i in range(len(x2)): + if x1[i] <= 0 or xe[i] <= 0: + # Skip shuffle + x2[i] = x1[i] + + v = -1.0 + while v <= 0: + v = np.random.normal(0.0, 1.0) * xe[i] + x1[i] + x2[i] = v + +# Replace original values +data[:, 2] = x2 + +np.savetxt(sys.argv[2], data) |