aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmass_profile/shuffle_T.py18
-rwxr-xr-xmass_profile/shuffle_profile.py37
-rwxr-xr-xmass_profile/shuffle_sbp.py18
3 files changed, 37 insertions, 36 deletions
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 <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)
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))
-