Mercurial > repos > astroteam > hess_astro_tool
annotate Image.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 |
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 import wcs |
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.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
|
14 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
|
15 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
|
16 from numpy import cos, pi |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
17 from oda_api.api import ProgressReporter |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
18 from oda_api.data_products import ImageDataProduct, PictureProduct |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
19 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
|
20 |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
21 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
|
22 pr.report_progress(stage="Progress", progress=5.0) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
23 |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
24 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
|
25 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
|
26 "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
|
27 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
28 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
|
29 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 T1 = "2000-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
|
34 T2 = "2022-10-10T13:16:00.0" # http://odahub.io/ontology#EndTime |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
35 Radius = 1.0 # http://odahub.io/ontology#AngleDegrees |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
36 pixsize = ( |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
37 0.05 # http://odahub.io/ontology#AngleDegrees ; oda:label "Pixel size" |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
38 ) |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
39 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
|
40 Emax = 100.0 # http://odahub.io/ontology#Energy_TeV |
0
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 _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
|
43 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 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
|
48 else: |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
49 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
|
50 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
55 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
|
56 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
|
57 message = "" |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
58 RA_pnts = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
59 DEC_pnts = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
60 DL3_files = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
61 OBSIDs = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
62 Tstart = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
63 Tstop = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 Tstart.append( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
73 Time( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
74 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
|
75 format="isot", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
76 scale="utc", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
77 ).mjd |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
78 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
79 Tstop.append( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
80 Time( |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
81 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
|
82 format="isot", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
83 scale="utc", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
84 ).mjd |
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 hdul.close() |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
87 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
92 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
|
93 OBSlist = [] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
94 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
|
95 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
|
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 cdec = cos(DEC * pi / 180.0) |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
102 Npix = int(2 * Radius / pixsize) + 1 |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
103 RA_bins = np.linspace( |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
104 RA - Npix * pixsize / cdec / 2, RA + Npix * pixsize / cdec / 2, Npix + 1 |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
105 ) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
106 DEC_bins = np.linspace( |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
107 DEC - Npix * pixsize / 2, DEC + Npix * pixsize / 2, Npix + 1 |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
108 ) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
109 |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
110 image = np.zeros((Npix, Npix)) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
111 for f in OBSlist: |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 ev_time = ev["TIME"] |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
118 mask = (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
|
119 h = np.histogram2d(ev_ra[mask], ev_dec[mask], bins=[RA_bins, DEC_bins]) |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
120 image += h[0] |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
121 hdul.close() |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
122 |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
123 image = np.transpose(image) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
124 |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
125 plt.imshow( |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
126 image, |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
127 extent=(RA_bins[0], RA_bins[-1], DEC_bins[0], DEC_bins[-1]), |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
128 origin="lower", |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
129 ) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
130 plt.colorbar() |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
131 |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
132 plt.xlim(*plt.xlim()[::-1]) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
133 |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
134 plt.xlabel("RA, degrees") |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
135 plt.ylabel("DEC,degrees") |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
136 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
137 # Create a new WCS object. The number of axes must be set |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
138 # from the start |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
139 w = wcs.WCS(naxis=2) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
140 |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
141 w.wcs.ctype = ["RA---CAR", "DEC--CAR"] |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
142 # we need a Plate carrée (CAR) projection since histogram is binned by ra-dec |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
143 # the peculiarity here is that CAR projection produces rectilinear grid only if CRVAL2==0 |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
144 # also, we will follow convention of RA increasing from right to left (CDELT1<0, need to flip an input image) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
145 # otherwise, aladin-lite doesn't show it |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
146 w.wcs.crval = [RA, 0] |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
147 w.wcs.crpix = [Npix / 2.0 + 0.5, 0.5 - DEC_bins[0] / pixsize] |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
148 w.wcs.cdelt = np.array([-pixsize / cdec, pixsize]) |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
149 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
150 header = w.to_header() |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
151 |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
152 hdu = fits.PrimaryHDU(np.flip(image, axis=1), header=header) |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
153 hdu.writeto("Image.fits", overwrite=True) |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
154 hdu = fits.open("Image.fits") |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
155 im = hdu[0].data |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
156 wcs1 = wcs.WCS(hdu[0].header) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
157 ax = plt.subplot(projection=wcs1) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
158 plt.imshow(im, origin="lower") |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
159 plt.colorbar(label="Counts per pixel") |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
160 plt.scatter( |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
161 [RA], [DEC], marker="x", color="white", transform=ax.get_transform("world") |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
162 ) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
163 plt.text( |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
164 RA, |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
165 DEC + 0.5 * pixsize, |
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_name, |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
167 color="white", |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
168 transform=ax.get_transform("world"), |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
169 ) |
0
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.grid(color="white", ls="solid") |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
172 plt.xlabel("RA") |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
173 plt.ylabel("Dec") |
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 pr.report_progress(stage="Progress", progress=100.0) |
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
175 plt.savefig("Image.png", format="png") |
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 bin_image = PictureProduct.from_file("Image.png") |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
178 fits_image = ImageDataProduct.from_fits_file("Image.fits") |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
179 |
1
593c4b45eda5
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2f23ec010eab8d33d2760f061286756e17015af7
astroteam
parents:
0
diff
changeset
|
180 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
|
181 fits = fits_image # http://odahub.io/ontology#Image |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
182 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
183 # output gathering |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
184 _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
|
185 _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
|
186 _oda_outs.append(("out_Image_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
|
187 _oda_outs.append(("out_Image_fits", "fits_galaxy.output", fits)) |
0
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
188 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
189 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
|
190 _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
|
191 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
|
192 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
|
193 _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
|
194 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
|
195 _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
|
196 _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
|
197 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
|
198 _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
|
199 _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
|
200 else: |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
201 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
|
202 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
|
203 _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
|
204 |
02e4bb4fa10c
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 2991f65b25d4e6d1b69458603fce917adff40f94
astroteam
parents:
diff
changeset
|
205 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
|
206 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
|
207 print("*** Job finished successfully ***") |