Mercurial > repos > astroteam > plot_tools_astro_tool
annotate sky_plot.py @ 0:2b1759ccaa8b draft default tip
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
author | astroteam |
---|---|
date | Fri, 25 Apr 2025 21:48:27 +0000 |
parents | |
children |
rev | line source |
---|---|
0
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
1 #!/usr/bin/env python |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
2 # coding: utf-8 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
3 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
4 #!/usr/bin/env python |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
5 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
6 # This script is generated with nb2galaxy |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
7 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
8 # flake8: noqa |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
9 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
10 import json |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
11 import os |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
12 import shutil |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
13 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
14 from oda_api.json import CustomJSONEncoder |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
15 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
16 fn = "data.tsv" # oda:POSIXPath |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
17 skiprows = 0 # http://odahub.io/ontology#Integer |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
18 sep = "whitespace" # http://odahub.io/ontology#String ; oda:allowed_value "auto", "comma", "tab", "whitespace", "semicolon" |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
19 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
20 ra_col = "c3" # http://odahub.io/ontology#String |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
21 dec_col = "c4" # http://odahub.io/ontology#String |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
22 weight_col = "" # http://odahub.io/ontology#String |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
23 binsz = 0.02 # http://odahub.io/ontology#Float |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
24 window_size_RA = 2.0 # http://odahub.io/ontology#Degree |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
25 window_size_DEC = 2.0 # http://odahub.io/ontology#Degree |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
26 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
27 _galaxy_wd = os.getcwd() |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
28 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
29 with open("inputs.json", "r") as fd: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
30 inp_dic = json.load(fd) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
31 if "C_data_product_" in inp_dic.keys(): |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
32 inp_pdic = inp_dic["C_data_product_"] |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
33 else: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
34 inp_pdic = inp_dic |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
35 fn = str(inp_pdic["fn"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
36 skiprows = int(inp_pdic["skiprows"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
37 sep = str(inp_pdic["sep"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
38 ra_col = str(inp_pdic["ra_col"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
39 dec_col = str(inp_pdic["dec_col"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
40 weight_col = str(inp_pdic["weight_col"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
41 binsz = float(inp_pdic["binsz"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
42 window_size_RA = float(inp_pdic["window_size_RA"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
43 window_size_DEC = float(inp_pdic["window_size_DEC"]) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
44 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
45 import astropy.units as u |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
46 import matplotlib.pyplot as plt |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
47 import numpy as np |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
48 import pandas as pd |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
49 from astropy.coordinates import SkyCoord |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
50 from gammapy.maps import Map |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
51 from oda_api.data_products import ImageDataProduct, PictureProduct |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
52 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
53 separators = { |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
54 "tab": "\t", |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
55 "comma": ",", |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
56 "semicolon": ";", |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
57 "whitespace": "\s+", |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
58 "space": " ", |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
59 } |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
60 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
61 df = None |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
62 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
63 if sep == "auto": |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
64 for name, s in separators.items(): |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
65 try: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
66 df = pd.read_csv(fn, sep=s, index_col=False, skiprows=skiprows) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
67 if len(df.columns) > 2: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
68 sep = s |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
69 print("Detected separator: ", name) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
70 break |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
71 except Exception as e: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
72 print("Separator ", s, " failed", e) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
73 assert sep != "auto", "Failed to find valid separator" |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
74 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
75 if df is None: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
76 df = pd.read_csv(fn, sep=separators[sep], index_col=False) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
77 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
78 df.columns |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
79 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
80 def read_data(df, colname, optional=False): |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
81 for i, c in enumerate(df.columns): |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
82 if colname == f"c{i+1}": |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
83 print(colname, c) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
84 return df[c].values |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
85 elif colname == c: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
86 print(colname, c) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
87 return df[c].values |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
88 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
89 assert optional, colname + " column not found" |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
90 return None |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
91 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
92 ra = read_data(df, ra_col) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
93 dec = read_data(df, dec_col) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
94 w = read_data(df, weight_col, optional=True) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
95 if w is None: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
96 w = np.ones_like(ra) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
97 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
98 source = SkyCoord(ra=np.mean(ra) * u.deg, dec=np.mean(dec) * u.deg) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
99 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
100 map = Map.create( |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
101 binsz=binsz, |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
102 width=(window_size_RA * u.deg, window_size_DEC * u.deg), |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
103 frame="icrs", |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
104 axes=[], |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
105 skydir=SkyCoord(source), |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
106 ) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
107 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
108 map.fill_by_coord({"lat": dec * u.deg, "lon": ra * u.deg}, weights=w) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
109 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
110 map.plot() |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
111 plt.savefig("map.png") |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
112 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
113 map.write("map.fits", overwrite=True) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
114 fits_image = ImageDataProduct.from_fits_file("map.fits") |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
115 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
116 plot = PictureProduct.from_file("map.png") |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
117 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
118 plot = plot # http://odahub.io/ontology#ODAPictureProduct |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
119 fits_image = fits_image # http://odahub.io/ontology#Image |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
120 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
121 # output gathering |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
122 _galaxy_meta_data = {} |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
123 _oda_outs = [] |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
124 _oda_outs.append(("out_sky_plot_plot", "plot_galaxy.output", plot)) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
125 _oda_outs.append( |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
126 ("out_sky_plot_fits_image", "fits_image_galaxy.output", fits_image) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
127 ) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
128 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
129 for _outn, _outfn, _outv in _oda_outs: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
130 _galaxy_outfile_name = os.path.join(_galaxy_wd, _outfn) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
131 if isinstance(_outv, str) and os.path.isfile(_outv): |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
132 shutil.move(_outv, _galaxy_outfile_name) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
133 _galaxy_meta_data[_outn] = {"ext": "_sniff_"} |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
134 elif getattr(_outv, "write_fits_file", None): |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
135 _outv.write_fits_file(_galaxy_outfile_name) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
136 _galaxy_meta_data[_outn] = {"ext": "fits"} |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
137 elif getattr(_outv, "write_file", None): |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
138 _outv.write_file(_galaxy_outfile_name) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
139 _galaxy_meta_data[_outn] = {"ext": "_sniff_"} |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
140 else: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
141 with open(_galaxy_outfile_name, "w") as fd: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
142 json.dump(_outv, fd, cls=CustomJSONEncoder) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
143 _galaxy_meta_data[_outn] = {"ext": "json"} |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
144 |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
145 with open(os.path.join(_galaxy_wd, "galaxy.json"), "w") as fd: |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
146 json.dump(_galaxy_meta_data, fd) |
2b1759ccaa8b
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit f28a8cb73a7f3053eac92166867a48b3d4af28fd
astroteam
parents:
diff
changeset
|
147 print("*** Job finished successfully ***") |