annotate Lightcurve.py @ 1:593c4b45eda5 draft default tip

planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
author astroteam
date Thu, 18 Apr 2024 09:26:15 +0000
parents 02e4bb4fa10c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
1 #!/usr/bin/env python
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
2 # coding: utf-8
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
3
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
4 # flake8: noqa
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
5
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
6 import json
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
7 import os
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
8 import shutil
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
9
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
10 import matplotlib.pyplot as plt
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
11 import numpy as np
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
12 from astropy.coordinates import SkyCoord
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
13 from astropy.io import fits
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
14 from astropy.time import Time
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
15 from numpy import sqrt
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
16 from oda_api.data_products import ODAAstropyTable, PictureProduct
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
17 from oda_api.json import CustomJSONEncoder
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
18
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
19 if os.path.exists("hess_dl3_dr1.tar.gz") == False:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
20 get_ipython().system( # noqa: F821
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
21 "wget https://zenodo.org/record/1421099/files/hess_dl3_dr1.tar.gz"
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
22 )
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
23 get_ipython().system("tar -zxvf hess_dl3_dr1.tar.gz") # noqa: F821
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
24 from oda_api.api import ProgressReporter
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
25
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
26 pr = ProgressReporter()
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
27 pr.report_progress(stage="Progress", progress=5.0)
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
28
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
29 src_name = "Crab" # http://odahub.io/ontology#AstrophysicalObject
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
30 RA = 83.628700 # http://odahub.io/ontology#PointOfInterestRA
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
31 DEC = 22.014700 # http://odahub.io/ontology#PointOfInterestDEC
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
32 T1 = "2004-11-20T13:16:00.0" # http://odahub.io/ontology#StartTime
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
33 T2 = "2004-12-20T13:16:00.0" # http://odahub.io/ontology#EndTime
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
34 Radius = 2.5 # http://odahub.io/ontology#AngleDegrees
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
35 R_s = 0.2 # http://odahub.io/ontology#AngleDegrees
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
36 Emin = 1 # http://odahub.io/ontology#Energy_TeV
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
37 Emax = 100.0 # http://odahub.io/ontology#Energy_TeV
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
38 NTbins = 30 # http://odahub.io/ontology#Integer
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
39
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
40 _galaxy_wd = os.getcwd()
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
41
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
42 with open("inputs.json", "r") as fd:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
43 inp_dic = json.load(fd)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
44 if "_data_product" in inp_dic.keys():
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
45 inp_pdic = inp_dic["_data_product"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
46 else:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
47 inp_pdic = inp_dic
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
48
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
49 for vn, vv in inp_pdic.items():
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
50 if vn != "_selector":
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
51 globals()[vn] = type(globals()[vn])(vv)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
52
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
53 T1 = Time(T1, format="isot", scale="utc").mjd
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
54 T2 = Time(T2, format="isot", scale="utc").mjd
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
55 message = ""
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
56 RA_pnts = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
57 DEC_pnts = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
58 DL3_files = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
59 OBSIDs = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
60 Tstart = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
61 Tstop = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
62 flist = os.listdir("data")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
63 for f in flist:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
64 if f[-7:] == "fits.gz":
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
65 DL3_files.append(f)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
66 OBSIDs.append(int(f[20:26]))
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
67 hdul = fits.open("data/" + f)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
68 RA_pnts.append(float(hdul[1].header["RA_PNT"]))
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
69 DEC_pnts.append(float(hdul[1].header["DEC_PNT"]))
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
70 Tstart.append(
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
71 Time(
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
72 hdul[1].header["DATE-OBS"] + "T" + hdul[1].header["TIME-OBS"],
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
73 format="isot",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
74 scale="utc",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
75 ).mjd
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
76 )
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
77 Tstop.append(
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
78 Time(
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
79 hdul[1].header["DATE-END"] + "T" + hdul[1].header["TIME-END"],
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
80 format="isot",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
81 scale="utc",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
82 ).mjd
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
83 )
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
84 hdul.close()
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
85
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
86 Coords_s = SkyCoord(RA, DEC, unit="degree")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
87 COORDS_pnts = SkyCoord(RA_pnts, DEC_pnts, unit="degree")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
88 seps = COORDS_pnts.separation(Coords_s).deg
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
89
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
90 mask = np.where((seps < Radius) & (Tstart > T1) & (Tstop < T2))[0]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
91 OBSlist = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
92 Tbegs = []
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
93 for i in mask:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
94 OBSlist.append(DL3_files[i])
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
95 Tbegs.append(Tstart[i])
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
96 if len(OBSlist) == 0:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
97 message = "No data found"
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
98 raise RuntimeError("No data found")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
99 message
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
100
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
101 Tbins = np.linspace(T1, T2, NTbins + 1)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
102 Tmin = Tbins[:-1]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
103 Tmax = Tbins[1:]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
104 Tmean = (Tmin + Tmax) / 2.0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
105 Tbins
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
106
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
107 flux = np.zeros(NTbins)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
108 flux_err = np.zeros(NTbins)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
109 flux_b = np.zeros(NTbins)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
110 flux_b_err = np.zeros(NTbins)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
111 Expos = np.zeros(NTbins)
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
112 src_cts = np.zeros(NTbins)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
113 bkg_cts = np.zeros(NTbins)
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
114 for count, f in enumerate(OBSlist):
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
115 pr.report_progress(
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
116 stage="Progress", progress=5.0 + 95 * count / len(OBSlist)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
117 )
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
118 hdul = fits.open("data/" + f)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
119 RA_pnt = hdul[1].header["RA_PNT"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
120 DEC_pnt = hdul[1].header["DEC_PNT"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
121 Texp = hdul[1].header["LIVETIME"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
122 Trun_start = hdul[1].header["TSTART"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
123 dRA = RA - RA_pnt
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
124 dDEC = DEC - DEC_pnt
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
125 RA_b = RA_pnt - dRA
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
126 DEC_b = DEC_pnt - dDEC
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
127 Coords_b = SkyCoord(RA_b, DEC_b, unit="degree")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
128 Coords_pnt = SkyCoord(RA_pnt, DEC_pnt, unit="degree")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
129 dist = Coords_pnt.separation(Coords_s).deg
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
130
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
131 ev = hdul["EVENTS"].data
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
132 ev_ra = ev["RA"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
133 ev_dec = ev["DEC"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
134 ev_en = ev["ENERGY"]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
135 ev_time = (ev["TIME"] - Trun_start) / 86400.0 + Tbegs[count]
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
136 Nevents = len(ev)
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
137 print(ev_time[0])
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
138 ev_coords = SkyCoord(ev_ra, ev_dec, unit="degree")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
139 sep_s = ev_coords.separation(Coords_s).deg
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
140 sep_b = ev_coords.separation(Coords_b).deg
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
141
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
142 hdu = hdul["AEFF"].data
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
143 EEmin = hdu["ENERG_LO"][0]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
144 EEmax = hdu["ENERG_HI"][0]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
145 EE = sqrt(EEmin * EEmax)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
146 EEbins = np.concatenate((EEmin, [EEmax[-1]]))
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
147 AA = hdu["EFFAREA"][0] + 1e-10
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
148 Thmin = hdu["THETA_LO"][0]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
149 Thmax = hdu["THETA_HI"][0]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
150 ind = np.argmin((Thmin - dist) ** 2)
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
151 mask = EE < Emin
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
152 ind_en = len(EE[mask])
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
153 Expos += np.histogram(
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
154 ev_time,
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
155 weights=AA[ind, ind_en] * Texp * 1e4 * np.ones(Nevents) / Nevents,
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
156 bins=Tbins,
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
157 )[0]
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
158 mask = np.where((sep_s < R_s) & (ev_en > Emin) & (ev_en < Emax))
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
159 src_cts += np.histogram(ev_time[mask], bins=Tbins)[0]
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
160 mask = np.where((sep_b < R_s) & (ev_en > Emin) & (ev_en < Emax))
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
161 bkg_cts += np.histogram(ev_time[mask], bins=Tbins)[0]
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
162 hdul.close()
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
163 print(src_cts)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
164 print(bkg_cts)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
165 print(Expos)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
166 src = src_cts - bkg_cts
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
167 src_err = sqrt(src_cts + bkg_cts)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
168 flux = src / (Expos + 1)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
169 flux_err = src_err / (Expos + 1)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
170 flux_b = bkg_cts / (Expos + 1)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
171 flux_b_err = sqrt(bkg_cts) / (Expos + 1)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
172 # flux_err+=np.sum(src_err/AA,axis=1)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
173 # flux_b+=np.sum(cts2/AA,axis=1)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
174 # flux_b_err+=np.sum(sqrt(cts2)/AA,axis=1)
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
175 print(flux)
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
176
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
177 if message == "":
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
178 plt.errorbar(
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
179 Tmean,
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
180 flux,
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
181 yerr=flux_err,
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
182 xerr=[Tmean - Tmin, Tmax - Tmean],
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
183 linestyle="none",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
184 label="source",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
185 )
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
186 plt.errorbar(
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
187 Tmean,
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
188 flux_b,
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
189 yerr=flux_b_err,
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
190 xerr=[Tmean - Tmin, Tmax - Tmean],
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
191 linestyle="none",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
192 label="background",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
193 )
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
194 plt.xlabel("Time, MJD")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
195 plt.ylabel("Flux, cts/cm$^2$s")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
196 plt.yscale("log")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
197 ymin = min(min(flux - flux_err), min(flux_b - flux_b_err))
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
198 ymax = max(max(flux + flux_err), max(flux_b + flux_b_err))
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
199 plt.ylim(ymin / 2.0, 2 * ymax)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
200 plt.legend(loc="lower left")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
201 plt.savefig("Lightcurve.png", format="png")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
202
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
203 if message == "":
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
204 bin_image = PictureProduct.from_file("Lightcurve.png")
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
205 from astropy.table import Table
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
206
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
207 data = [Tmean, Tmin, Tmax, flux, flux_err, flux_b, flux_b_err]
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
208 names = (
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
209 "Tmean[MJD]",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
210 "Tmin[MJD]",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
211 "Tmax[MJD]",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
212 "Flux[counts/cm2s]",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
213 "Flux_error[counts/cm2s]",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
214 "Background[counts/cm2s]",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
215 "Background_error[counts/cm2s]",
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
216 )
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
217 lc = ODAAstropyTable(Table(data, names=names))
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
218
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
219 png = bin_image # http://odahub.io/ontology#ODAPictureProduct
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
220 table = lc # http://odahub.io/ontology#ODAAstropyTable
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
221
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
222 # output gathering
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
223 _galaxy_meta_data = {}
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
224 _oda_outs = []
1
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
225 _oda_outs.append(("out_Lightcurve_png", "png_galaxy.output", png))
593c4b45eda5 planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents: 0
diff changeset
226 _oda_outs.append(("out_Lightcurve_table", "table_galaxy.output", table))
0
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
227
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
228 for _outn, _outfn, _outv in _oda_outs:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
229 _galaxy_outfile_name = os.path.join(_galaxy_wd, _outfn)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
230 if isinstance(_outv, str) and os.path.isfile(_outv):
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
231 shutil.move(_outv, _galaxy_outfile_name)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
232 _galaxy_meta_data[_outn] = {"ext": "_sniff_"}
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
233 elif getattr(_outv, "write_fits_file", None):
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
234 _outv.write_fits_file(_galaxy_outfile_name)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
235 _galaxy_meta_data[_outn] = {"ext": "fits"}
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
236 elif getattr(_outv, "write_file", None):
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
237 _outv.write_file(_galaxy_outfile_name)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
238 _galaxy_meta_data[_outn] = {"ext": "_sniff_"}
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
239 else:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
240 with open(_galaxy_outfile_name, "w") as fd:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
241 json.dump(_outv, fd, cls=CustomJSONEncoder)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
242 _galaxy_meta_data[_outn] = {"ext": "json"}
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
243
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
244 with open(os.path.join(_galaxy_wd, "galaxy.json"), "w") as fd:
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
245 json.dump(_galaxy_meta_data, fd)
02e4bb4fa10c planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff changeset
246 print("*** Job finished successfully ***")