From 6eb4031ac1aa3000e9533de890455a9935564ede Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 7 Feb 2017 21:35:57 +0800 Subject: Add shuffle_profile.py to replace shuffle_{T,sbp}.py NOTE: This tool shuffle the data on column 3 according to their errors on column 4. --- mass_profile/shuffle_T.py | 18 ------------------ mass_profile/shuffle_profile.py | 37 +++++++++++++++++++++++++++++++++++++ mass_profile/shuffle_sbp.py | 18 ------------------ 3 files changed, 37 insertions(+), 36 deletions(-) delete mode 100755 mass_profile/shuffle_T.py create mode 100755 mass_profile/shuffle_profile.py delete mode 100755 mass_profile/shuffle_sbp.py diff --git a/mass_profile/shuffle_T.py b/mass_profile/shuffle_T.py deleted file mode 100755 index 24e7393..0000000 --- a/mass_profile/shuffle_T.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python - -import sys -import scipy - -output_file=open(sys.argv[2],'w') -for i in open(sys.argv[1]): - r,re,c,s=i.strip().split() - c=float(c) - s=float(s) - - if c>0 and s>0: - c1=-1 - while c1<=0: - c1=scipy.random.normal(0,1)*s+c - - output_file.write("%s\t%s\t%s\t%s\n"%(r,re,c1,s)) - diff --git a/mass_profile/shuffle_profile.py b/mass_profile/shuffle_profile.py new file mode 100755 index 0000000..124f505 --- /dev/null +++ b/mass_profile/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 ") + 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) diff --git a/mass_profile/shuffle_sbp.py b/mass_profile/shuffle_sbp.py deleted file mode 100755 index 210bfb8..0000000 --- a/mass_profile/shuffle_sbp.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python - -import sys -import scipy - -output_file=open(sys.argv[2],'w') -for i in open(sys.argv[1]): - c,s=i.strip().split() - c=float(c) - s=float(s) - - if c>0 and s>0: - c1=-1 - while c1<=0: - c1=scipy.random.normal(0,1)*s+c - - output_file.write("%s\t%s\n"%(c1,s)) - -- cgit v1.2.2