annotate detectgrb.py @ 0:c80db1ec6611 draft default tip

planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
author astroteam
date Wed, 13 Aug 2025 19:10:53 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
1 #!/usr/bin/env python
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
2 # coding: utf-8
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
3
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
4 #!/usr/bin/env python
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
5
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
6 # This script is generated with nb2galaxy
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
7
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
8 # flake8: noqa
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
9
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
10 import json
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
11 import os
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
12 import shutil
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
13
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
14 from oda_api.json import CustomJSONEncoder
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
15
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
16 T1 = "2023-01-16T04:53:33.9" # http://odahub.io/ontology#StartTime
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
17 T2 = "2023-01-16T04:55:33.9" # http://odahub.io/ontology#EndTime
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
18 detection_time_scales = "1,10"
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
19 lc_time_scale = 0.1 # https://odahub.io/ontology#TimeIntervalSeconds
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
20 background_age = 10 # oda:TimeIntervalSeconds
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
21 min_sn = 5 # https://odahub.io/ontology#SignalToNoiseRatio
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
22
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
23 _galaxy_wd = os.getcwd()
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
24
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
25 with open("inputs.json", "r") as fd:
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
26 inp_dic = json.load(fd)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
27 if "C_data_product_" in inp_dic.keys():
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
28 inp_pdic = inp_dic["C_data_product_"]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
29 else:
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
30 inp_pdic = inp_dic
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
31 T1 = str(inp_pdic["T1"])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
32 T2 = str(inp_pdic["T2"])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
33 detection_time_scales = str(inp_pdic["detection_time_scales"])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
34 lc_time_scale = float(inp_pdic["lc_time_scale"])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
35 background_age = float(inp_pdic["background_age"])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
36 min_sn = int(inp_pdic["min_sn"])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
37
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
38 import numpy as np
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
39 from astropy.time import Time
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
40 from matplotlib import pylab as plt
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
41 from oda_api.api import DispatcherAPI
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
42 from oda_api.data_products import LightCurveDataProduct, PictureProduct
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
43
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
44 disp = DispatcherAPI(
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
45 url="https://www.astro.unige.ch/mmoda//dispatch-data", instrument="mock"
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
46 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
47
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
48 par_dict = {
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
49 "T1": T1,
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
50 "T2": T2,
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
51 "T_format": "isot",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
52 "instrument": "spi_acs",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
53 "product": "spi_acs_lc",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
54 "product_type": "Real",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
55 "time_bin": lc_time_scale,
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
56 "time_bin_format": "sec",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
57 }
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
58
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
59 data_collection = disp.get_product(**par_dict)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
60
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
61 lc = data_collection.spi_acs_lc_0_query.data_unit[1].data
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
62
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
63 lc["TIME"] = (
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
64 lc["TIME"] / 24 / 3600 + (Time(T1).mjd + Time(T2).mjd) / 2.0
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
65 ) # TODO: more accurately
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
66
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
67 def rebin(x, n):
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
68 N = int(len(x) / n)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
69 return np.array(x[: N * n]).reshape((N, n)).sum(1)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
70
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
71 lc = LightCurveDataProduct.from_arrays(
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
72 times=Time(lc["TIME"], format="mjd"), fluxes=lc["RATE"], errors=lc["ERROR"]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
73 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
74
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
75 obj_results = [lc.encode()]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
76
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
77 T0_ijd = lc.data_unit[1].data["TIME"][np.argmax(lc.data_unit[1].data["FLUX"])]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
78
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
79 ijd2plot = lambda x: (x - T0_ijd) * 24 * 3600
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
80
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
81 m_bkg = ijd2plot(lc.data_unit[1].data["TIME"]) < background_age
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
82 np.sum(m_bkg)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
83 bkg = np.mean(lc.data_unit[1].data["FLUX"][m_bkg])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
84 bkg
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
85
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
86 from matplotlib import pylab as plt
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
87
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
88 plt.figure(figsize=(10, 6))
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
89
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
90 plt.errorbar(
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
91 ijd2plot(lc.data_unit[1].data["TIME"]),
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
92 lc.data_unit[1].data["FLUX"],
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
93 lc.data_unit[1].data["ERROR"],
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
94 label=f"{lc_time_scale} s",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
95 alpha=0.5,
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
96 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
97
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
98 best_detection = {"sn": None, "timescale": None, "t_max_sn": None}
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
99
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
100 for detection_time_scale in detection_time_scales.split(","):
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
101 n = int(float(detection_time_scale.strip()) / lc_time_scale)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
102
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
103 r_t = rebin(lc.data_unit[1].data["TIME"], n) / n
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
104 r_c = rebin(lc.data_unit[1].data["FLUX"], n) / n
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
105 r_ce = rebin(lc.data_unit[1].data["ERROR"] ** 2, n) ** 0.5 / n
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
106
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
107 sn = (r_c - bkg) / r_ce
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
108 imax = sn.argmax()
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
109
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
110 if best_detection["sn"] is None or best_detection["sn"] < sn[imax]:
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
111 best_detection["sn"] = sn[imax]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
112 best_detection["timescale"] = detection_time_scale
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
113 best_detection["t_max_sn"] = Time(r_t[imax], format="mjd").isot
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
114
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
115 plt.errorbar(
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
116 ijd2plot(r_t),
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
117 r_c,
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
118 r_ce,
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
119 label=f"{detection_time_scale} s, S/N = {sn[imax]:.1f}",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
120 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
121
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
122 plt.axhline(bkg, lw=3, ls=":", c="k")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
123
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
124 plt.grid()
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
125 plt.legend()
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
126
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
127 plt.ylabel("Flux")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
128 plt.xlabel("Time, MJD")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
129
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
130 plt.title(best_detection)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
131
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
132 plt.savefig("annotated-lc.png")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
133
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
134 Time(r_t, format="mjd").isot
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
135
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
136 bin_image = PictureProduct.from_file("annotated-lc.png")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
137
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
138 detection_note = str(dict(best_detection=best_detection))
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
139
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
140 import numpy as np
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
141 from astropy import wcs
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
142 from astropy.io import fits
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
143 from matplotlib import pylab as plt
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
144
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
145 x, y = np.meshgrid(np.linspace(0, 10, 500), np.linspace(0, 10, 500))
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
146
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
147 image = np.exp(-((x - 5) ** 2 + (y - 5) ** 2))
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
148
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
149 pixsize = 0.1
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
150 Npix = 500
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
151 cdec = 1
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
152
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
153 RA = 0
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
154 DEC = 0
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
155
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
156 # Create a new WCS object. The number of axes must be set
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
157 # from the start
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
158 w = wcs.WCS(naxis=2)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
159
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
160 # Set up an "Airy's zenithal" projection
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
161 # Vector properties may be set with Python lists, or Numpy arrays
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
162 w.wcs.crpix = [image.shape[0] / 2.0, image.shape[1] / 2.0]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
163 w.wcs.cdelt = np.array([pixsize / cdec, pixsize])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
164 w.wcs.crval = [RA, DEC]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
165 w.wcs.ctype = ["RA---CAR", "DEC--CAR"]
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
166 w.wcs.set_pv([(1, 1, 45.0)])
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
167
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
168 # Now, write out the WCS object as a FITS header
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
169 header = w.to_header()
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
170
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
171 # header is an astropy.io.fits.Header object. We can use it to create a new
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
172 # PrimaryHDU and write it to a file.
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
173 hdu = fits.PrimaryHDU(image, header=header)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
174 hdu.writeto("Image.fits", overwrite=True)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
175 hdu = fits.open("Image.fits")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
176 im = hdu[0].data
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
177 from astropy.wcs import WCS
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
178
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
179 wcs = WCS(hdu[0].header)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
180 plt.subplot(projection=wcs)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
181 plt.imshow(im, origin="lower")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
182 plt.grid(color="white", ls="solid")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
183 plt.xlabel("RA")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
184 plt.ylabel("Dec")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
185
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
186 from oda_api.data_products import ImageDataProduct
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
187
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
188 fits_image = ImageDataProduct.from_fits_file("Image.fits")
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
189
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
190 lc = lc # http://odahub.io/ontology#LightCurve
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
191
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
192 detection_comment = detection_note # http://odahub.io/ontology#ODATextProduct
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
193 image_output = bin_image # http://odahub.io/ontology#ODAPictureProduct
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
194 image_fits = fits_image # http://odahub.io/ontology#Image
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
195
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
196 # output gathering
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
197 _galaxy_meta_data = {}
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
198 _oda_outs = []
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
199 _oda_outs.append(("out_detectgrb_lc", "lc_galaxy.output", lc))
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
200 _oda_outs.append(
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
201 (
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
202 "out_detectgrb_detection_comment",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
203 "detection_comment_galaxy.output",
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
204 detection_comment,
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
205 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
206 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
207 _oda_outs.append(
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
208 ("out_detectgrb_image_output", "image_output_galaxy.output", image_output)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
209 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
210 _oda_outs.append(
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
211 ("out_detectgrb_image_fits", "image_fits_galaxy.output", image_fits)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
212 )
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
213
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
214 for _outn, _outfn, _outv in _oda_outs:
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
215 _galaxy_outfile_name = os.path.join(_galaxy_wd, _outfn)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
216 if isinstance(_outv, str) and os.path.isfile(_outv):
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
217 shutil.move(_outv, _galaxy_outfile_name)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
218 _galaxy_meta_data[_outn] = {"ext": "_sniff_"}
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
219 elif getattr(_outv, "write_fits_file", None):
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
220 _outv.write_fits_file(_galaxy_outfile_name)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
221 _galaxy_meta_data[_outn] = {"ext": "fits"}
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
222 elif getattr(_outv, "write_file", None):
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
223 _outv.write_file(_galaxy_outfile_name)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
224 _galaxy_meta_data[_outn] = {"ext": "_sniff_"}
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
225 else:
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
226 with open(_galaxy_outfile_name, "w") as fd:
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
227 json.dump(_outv, fd, cls=CustomJSONEncoder)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
228 _galaxy_meta_data[_outn] = {"ext": "json"}
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
229
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
230 with open(os.path.join(_galaxy_wd, "galaxy.json"), "w") as fd:
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
231 json.dump(_galaxy_meta_data, fd)
c80db1ec6611 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 5b1251e9c9cdff7f825bfcfebdfdb12714c13d8f
astroteam
parents:
diff changeset
232 print("*** Job finished successfully ***")