forked from yaoyuhan/ForcePhotZTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
61 lines (54 loc) · 1.5 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import io
import gzip
import glob
import time
import pandas as pd
import numpy as np
import subprocess
import astropy.units as u
from astropy.io import fits
import astropy.io.ascii as asci
from astropy.time import Time
from astropy.utils.exceptions import AstropyDeprecationWarning
import warnings
warnings.simplefilter('ignore', category = AstropyDeprecationWarning)
def database_query(s, q, nquery = 5):
"""
To prevent error in Kowalski query:
KeyError: 'result_data'
"""
r = {}
cnt = 0
while cnt < nquery:
r = s.query(query=q)
if "data" in r:
break
time.sleep(5)
cnt = cnt + 1
return r
def get_dets(s, name):
q = {"query_type": "find",
"query": {
"catalog": "ZTF_alerts",
"filter": {
'objectId': {'$eq': name},
'candidate.isdiffpos': {'$in': ['1', 't']},
},
"projection": {
"_id": 0,
"candidate.jd": 1,
"candidate.ra": 1,
"candidate.dec": 1,
"candidate.magpsf": 1,
"candidate.sigmapsf": 1,
"candidate.fid": 1,
"candidate.programid": 1,
"candidate.drb": 1
}
}
}
query_result = database_query(s, q, nquery = 10)
out = query_result['data']
return out