-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.py
96 lines (72 loc) · 2.39 KB
/
query.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'arnault'
import pymongo
import numpy as np
import os
import pickle
from astropy import wcs as pywcs
if os.name == 'nt':
MONGO_URL = r'mongodb://127.0.0.1:27017'
FILES_ROOT = 'data/'
else:
MONGO_URL = r'mongodb://lsst:lsst2015@172.17.0.190:27017/lsst'
FILES_ROOT = '/sps/lsst/data/CFHT/input/raw/'
def dms(angle):
"""
Convert a floating point angle into textual representation Degree:Minute:Second (-> DEC coordinate)
:param angle: floating point value
:return: Degree:Minute:Second
"""
d = int(angle)
m = (angle - d) * 60.0
s = (m - int(m)) * 60.0
return '[%d:%d:%f]' % (int(d), int(m), s)
def hms(angle):
"""
Convert a floating point angle into textual representation Hour:Minute:Second (-> RA coordinate)
:param angle: floating point value
:return: Hour:Minute:Second
"""
""" """
hour = angle*24.0/360.0
h = int(hour)
m = (hour - h) * 60.0
s = (m - int(m)) * 60.0
return '[%d:%d:%f]' % (int(h), int(m), s)
def radec(coord):
"""
Convert a floating point array of coordinates into textual representation Hour:Minute:Second (-> RA/DEC coordinates)
:param coord: array of coordinates [RA, DEC]
:return: text
"""
return 'RA=%s DEC=%s' % (hms(coord[0]), dms(coord[1]))
if __name__ == '__main__':
client = pymongo.MongoClient(MONGO_URL)
lsst = client.lsst
for coll in lsst.collection_names():
c = lsst[coll]
print coll, c.count()
out = lsst.fits.find( { 'where': { '$in': [u'i'] } } )
for x in out:
print '---------- where =', x[u'where'], x['header_index']
print 'DETSIZE = ', x['DETSIZE']
for a in 'CD1_1', 'CD1_2', 'CD2_1', 'CD2_2', 'CRVAL1', 'CRVAL2', 'CRPIX1', 'CRPIX2':
if a in x: print '%s = %s' % (a, x[a])
path = FILES_ROOT + '/'.join(x[u'where'])
print path
for key in x:
if key == 'wcs':
value = x[key]
try:
wcs = pickle.loads(value)
pixel = np.array([[0, 0],], np.float_)
sky = wcs.wcs_pix2world(pixel, 0)
ra, dec = sky[0]
# print 'RADEC', ra, dec
except:
raise
else:
# print key, x[key]
pass
continue