Mercurial > repos > astroteam > hess_astro_tool
annotate Lightcurve.py @ 0:02e4bb4fa10c draft
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
author | astroteam |
---|---|
date | Mon, 19 Feb 2024 10:56:44 +0000 |
parents | |
children | 593c4b45eda5 |
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 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
24 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
25 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
|
26 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
|
27 DEC = 22.014700 # http://odahub.io/ontology#PointOfInterestDEC |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
28 T1 = "2003-10-09T13:16:00.0" # http://odahub.io/ontology#StartTime |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
29 T2 = "2005-10-10T13:16:00.0" # http://odahub.io/ontology#EndTime |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
30 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
|
31 R_s = 0.2 # 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
|
32 Emin = 100.0 # http://odahub.io/ontology#Energy_GeV |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
33 Emax = 10000.0 # http://odahub.io/ontology#Energy_GeV |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
34 NTbins = 10 # http://odahub.io/ontology#Integer |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
35 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
36 _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
|
37 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 else: |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
43 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
|
44 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
49 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
|
50 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
|
51 message = "" |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
52 RA_pnts = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
53 DEC_pnts = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
54 DL3_files = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
55 OBSIDs = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
56 Tstart = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
57 Tstop = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 Tstart.append( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
67 Time( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
68 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
|
69 format="isot", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
70 scale="utc", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
71 ).mjd |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
72 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
73 Tstop.append( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
74 Time( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
75 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
|
76 format="isot", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
77 scale="utc", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
78 ).mjd |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
79 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
80 hdul.close() |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
81 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
86 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
|
87 OBSlist = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
88 Tbegs = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 message |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
96 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 Tbins |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
102 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 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
|
107 Expos = 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 for count, f in enumerate(OBSlist): |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 ev_time = (ev["TIME"] - Trun_start) / 86400.0 + Tbegs[count] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 ind = np.argmin((Thmin - dist) ** 2) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
141 AA = AA[ind] * Texp * 1e4 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
142 mask = np.where((sep_s < R_s)) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
143 cts1 = np.histogram2d(ev_time[mask], ev_en[mask], bins=[Tbins, EEbins])[0] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
144 mask = sep_b < R_s |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
145 cts2 = np.histogram2d(ev_time[mask], ev_en[mask], bins=[Tbins, EEbins])[0] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
146 src = cts1 - cts2 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
147 src_err = sqrt(cts1 + cts2) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
148 flux += np.sum(src / AA, axis=1) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
149 flux_err += np.sum(src_err / AA, axis=1) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
150 flux_b += np.sum(cts2 / AA, axis=1) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
151 flux_b_err += np.sum(sqrt(cts2) / AA, axis=1) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
152 hdul.close() |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
153 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
154 if message == "": |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
155 plt.errorbar( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
156 Tmean, |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
157 flux, |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
158 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
|
159 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
|
160 linestyle="none", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
161 label="source", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
162 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
163 plt.errorbar( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
164 Tmean, |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
165 flux_b, |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
166 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
|
167 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
|
168 linestyle="none", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
169 label="background", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
170 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
180 if message == "": |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
181 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
|
182 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
|
183 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
184 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
|
185 names = ( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
186 "Tmean[MJD]", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
187 "Tmin[MJD]", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
188 "Tmax[MJD]", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
189 "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
|
190 "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
|
191 "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
|
192 "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
|
193 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
194 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
|
195 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
196 picture = bin_image # http://odahub.io/ontology#ODAPictureProduct |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
197 lightcurve_astropy_table = lc # http://odahub.io/ontology#ODAAstropyTable |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
198 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
199 # output gathering |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
200 _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
|
201 _oda_outs = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
202 _oda_outs.append(("out_Lightcurve_picture", "picture_galaxy.output", picture)) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
203 _oda_outs.append( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
204 ( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
205 "out_Lightcurve_lightcurve_astropy_table", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
206 "lightcurve_astropy_table_galaxy.output", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
207 lightcurve_astropy_table, |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
208 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
209 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
210 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
211 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
|
212 _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
|
213 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
|
214 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
|
215 _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
|
216 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
|
217 _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
|
218 _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
|
219 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
|
220 _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
|
221 _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
|
222 else: |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
223 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
|
224 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
|
225 _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
|
226 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
227 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
|
228 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
|
229 print("*** Job finished successfully ***") |