Mercurial > repos > muon-spectroscopy-computational-project > muspinsim_plot
annotate generate_plot.py @ 4:e15e8800c39e draft default tip
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit 70a4d37ecdf5d586703cfc509922311e95d3205c
author | muon-spectroscopy-computational-project |
---|---|
date | Tue, 18 Jul 2023 13:26:26 +0000 |
parents | 89ae4a5724a5 |
children |
rev | line source |
---|---|
0
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
1 import json |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
2 import sys |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
3 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
4 import matplotlib.pyplot as plt |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
5 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
6 import numpy as np |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
7 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
8 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
9 def main(): |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
10 input_json_path = sys.argv[1] |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
11 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
12 plot_params = json.load(open(input_json_path, "r")) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
13 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
14 for series in plot_params["mu_out_series"]: |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
15 mu_data = np.loadtxt(series['mu_data'], usecols=(0, 1)) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
16 x, y = mu_data.T |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
17 { |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
18 'line': lambda x, y, label, c, args: |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
19 plt.plot(x, y, |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
20 label=label, |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
21 c=c, |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
22 ls=args['linestyle'], |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
23 lw=args['linewidth'] |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
24 ), |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
25 'points': lambda x, y, label, c, args: |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
26 plt.scatter(x, y, |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
27 label=label, |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
28 c=c, |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
29 s=args['pointscale'], |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
30 marker=args['pointstyle'], |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
31 ) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
32 }.get(series['series_type']['type'])( |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
33 x, y, series['mu_label'], series['colour'], series['series_type'] |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
34 ) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
35 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
36 plt.xlabel(plot_params['xlab']) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
37 plt.ylabel(plot_params['ylab']) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
38 plt.title(plot_params['title']) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
39 plt.legend(loc="upper right") |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
40 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
41 outfile = "outfile.{}".format(plot_params['out_file_type']) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
42 plt.savefig(outfile, format=plot_params['out_file_type']) |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
43 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
44 |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
45 if __name__ == '__main__': |
89ae4a5724a5
planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
muon-spectroscopy-computational-project
parents:
diff
changeset
|
46 main() |