Mercurial > repos > astroteam > analyse_short_astro_text_astro_tool
comparison aux_functions.py @ 0:a35056104c2c draft default tip
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit da42ae0d18f550dec7f6d7e29d297e7cf1909df2
author | astroteam |
---|---|
date | Fri, 13 Jun 2025 13:26:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a35056104c2c |
---|---|
1 import numpy as np | |
2 | |
3 | |
4 def list_tel(key, G): | |
5 cols = [] | |
6 | |
7 for e in G.query(f'SELECT ?a ?b ?c WHERE {{<{key}> <https://odahub.io/ontology#sensitivity> ?c}} LIMIT 500'): | |
8 cols.append(str(e[2])) | |
9 | |
10 if len(cols) == 0: | |
11 for e in G.query(f'SELECT ?a ?b ?c WHERE {{?a <http://purl.org/dc/terms/isRequiredBy> <{key}>}} LIMIT 500'): | |
12 for f in G.query(f'SELECT ?a ?b ?c WHERE {{<{e[0]}> <https://odahub.io/ontology#sensitivity> ?c}} LIMIT 500'): | |
13 cols.append(str(f[2])) | |
14 | |
15 # if len(cols) == 0: | |
16 # aux_ = [] | |
17 # for key in dict_.keys(): | |
18 # if dict_[key] == -i: | |
19 # for e in G.query(f'SELECT ?a ?b ?c WHERE {{?a <http://purl.org/dc/terms/isPartOf> <{key}>}} LIMIT 500'): | |
20 # # for f in G.query(f'SELECT ?a ?b ?c WHERE {{<{e[0]}> <https://odahub.io/ontology#sensitivity> ?c}} LIMIT 500'): | |
21 # aux_.append(e[0]) | |
22 # if len(aux_) == 1: | |
23 # print(aux_) | |
24 | |
25 return list(set(cols)) | |
26 | |
27 | |
28 def provide_telescope_sensitivities(dict_, G): | |
29 colors = [] | |
30 N_TEL = len(dict_.keys()) | |
31 for key in dict_.keys(): | |
32 for e in G.query(f'SELECT ?a ?b ?c WHERE {{<{key}> <https://odahub.io/ontology#sensitivity> ?c}} LIMIT 500'): | |
33 colors.append(str(e[2])) | |
34 | |
35 return list(set(colors)), N_TEL | |
36 | |
37 | |
38 def bits(ask="try"): | |
39 if ask == "None": | |
40 return 0 # (0 0 0 0 0 0 0 0 0) | |
41 if ask == "gamma-ray": | |
42 return 1 # (0 0 0 0 0 0 0 0 1) | |
43 if ask == "x-ray": | |
44 return 2 # (0 0 0 0 0 0 0 1 0) | |
45 if ask == "ultraviolet": | |
46 return 4 # (0 0 0 0 0 0 1 0 0) | |
47 if ask == "optical": | |
48 return 8 # (0 0 0 0 0 1 0 0 0) | |
49 if ask == "infrared": | |
50 return 16 # (0 0 0 0 1 0 0 0 0) | |
51 if ask == "radio": | |
52 return 32 # (0 0 0 1 0 0 0 0 0) | |
53 if ask == "cosmic-ray": | |
54 return 64 # (0 0 1 0 0 0 0 0 0) | |
55 if ask == "gravitational-wave": | |
56 return 128 # (0 1 0 0 0 0 0 0 0) | |
57 if ask == "neutrino": | |
58 return 256 # (1 0 0 0 0 0 0 0 0) | |
59 # print(f"You have asked for {ask}. Which does not exist. Please check bits() function.") | |
60 # os._exit(1) | |
61 | |
62 | |
63 def bits2sens(ask=None): | |
64 if ask == 0: | |
65 return "None" | |
66 if ask == 1: | |
67 return "gamma-ray" | |
68 if ask == 2: | |
69 return "x-ray" | |
70 if ask == 4: | |
71 return "ultraviolet" | |
72 if ask == 8: | |
73 return "optical" | |
74 if ask == 16: | |
75 return "infrared" | |
76 if ask == 32: | |
77 return "radio" | |
78 if ask == 64: | |
79 return "cosmic-ray" | |
80 if ask == 128: | |
81 return "gravitational-wave" | |
82 if ask == 256: | |
83 return "neutrino" | |
84 # print(f"You have asked for {ask}. Which does not exist. Please check bits() function.") | |
85 # os._exit(1) | |
86 | |
87 | |
88 def compute_sensitivity(colors): | |
89 final_ = 0 | |
90 for color in colors: | |
91 final_ = np.bitwise_or(bits(ask=color), final_) | |
92 | |
93 return final_ | |
94 | |
95 | |
96 def compute_sensitivity_int(colors_int): | |
97 final_ = 0 | |
98 for color in colors_int: | |
99 final_ = np.bitwise_or(color, final_) | |
100 | |
101 return final_ | |
102 | |
103 | |
104 def find_sensitivity(bit_integer): | |
105 list_o = [] | |
106 list_b = [] | |
107 list_b_12 = [] | |
108 | |
109 colors = ['gravitational-wave', 'radio', 'ultraviolet', 'optical', 'gamma-ray', 'infrared', 'x-ray', 'cosmic-ray', 'neutrino'] | |
110 | |
111 for sens in colors: | |
112 bit_ = bits(ask=sens) | |
113 if np.bitwise_and(bit_, bit_integer) == bit_: | |
114 list_o.append(sens) | |
115 list_b.append(bit_) | |
116 | |
117 for i_1 in range(len(colors)): | |
118 s_1 = colors[i_1] | |
119 b_1 = bits(ask=s_1) | |
120 for i_2 in range(i_1, len(colors), 1): | |
121 s_2 = colors[i_2] | |
122 b_2 = bits(ask=s_2) | |
123 | |
124 if i_1 != i_2: | |
125 b_12 = np.bitwise_or(b_1, b_2) | |
126 | |
127 if np.bitwise_and(b_12, bit_integer) == b_12: | |
128 list_b_12.append(b_12) | |
129 else: | |
130 if b_2 == bit_integer: | |
131 list_b_12.append(b_2) | |
132 | |
133 return list_o, list_b, list_b_12 | |
134 | |
135 | |
136 def find_name_workflow(list_telescopes): | |
137 indices = [] | |
138 if "https://odahub.io/ontology#international-gamma-ray-astrophysics-laboratory" in list_telescopes: | |
139 indices.append(50) | |
140 if "https://odahub.io/ontology#imager-on-board-the-integral-satellite" in list_telescopes: | |
141 indices.append(51) | |
142 if "https://odahub.io/ontology#joint-european-x-ray-monitor" in list_telescopes: | |
143 indices.append(52) | |
144 if "https://odahub.io/ontology#spectrometer-on-integral" in list_telescopes: | |
145 indices.append(53) | |
146 if "https://odahub.io/ontology#astronomy-with-a-neutrino-telescope-and-abyss-environmental-research-project" in list_telescopes: | |
147 indices.append(54) | |
148 if "https://odahub.io/ontology#laser-interferometer-gravitational-wave-observatory" in list_telescopes: | |
149 indices.append(55) | |
150 if "https://odahub.io/ontology#virgo" in list_telescopes: | |
151 indices.append(55) | |
152 if "https://odahub.io/ontology#iceCube-neutrino-observatory" in list_telescopes: | |
153 indices.append(56) | |
154 if "https://odahub.io/ontology#high-energy-stereoscopic-system" in list_telescopes: | |
155 indices.append(57) | |
156 if "https://odahub.io/ontology#cherenkov-telescope-array" in list_telescopes: | |
157 indices.append(58) | |
158 if "https://odahub.io/ontology#cherenkov-telescope-array-observatory" in list_telescopes: | |
159 indices.append(58) | |
160 return indices | |
161 | |
162 | |
163 def get_list_instruments_CNN_MMODA(): | |
164 return ["INTEGRAL", "ISGRI", "JEM-X", "SPI-ACS", "ANTARES", "LIGO/VIRGO", "IceCube", "HESS", "CTA/CTAO"] | |
165 | |
166 | |
167 def get_dict_instruments_URL_MMODA(): | |
168 return { | |
169 "spi_acs": ["INTEGRAL", "SPI-ACS"], | |
170 "cta": ["CTA/CTAO"], | |
171 "hess": ["HESS"], | |
172 "isgri": ["INTEGRAL", "ISGRI"], | |
173 "jemx": ["INTEGRAL", "JEM-X"], | |
174 "icecube": ["IceCube"], | |
175 "antares": ["ANTARES"], | |
176 "gw": ["LIGO/VIRGO"] | |
177 } |