# HG changeset patch
# User muon-spectroscopy-computational-project
# Date 1689686763 0
# Node ID 06aabd70b86935a64ceed8f7f6034f34318e429a
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_combine commit 70a4d37ecdf5d586703cfc509922311e95d3205c
diff -r 000000000000 -r 06aabd70b869 combine.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/combine.py Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,50 @@
+import json
+import sys
+
+import numpy as np
+
+import scipy.stats as stats
+
+
+def main():
+ input_json_path = sys.argv[1]
+ params = json.load(open(input_json_path, "r"))
+
+ x_equal = True
+ data = np.loadtxt(params["data_in"][0], usecols=(0, 1))
+ x_values = [data[:, 0]]
+ y_values = [data[:, 1]]
+ bins = len(data)
+
+ for path in params["data_in"][1:]:
+ data = np.loadtxt(path, usecols=(0, 1))
+ x_values.append(data[:, 0])
+ y_values.append(data[:, 1])
+ length_equal = bins == len(data)
+ bins = min(bins, len(data))
+ x_equal = (
+ x_equal and length_equal and np.allclose(x_values, x_values[-1])
+ )
+
+ if x_equal:
+ print(
+ "All x ranges were identical, performing direct average over "
+ f"{len(x_values)} files"
+ )
+ means = np.mean(y_values, axis=0)
+ np.savetxt("data_out.dat", np.column_stack((x_values[0], means)))
+ return
+
+ if params["bins"] is not None:
+ bins = params["bins"]
+
+ x_flat = np.concatenate(x_values)
+ y_flat = np.concatenate(y_values)
+ print(f"Averaging {len(x_flat)} data points into {bins} bins")
+ means, edges, _ = stats.binned_statistic(x_flat, y_flat, bins=bins)
+ data_out = np.column_stack(((edges[1:] + edges[:-1]) / 2, means))
+ np.savetxt("data_out.dat", data_out)
+
+
+if __name__ == "__main__":
+ main()
diff -r 000000000000 -r 06aabd70b869 muon_macros.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/muon_macros.xml Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ^[\s\d,\[\]]+$
+
+
+
+
+
+ 2.2.1
+ 10.5281/zenodo.7733979
+ 10.5281/zenodo.6517626
+ 0.3.0
+ 10.5281/zenodo.8026711
+ 10.5281/zenodo.7025643
+
\ No newline at end of file
diff -r 000000000000 -r 06aabd70b869 muspinsim_combine.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/muspinsim_combine.xml Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,75 @@
+
+ combine datafiles generated from MuSpinSim
+
+
+
+ 0
+ muon_macros.xml
+
+
+
+
+
+
+
+ numpy
+ scipy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @MUSPINSIM_CITATION@
+
+
diff -r 000000000000 -r 06aabd70b869 test-data/high.dat
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/high.dat Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,3 @@
+7.000000000000000000e-02 1.500000000000000000e-01
+8.000000000000000000e-02 1.000000000000000000e-01
+9.000000000000000000e-02 0.500000000000000000e-01
diff -r 000000000000 -r 06aabd70b869 test-data/low.dat
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/low.dat Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,3 @@
+0.000000000000000000e+00 5.000000000000000000e-01
+1.000000000000000000e-02 4.500000000000000000e-01
+2.000000000000000000e-02 4.000000000000000000e-01
diff -r 000000000000 -r 06aabd70b869 test-data/mid.dat
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/mid.dat Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,10 @@
+0.500000000000000000e-02 2.500000000000000000e-01
+1.500000000000000000e-02 2.500000000000000000e-01
+2.500000000000000000e-02 2.500000000000000000e-01
+3.500000000000000000e-02 2.500000000000000000e-01
+4.500000000000000000e-02 2.500000000000000000e-01
+5.500000000000000000e-02 2.500000000000000000e-01
+6.500000000000000000e-02 2.500000000000000000e-01
+7.500000000000000000e-02 2.500000000000000000e-01
+8.500000000000000000e-02 2.500000000000000000e-01
+9.500000000000000000e-02 2.500000000000000000e-01
diff -r 000000000000 -r 06aabd70b869 test-data/out_all.dat
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/out_all.dat Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,3 @@
+1.583333333333333467e-02 3.500000000000000333e-01
+4.750000000000000056e-02 2.500000000000000000e-01
+7.916666666666666297e-02 1.857142857142857206e-01
diff -r 000000000000 -r 06aabd70b869 test-data/out_all_10.dat
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/out_all_10.dat Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,10 @@
+4.749999999999999882e-03 3.750000000000000000e-01
+1.424999999999999878e-02 3.499999999999999778e-01
+2.375000000000000028e-02 3.250000000000000111e-01
+3.325000000000000178e-02 2.500000000000000000e-01
+4.274999999999999634e-02 2.500000000000000000e-01
+5.224999999999999784e-02 2.500000000000000000e-01
+6.174999999999999933e-02 2.500000000000000000e-01
+7.125000000000000777e-02 2.000000000000000111e-01
+8.074999999999998845e-02 1.749999999999999889e-01
+9.024999999999999689e-02 1.499999999999999944e-01
diff -r 000000000000 -r 06aabd70b869 test-data/out_low.dat
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/out_low.dat Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,3 @@
+0.000000000000000000e+00 5.000000000000000000e-01
+1.000000000000000021e-02 4.500000000000000111e-01
+2.000000000000000042e-02 4.000000000000000222e-01
diff -r 000000000000 -r 06aabd70b869 test-data/out_low_high.dat
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/out_low_high.dat Tue Jul 18 13:26:03 2023 +0000
@@ -0,0 +1,3 @@
+1.499999999999999944e-02 4.500000000000000111e-01
+4.499999999999999833e-02 nan
+7.499999999999999722e-02 9.999999999999999167e-02