-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextract_mag_airmass_common.py
72 lines (61 loc) · 2.63 KB
/
extract_mag_airmass_common.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
#! /usr/bin/env python
# Routine created by Victor Terron, modified by Javier Blasco to suit his needs.
# LEMON modules
import lemon.database as database
import matplotlib.pyplot as plt
import numpy as np
def main(db_name):
db = database.LEMONdB(db_name)
# (1) Identify stars that have been observed in the same number of images
# that the star that has been observed in the maximum number of images :-)
# I could have simply used the image count of the images, but that would
# discard all the stars if there were an image without stars.
query = """
SELECT s.id
FROM stars AS s
INNER JOIN photometry AS p
ON s.id = p.star_id
GROUP BY p.star_id
HAVING COUNT(*) = (SELECT MAX(nimages)
FROM (SELECT COUNT(*) AS nimages
FROM photometry
GROUP BY star_id))
"""
db._execute(query)
# IDs of the stars observed in all the images
star_ids = set(x[0] for x in db._rows)
num_stars = len(star_ids)
# (2) Identify the number of images involved so that we can return airmass and magnitude of stars in all images
query = """
SELECT id
FROM images
WHERE sources = 0
"""
db._execute(query)
num_airmasses = len(set(_ for _ in db._rows))
# Create numpy arrays to store airmasses and magnitudes
airmasses = np.zeros([num_stars, num_airmasses], dtype=np.float64)
magnitudes = np.zeros([num_stars, num_airmasses], dtype=np.float64)
SNR = np.zeros([num_stars, num_airmasses], dtype=np.float64)
filters = np.array([""] * num_stars * num_airmasses, dtype="S15").reshape(num_stars, num_airmasses)
im_paths = np.array([""] * num_stars * num_airmasses, dtype="S100").reshape(num_stars, num_airmasses)
for ii, id_ in enumerate(star_ids):
query = """
SELECT p.star_id, f.name, p.magnitude, i.airmass, p.SNR, i.path
FROM photometry AS p
INNER JOIN images AS i
ON p.image_id = i.id
INNER JOIN photometric_filters AS f
ON i.filter_id = f.id
WHERE p.star_id = ?
"""
t = (id_, )
db._execute(query, t)
for jj, row in enumerate(db._rows):
star_id, filter_name, magnitude, airmass, snr, path = row
airmasses[ii,jj] = airmass
magnitudes[ii,jj] = magnitude
filters[ii, jj] = filter_name
SNR[ii,jj] = snr
im_paths[ii,jj] = path
return airmasses, magnitudes, filters, SNR, im_paths